GCC Code Coverage Report


Directory: ./
File: src/OptionValue.cpp
Date: 2024-07-27 10:53:27
Exec Total Coverage
Lines: 75 77 97.4%
Branches: 22 30 73.3%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #include "path_completion.h"
8 #include "OptionValue.h"
9
10 ///Default constructeur of OptionValue
11 /** @param type : type of the OptionValue
12 */
13 556 OptionValue::OptionValue(OptionType::OptionType type){
14 556 VecValue vecValue, vecDefaultValue, vecPossibleValue;
15
1/1
✓ Branch 1 taken 556 times.
556 initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
16 556 }
17
18 ///Initialisation function of the class OptionValue
19 /** @param value : value of the OptionValue
20 * @param type : type of the OptionValue
21 */
22 37 OptionValue::OptionValue(const std::string & value, OptionType::OptionType type){
23 37 VecValue vecValue, vecDefaultValue, vecPossibleValue;
24
1/1
✓ Branch 1 taken 37 times.
37 vecValue.push_back(value);
25
1/1
✓ Branch 1 taken 37 times.
37 initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
26 37 }
27
28 ///Initialisation function of the class OptionValue
29 /** @param vecValue : vector of values of the OptionValue
30 * @param type : type of the OptionValue
31 */
32 1 OptionValue::OptionValue(const VecValue & vecValue, OptionType::OptionType type){
33 1 VecValue vecDefaultValue, vecPossibleValue;
34
1/1
✓ Branch 1 taken 1 times.
1 initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
35 1 }
36
37 ///Initialisation function of the class OptionValue
38 /** @param value : value of the OptionValue
39 * @param type : type of the OptionValue
40 * @param vecDefaultValue : default value of the OptionValue
41 */
42 1 OptionValue::OptionValue(const std::string & value, OptionType::OptionType type, const VecValue & vecDefaultValue){
43 1 VecValue vecValue, vecPossibleValue;
44
1/1
✓ Branch 1 taken 1 times.
1 vecValue.push_back(value);
45
1/1
✓ Branch 1 taken 1 times.
1 initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
46 1 }
47
48 ///Initialisation function of the class OptionValue
49 /** @param vecValue : vector of values of the OptionValue
50 * @param type : type of the OptionValue
51 * @param vecDefaultValue : default value of the OptionValue
52 */
53 1 OptionValue::OptionValue(const VecValue & vecValue, OptionType::OptionType type, const VecValue & vecDefaultValue){
54 1 VecValue vecPossibleValue;
55
1/1
✓ Branch 1 taken 1 times.
1 initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
56 1 }
57
58 ///Initialisation function of the class OptionValue
59 /** @param value : value of the OptionValue
60 * @param type : type of the OptionValue
61 * @param vecDefaultValue : default value of the OptionValue
62 * @param vecPossibleValue : vector of the possible values for the OptionValue
63 */
64 1 OptionValue::OptionValue(const std::string & value, OptionType::OptionType type, const VecValue & vecDefaultValue, const VecValue & vecPossibleValue){
65 1 VecValue vecValue;
66
1/1
✓ Branch 1 taken 1 times.
1 vecValue.push_back(value);
67
1/1
✓ Branch 1 taken 1 times.
1 initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
68 1 }
69
70 ///Initialisation function of the class OptionValue
71 /** @param vecValue : vector of values of the OptionValue
72 * @param type : type of the OptionValue
73 * @param vecDefaultValue : default value of the OptionValue
74 * @param vecPossibleValue : vector of the possible values for the OptionValue
75 */
76 1 OptionValue::OptionValue(const VecValue & vecValue, OptionType::OptionType type, const VecValue & vecDefaultValue, const VecValue & vecPossibleValue){
77
1/1
✓ Branch 1 taken 1 times.
1 initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
78 1 }
79
80
81 ///Copy constructor of OptionValue
82 /** @param other : class to copy
83 */
84 167 OptionValue::OptionValue(const OptionValue & other){
85
1/1
✓ Branch 1 taken 167 times.
167 copyOptionValue(other);
86 167 }
87
88 ///Destructeur of OptionValue
89 1334 OptionValue::~OptionValue(){
90
91 }
92
93 ///Definition of equal operator of OptionValue
94 /** @param other : class to copy
95 * @return copied class
96 */
97 422 OptionValue & OptionValue::operator = (const OptionValue & other){
98 422 copyOptionValue(other);
99 422 return *this;
100 }
101
102 ///Set the type of the OptionValue
103 /** @param type : type of the OptionValue
104 */
105 167 void OptionValue::setType(OptionType::OptionType type){
106 167 p_type = type;
107 167 }
108
109 ///Set the value of the OptionValue
110 /** @param value : value to be set
111 */
112 1 void OptionValue::setValue(const std::string & value){
113 1 VecValue vecValue;
114
1/1
✓ Branch 1 taken 1 times.
1 vecValue.push_back(value);
115
1/1
✓ Branch 1 taken 1 times.
1 setValue(vecValue);
116 1 }
117
118 ///Set the value of the OptionValue
119 /** @param value : value to be set
120 */
121 2 void OptionValue::setValue(const VecValue & value){p_vecValue = value;}
122
123 ///Add value of the OptionValue
124 /** @param value : value to be added
125 */
126 39 void OptionValue::addValue(const std::string & value){p_vecValue.push_back(value);}
127
128 ///Get the vector of values
129 /** @return vector of values
130 */
131 4 const VecValue & OptionValue::getValue() const{return p_vecValue;}
132
133 ///Get the vector of values
134 /** @return vector of values
135 */
136 7 VecValue & OptionValue::getValue(){return p_vecValue;}
137
138 ///Get the type of the OptionValue
139 /** @return type of the OptionValue
140 */
141 38 OptionType::OptionType OptionValue::getType() const{return p_type;}
142
143 ///Get the type of the OptionValue
144 /** @return type of the OptionValue
145 */
146 104 OptionType::OptionType & OptionValue::getType(){return p_type;}
147
148 ///Get the default value of the OptionValue
149 /** @return default value of the OptionValue
150 */
151 39 const VecValue & OptionValue::getDefaultValue() const{return p_vecDefaultValue;}
152
153 ///Get the default value of the OptionValue
154 /** @return default value of the OptionValue
155 */
156 1 VecValue & OptionValue::getDefaultValue(){return p_vecDefaultValue;}
157
158 ///Get the possible values of the OptionValue
159 /** @return possible values of the OptionValue
160 */
161 39 const VecValue & OptionValue::getPossibleValue() const{return p_vecPossibleValue;}
162
163 ///Get the possible values of the OptionValue
164 /** @return possible values of the OptionValue
165 */
166 1 VecValue & OptionValue::getPossibleValue(){return p_vecPossibleValue;}
167
168 ///Print the possible value to the bash completion
169 /** @param[out] strBashCompletion : string of all possible choices
170 * @param cursorOption : option of the cursor which is currently completed
171 */
172 8 void OptionValue::bashCompletionValue(std::string & strBashCompletion, const std::string & cursorOption) const{
173 // std::cerr << "OptionValue::bashCompletionValue : cursorOption = '"<<cursorOption<<"'" << std::endl;
174
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 if(p_vecPossibleValue.size() != 0lu){ //If there is some possible values, we print them
175 for(VecValue::const_iterator it(p_vecPossibleValue.begin()); it != p_vecPossibleValue.end(); ++it){
176 strBashCompletion += " " + *it;
177 }
178 }else{
179 //Now, we can complete by respect to the expected type
180
3/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 3 times.
8 if(p_type == OptionType::FILE_OR_DIR || p_type == OptionType::FILENAME){
181
1/1
✓ Branch 2 taken 5 times.
5 strBashCompletion += path_completion_all(cursorOption);
182
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 }else if(p_type == OptionType::DIRECTORY){
183
1/1
✓ Branch 2 taken 2 times.
2 strBashCompletion += path_completion_dirOnly(cursorOption);
184 }else{
185
1/1
✓ Branch 2 taken 1 times.
1 strBashCompletion += convertOptionTypeToString(p_type);
186 }
187 }
188 8 }
189
190 ///Copy function of OptionValue
191 /** @param other : class to copy
192 */
193 589 void OptionValue::copyOptionValue(const OptionValue & other){
194 589 p_vecValue = other.p_vecValue;
195 589 p_type = other.p_type;
196 589 p_vecDefaultValue = other.p_vecDefaultValue;
197 589 p_vecPossibleValue = other.p_vecPossibleValue;
198 589 }
199
200 ///Initialisation function of the class OptionValue
201 /** @param vecValue : vector of values of the OptionValue
202 * @param type : type of the OptionValue
203 * @param vecDefaultValue : default value of the OptionValue
204 * @param vecPossibleValue : vector of the possible values for the OptionValue
205 */
206 598 void OptionValue::initialisationOptionValue(const VecValue & vecValue, OptionType::OptionType type, const VecValue & vecDefaultValue, const VecValue & vecPossibleValue){
207 598 p_vecValue = vecValue;
208 598 p_type = type;
209 598 p_vecDefaultValue = vecDefaultValue;
210 598 p_vecPossibleValue = vecPossibleValue;
211 598 }
212
213
214
215
216
217