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