GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixOptionParser/src/OptionValue_impl.h
Date: 2025-03-14 11:56:07
Exec Total Coverage
Lines: 27 32 84.4%
Branches: 21 49 42.9%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #ifndef __POPTIONVALUE_IMPL_H__
8 #define __POPTIONVALUE_IMPL_H__
9
10 #include <stdexcept>
11 #include "OptionValue.h"
12
13 ///Set the value in the OptionValue
14 /** @param value : value of the OptionValue
15 */
16 template<typename T>
17 80 void OptionValue::setDefaultValue(const T & value){
18
1/1
✓ Branch 1 taken 80 times.
80 PString valueBinStr;
19
1/1
✓ Branch 1 taken 80 times.
80 valueBinStr.fromValue(value);
20 80 PVecString vecValue;
21
1/1
✓ Branch 1 taken 80 times.
80 vecValue.push_back(valueBinStr);
22
1/1
✓ Branch 1 taken 80 times.
80 p_vecDefaultValue = vecValue;
23 80 }
24
25 ///Set the value in the OptionValue
26 /** @param value : value of the OptionValue
27 */
28 template<typename T>
29 void OptionValue::setDefaultValue(const std::vector<T> & value){
30 p_vecDefaultValue = value;
31 }
32
33 ///Get the value of the option
34 /** @param[out] value : value of the option
35 * @param isParsed : true if the option is parsed, false if not
36 */
37 template<typename T>
38 68 void OptionValue::getValue(T & value, bool isParsed) const{
39 68 checkTypeFromTemplate<T>();
40
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 33 times.
68 if(isParsed){
41
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
35 if(p_vecValue.size() > 1lu){
42 std::runtime_error("OptionValue::getValue : several value but only one value in parameter");
43 }
44
1/1
✓ Branch 3 taken 10 times.
35 value = stringToValue<T>(p_vecValue.front());
45 }else{
46
1/2
✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
33 if(p_vecDefaultValue.size() == 1lu){
47
1/2
✓ Branch 3 taken 28 times.
✗ Branch 4 not taken.
33 value = stringToValue<T>(p_vecDefaultValue.front());
48 }else{
49 std::runtime_error("OptionValue::getValue : several value but only one value in parameter");
50 }
51 }
52 68 }
53
54 ///Get the value of the option
55 /** @param[out] vecValue : value of the option
56 * @param isParsed : true if the option is parsed, false if not
57 */
58 template<typename T>
59 12 void OptionValue::getValue(std::vector<T> & vecValue, bool isParsed) const{
60 12 checkTypeFromTemplate<T>();
61
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
12 if(isParsed){
62
2/2
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 9 times.
27 for(PVecString::const_iterator it(p_vecValue.begin()); it != p_vecValue.end(); ++it){
63
2/4
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 18 times.
✗ Branch 6 not taken.
18 vecValue.push_back(stringToValue<T>(*it));
64 }
65 }else{
66
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 3 times.
6 for(PVecString::const_iterator it(p_vecDefaultValue.begin()); it != p_vecDefaultValue.end(); ++it){
67
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 vecValue.push_back(stringToValue<T>(*it));
68 }
69 }
70 12 }
71
72 ///Check the type from the template
73 /** Throw exception if there is an incompatibility
74 */
75 template<typename T>
76 124 void OptionValue::checkTypeFromTemplate() const{
77 124 OptionType::OptionType optionTypeFromDefault = getOptionTypeFromType<T>();
78
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
124 if(!isOptionTypeCompatible(p_type, optionTypeFromDefault)){
79 std::stringstream strError;
80 strError << "OptionValue::checkTypeFromTemplate : Incompatible types from parameters (" << convertOptionTypeToString(p_type) << ") ad for default type ("<<convertOptionTypeToString(optionTypeFromDefault)<<")";
81 throw std::runtime_error(strError.str());
82 }
83 124 }
84
85 #endif
86
87
88