GCC Code Coverage Report


Directory: ./
File: src/OptionValue_impl.h
Date: 2024-07-27 10:53:27
Exec Total Coverage
Lines: 26 31 83.9%
Branches: 18 45 40.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 __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 44 void OptionValue::setDefaultValue(const T & value){
18
1/1
✓ Branch 1 taken 44 times.
44 std::string valueBinStr(convertToString(value));
19 44 VecValue vecValue;
20
1/1
✓ Branch 1 taken 44 times.
44 vecValue.push_back(valueBinStr);
21
1/1
✓ Branch 1 taken 44 times.
44 p_vecDefaultValue = vecValue;
22 44 }
23
24 ///Set the value in the OptionValue
25 /** @param value : value of the OptionValue
26 */
27 template<typename T>
28 void OptionValue::setDefaultValue(const std::vector<T> & value){
29 p_vecDefaultValue = value;
30 }
31
32 ///Set the value in the OptionValue
33 /** @param value : value of the OptionValue
34 */
35 template<typename T>
36 void OptionValue::setDefaultValue(const std::list<T> & value){
37 VecValue vecValue;
38 for(typename std::list<T>::const_iterator it(value.begin()); it != value.end(); ++it){
39 vecValue.push_back(convertToString(*it));
40 }
41 p_vecDefaultValue = vecValue;
42 }
43
44 ///Get the value of the option
45 /** @param[out] value : value of the option
46 * @param isParsed : true if the option is parsed, false if not
47 */
48 template<typename T>
49 30 void OptionValue::getValue(T & value, bool isParsed) const{
50 30 checkTypeFromTemplate<T>();
51
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 5 times.
30 if(isParsed){
52
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
25 if(p_vecValue.size() > 1lu){
53 std::runtime_error("OptionValue::getValue : several value but only one value in parameter");
54 }
55 25 value = stringToValue<T>(p_vecValue.front());
56 }else{
57
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 if(p_vecDefaultValue.size() == 1lu){
58 5 value = stringToValue<T>(p_vecDefaultValue.front());
59 }else{
60 std::runtime_error("OptionValue::getValue : several value but only one value in parameter");
61 }
62 }
63 30 }
64
65 ///Get the value of the option
66 /** @param[out] vecValue : value of the option
67 * @param isParsed : true if the option is parsed, false if not
68 */
69 template<typename T>
70 void OptionValue::getValue(std::vector<T> & vecValue, bool isParsed) const{
71 checkTypeFromTemplate<T>();
72 if(isParsed){
73 for(VecValue::const_iterator it(p_vecValue.begin()); it != p_vecValue.end(); ++it){
74 vecValue.push_back(stringToValue<T>(*it));
75 }
76 }else{
77 for(VecValue::const_iterator it(p_vecDefaultValue.begin()); it != p_vecDefaultValue.end(); ++it){
78 vecValue.push_back(stringToValue<T>(*it));
79 }
80 }
81 }
82
83 ///Get the value of the option
84 /** @param[out] vecValue : value of the option
85 * @param isParsed : true if the option is parsed, false if not
86 */
87 template<typename T>
88 4 void OptionValue::getValue(std::list<T> & vecValue, bool isParsed) const{
89 4 checkTypeFromTemplate<T>();
90
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if(isParsed){
91
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1 times.
4 for(VecValue::const_iterator it(p_vecValue.begin()); it != p_vecValue.end(); ++it){
92
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));
93 }
94 }else{
95
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 3 times.
6 for(VecValue::const_iterator it(p_vecDefaultValue.begin()); it != p_vecDefaultValue.end(); ++it){
96
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));
97 }
98 }
99 4 }
100
101 ///Check the type from the template
102 /** Throw exception if there is an incompatibility
103 */
104 template<typename T>
105 34 void OptionValue::checkTypeFromTemplate() const{
106 34 OptionType::OptionType optionTypeFromDefault = getOptionTypeFromType<T>();
107
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
34 if(!isOptionTypeCompatible(p_type, optionTypeFromDefault)){
108 std::stringstream strError;
109 strError << "OptionValue::checkTypeFromTemplate : Incompatible types from parameters (" << convertOptionTypeToString(p_type) << ") ad for default type ("<<convertOptionTypeToString(optionTypeFromDefault)<<")";
110 throw std::runtime_error(strError.str());
111 }
112 34 }
113
114 #endif
115
116
117