GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixOptionParser/src/OptionParser_impl.h
Date: 2025-03-14 12:18:05
Exec Total Coverage
Lines: 8 8 100.0%
Branches: 6 6 100.0%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #ifndef __POPTIONPARSER_IMPL_H__
8 #define __POPTIONPARSER_IMPL_H__
9
10 #include <sstream>
11 #include "OptionParser.h"
12
13 ///Add an option in the OptionParser
14 /** @param longOption : long option (start with --) as --version
15 * @param shortOption : short option (start with -) as -v
16 * @param defaultValue : default value of the option
17 * @param docString : documentation string of the option
18 * The type of the option will be automatically determined with the type of the default value
19 */
20 template<typename T>
21 44 void OptionParser::addOption(const PString & longOption, const PString & shortOption, const T defaultValue, const PString & docString){
22
1/1
✓ Branch 1 taken 2 times.
44 OptionType::OptionType optionType = getOptionTypeFromType<T>();
23
1/1
✓ Branch 1 taken 44 times.
44 OptionValue value;
24
1/1
✓ Branch 1 taken 44 times.
44 value.setType(optionType);
25
1/1
✓ Branch 1 taken 44 times.
44 value.setDefaultValue(defaultValue);
26
1/1
✓ Branch 1 taken 44 times.
44 Option option(longOption, shortOption, value, false, docString);
27
1/1
✓ Branch 2 taken 44 times.
44 p_vecMode.back().addOption(option);
28 44 }
29
30 ///Add an option in the OptionParser
31 /** @param longOption : long option (start with --) as --version
32 * @param shortOption : short option (start with -) as -v
33 * @param defaultValue : default value of the option
34 * @param optionType : type of the data of the option (int, float, double, string, etc)
35 * @param docString : documentation string of the option
36 * The function will check if the given optionType is relevant with the type of the default value
37 */
38 template<typename T>
39 void OptionParser::addOption(const PString & longOption, const PString & shortOption, const T defaultValue,
40 OptionType::OptionType optionType, const PString & docString)
41 {
42 checkOptionType<T>(optionType);
43 OptionValue value;
44 value.setType(optionType);
45 value.setDefaultValue(defaultValue);
46 Option option(longOption, shortOption, value, false, docString);
47 p_vecMode.back().addOption(option);
48 }
49
50 ///Check the given option type
51 /** @param optionType : type of the option to be checked
52 * Throw an exception if there is a problem
53 */
54 template<typename T>
55 void OptionParser::checkOptionType(OptionType::OptionType optionType){
56 OptionType::OptionType optionTypeFromDefault = getOptionTypeFromType<T>();
57 if(!isOptionTypeCompatible(optionType, optionTypeFromDefault)){
58 std::stringstream strError;
59 strError << "OptionParser::checkOptionType : Incompatible types from parameters (" << convertOptionTypeToString(optionType) << ") ad for default type ("<<convertOptionTypeToString(optionTypeFromDefault)<<")";
60 throw std::runtime_error(strError.str());
61 }
62 }
63
64 #endif
65
66