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 |
|
662 |
OptionValue::OptionValue(OptionType::OptionType type){ |
14 |
|
1324 |
VecValue vecValue, vecDefaultValue, vecPossibleValue; |
15 |
✓ |
662 |
initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue); |
16 |
|
662 |
} |
17 |
|
|
|
18 |
|
|
///Initialisation function of the class OptionValue |
19 |
|
|
/** @param value : value of the OptionValue |
20 |
|
|
* @param type : type of the OptionValue |
21 |
|
|
*/ |
22 |
|
65 |
OptionValue::OptionValue(const std::string & value, OptionType::OptionType type){ |
23 |
|
130 |
VecValue vecValue, vecDefaultValue, vecPossibleValue; |
24 |
✓ |
65 |
vecValue.push_back(value); |
25 |
✓ |
65 |
initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue); |
26 |
|
65 |
} |
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 |
|
2 |
VecValue vecDefaultValue, vecPossibleValue; |
34 |
✓ |
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 |
|
2 |
VecValue vecValue, vecPossibleValue; |
44 |
✓ |
1 |
vecValue.push_back(value); |
45 |
✓ |
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 |
|
2 |
VecValue vecPossibleValue; |
55 |
✓ |
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 |
|
2 |
VecValue vecValue; |
66 |
✓ |
1 |
vecValue.push_back(value); |
67 |
✓ |
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 |
initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue); |
78 |
|
1 |
} |
79 |
|
|
|
80 |
|
|
|
81 |
|
|
///Copy constructor of OptionValue |
82 |
|
|
/** @param other : class to copy |
83 |
|
|
*/ |
84 |
|
197 |
OptionValue::OptionValue(const OptionValue & other){ |
85 |
✓ |
197 |
copyOptionValue(other); |
86 |
|
197 |
} |
87 |
|
|
|
88 |
|
|
///Destructeur of OptionValue |
89 |
|
1670 |
OptionValue::~OptionValue(){ |
90 |
|
|
|
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
///Definition of equal operator of OptionValue |
94 |
|
|
/** @param other : class to copy |
95 |
|
|
* @return copied class |
96 |
|
|
*/ |
97 |
|
526 |
OptionValue & OptionValue::operator = (const OptionValue & other){ |
98 |
|
526 |
copyOptionValue(other); |
99 |
|
526 |
return *this; |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
///Set the type of the OptionValue |
103 |
|
|
/** @param type : type of the OptionValue |
104 |
|
|
*/ |
105 |
|
197 |
void OptionValue::setType(OptionType::OptionType type){ |
106 |
|
197 |
p_type = type; |
107 |
|
197 |
} |
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 |
|
2 |
VecValue vecValue; |
114 |
✓ |
1 |
vecValue.push_back(value); |
115 |
✓ |
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 |
|
40 |
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 |
|
34 |
OptionType::OptionType OptionValue::getType() const{return p_type;} |
142 |
|
|
|
143 |
|
|
///Get the type of the OptionValue |
144 |
|
|
/** @return type of the OptionValue |
145 |
|
|
*/ |
146 |
|
139 |
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 |
|
35 |
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 |
|
35 |
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 |
✗✓ |
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 |
✓✗✓✓
|
8 |
if(p_type == OptionType::FILE_OR_DIR || p_type == OptionType::FILENAME){ |
181 |
✓ |
5 |
strBashCompletion += path_completion_all(cursorOption); |
182 |
✓✓ |
3 |
}else if(p_type == OptionType::DIRECTORY){ |
183 |
✓ |
2 |
strBashCompletion += path_completion_dirOnly(cursorOption); |
184 |
|
|
}else{ |
185 |
✓ |
1 |
strBashCompletion += convertOptionTypeToString(p_type); |
186 |
|
|
} |
187 |
|
|
} |
188 |
|
8 |
} |
189 |
|
|
|
190 |
|
|
///Copy function of OptionValue |
191 |
|
|
/** @param other : class to copy |
192 |
|
|
*/ |
193 |
|
723 |
void OptionValue::copyOptionValue(const OptionValue & other){ |
194 |
|
723 |
p_vecValue = other.p_vecValue; |
195 |
|
723 |
p_type = other.p_type; |
196 |
|
723 |
p_vecDefaultValue = other.p_vecDefaultValue; |
197 |
|
723 |
p_vecPossibleValue = other.p_vecPossibleValue; |
198 |
|
723 |
} |
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 |
|
732 |
void OptionValue::initialisationOptionValue(const VecValue & vecValue, OptionType::OptionType type, const VecValue & vecDefaultValue, const VecValue & vecPossibleValue){ |
207 |
|
732 |
p_vecValue = vecValue; |
208 |
|
732 |
p_type = type; |
209 |
|
732 |
p_vecDefaultValue = vecDefaultValue; |
210 |
|
732 |
p_vecPossibleValue = vecPossibleValue; |
211 |
|
732 |
} |
212 |
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
|