1 | /*
|
---|
2 | * MapOfActions.cpp
|
---|
3 | *
|
---|
4 | * Created on: 10.05.2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | using namespace std;
|
---|
9 |
|
---|
10 | #include "Patterns/Singleton_impl.hpp"
|
---|
11 | #include "Actions/MapOfActions.hpp"
|
---|
12 | #include "Helpers/Assert.hpp"
|
---|
13 |
|
---|
14 | #include "CommandLineParser.hpp"
|
---|
15 | #include "log.hpp"
|
---|
16 | #include "verbose.hpp"
|
---|
17 |
|
---|
18 | /** Constructor of class MapOfActions.
|
---|
19 | *
|
---|
20 | */
|
---|
21 | MapOfActions::MapOfActions()
|
---|
22 | {
|
---|
23 | // initialise lookup map
|
---|
24 | CmdParserLookup[&generic] = &(CommandLineParser::getInstance().generic);
|
---|
25 | CmdParserLookup[&config] = &(CommandLineParser::getInstance().config);
|
---|
26 | CmdParserLookup[&hidden] = &(CommandLineParser::getInstance().hidden);
|
---|
27 | CmdParserLookup[&visible] = &(CommandLineParser::getInstance().visible);
|
---|
28 |
|
---|
29 | // keys for actions
|
---|
30 | DescriptionMap["add-atom"] = "add atom of specified element";
|
---|
31 | DescriptionMap["bond-table"] = "setting name of the bond length table file";
|
---|
32 | DescriptionMap["bond-file"] = "name of the bond file";
|
---|
33 | DescriptionMap["boundary"] = "change box to add an empty boundary around all atoms";
|
---|
34 | DescriptionMap["bound-in-box"] = "bound all atoms in the domain";
|
---|
35 | DescriptionMap["center-edge"] = "center edge of all atoms on (0,0,0)";
|
---|
36 | DescriptionMap["center-in-box"] = "center all atoms in the domain";
|
---|
37 | DescriptionMap["change-box"] = "change the symmetrc matrix of the simulation domain";
|
---|
38 | DescriptionMap["change-element"] = "change the element of an atom";
|
---|
39 | DescriptionMap["change-molname"] = "change the name of a molecule";
|
---|
40 | DescriptionMap["convex-envelope"] = "create the convex envelope for a molecule";
|
---|
41 | DescriptionMap["default-molname"] = "set the default name of new molecules";
|
---|
42 | DescriptionMap["depth-first-search"] = "Depth-First Search analysis of the molecular system";
|
---|
43 | DescriptionMap["element-db"] = "setting the path where the element databases can be found";
|
---|
44 | DescriptionMap["fastparsing"] = "setting whether trajectories shall be parsed completely (n) or just first step (y)";
|
---|
45 | DescriptionMap["fill-molecule"] = "fill empty space of box with a filler molecule";
|
---|
46 | DescriptionMap["fragment-mol"] = "create for a given molecule into fragments up to given order";
|
---|
47 | DescriptionMap["help"] = "Give this help screen";
|
---|
48 | DescriptionMap["linear-interpolate"] = "linear interpolation in discrete steps between start and end position of a molecule";
|
---|
49 | DescriptionMap["nonconvex-envelope"] = "create the non-convex envelope for a molecule";
|
---|
50 | DescriptionMap["molecular-volume"] = "calculate the volume of a given molecule";
|
---|
51 | DescriptionMap["pair-correlation"] = "pair correlation analysis between two elements";
|
---|
52 | DescriptionMap["pair-correlation-point"] = "pair correlation analysis between atoms of a element to a given point";
|
---|
53 | DescriptionMap["pair-correlation-surface"] = "pair correlation analysis between atoms of a given element and a surface";
|
---|
54 | DescriptionMap["parse-xyz"] = "parse xyz file into World";
|
---|
55 | DescriptionMap["principal-axis-system"] = "calculate the principal axis system of the specified molecule";
|
---|
56 | DescriptionMap["remove-atom"] = "remove a specified atom";
|
---|
57 | DescriptionMap["remove-sphere"] = "remove sphere of atoms of around a specified atom";
|
---|
58 | DescriptionMap["repeat-box"] = "create periodic copies of the simulation box per axis";
|
---|
59 | DescriptionMap["rotate-to-pas"] = "calculate the principal axis system of the specified molecule and rotate specified axis to align with main axis";
|
---|
60 | DescriptionMap["set-basis"] = "set the name of the gaussian basis set for MPQC";
|
---|
61 | DescriptionMap["save-adjacency"] = "name of the adjacency file to write to";
|
---|
62 | DescriptionMap["save-bonds"] = "name of the bonds file to write to";
|
---|
63 | DescriptionMap["save-temperature"] = "name of the temperature file to write to";
|
---|
64 | DescriptionMap["subspace-dissect"] = "dissect the molecular system into molecules representing disconnected subgraphs";
|
---|
65 | DescriptionMap["suspend-in-water"] = "suspend the given molecule in water such that in the domain the mean density is as specified";
|
---|
66 | DescriptionMap["translate-mol"] = "translate molecule by given vector";
|
---|
67 | DescriptionMap["verbose"] = "set verbosity level";
|
---|
68 | DescriptionMap["verlet-integrate"] = "perform verlet integration of a given force file";
|
---|
69 | DescriptionMap["version"] = "show version";
|
---|
70 | // keys for values
|
---|
71 | DescriptionMap["bin-output-file"] = "name of the bin output file";
|
---|
72 | DescriptionMap["bin-end"] = "start of the last bin";
|
---|
73 | DescriptionMap["bin-start"] = "start of the first bin";
|
---|
74 | DescriptionMap["bin-width"] = "width of the bins";
|
---|
75 | DescriptionMap["distance"] = "distance in space";
|
---|
76 | DescriptionMap["distances"] = "list of three of distances in space, one for each axis direction";
|
---|
77 | DescriptionMap["element"] = "set of elements";
|
---|
78 | DescriptionMap["end-mol"] = "last or end step";
|
---|
79 | DescriptionMap["input"] = "name of input file";
|
---|
80 | DescriptionMap["length"] = "length in space";
|
---|
81 | DescriptionMap["lengths"] = "list of three of lengths in space, one for each axis direction";
|
---|
82 | DescriptionMap["MaxDistance"] = "maximum distance in space";
|
---|
83 | DescriptionMap["molecule-by-id"] = "index of a molecule";
|
---|
84 | DescriptionMap["output-file"] = "name of the output file";
|
---|
85 | DescriptionMap["periodic"] = "system is constraint to periodic boundary conditions (y/n)";
|
---|
86 | DescriptionMap["position"] = "position in R^3 space";
|
---|
87 | DescriptionMap["start-mol"] = "first or start step";
|
---|
88 |
|
---|
89 | // short forms for the actions
|
---|
90 | ShortFormMap["add-atom"] = "a";
|
---|
91 | ShortFormMap["bond-table"] = "g";
|
---|
92 | ShortFormMap["bond-file"] = "A";
|
---|
93 | ShortFormMap["boundary"] = "c";
|
---|
94 | ShortFormMap["bound-in-box"] = "B";
|
---|
95 | ShortFormMap["center-edge"] = "O";
|
---|
96 | ShortFormMap["center-in-box"] = "b";
|
---|
97 | ShortFormMap["change-element"] = "E";
|
---|
98 | ShortFormMap["convex-envelope"] = "o";
|
---|
99 | ShortFormMap["default-molname"] = "X";
|
---|
100 | ShortFormMap["depth-first-search"] = "D";
|
---|
101 | ShortFormMap["element-db"] = "e";
|
---|
102 | ShortFormMap["fastparsing"] = "n";
|
---|
103 | ShortFormMap["fill-molecule"] = "F";
|
---|
104 | ShortFormMap["fragment-mol"] = "f";
|
---|
105 | ShortFormMap["help"] = "h";
|
---|
106 | ShortFormMap["input"] = "i";
|
---|
107 | ShortFormMap["linear-interpolate"] = "L";
|
---|
108 | ShortFormMap["nonconvex-envelope"] = "N";
|
---|
109 | ShortFormMap["pair-correlation"] = "CE";
|
---|
110 | ShortFormMap["pair-correlation-point"] = "CP";
|
---|
111 | ShortFormMap["pair-correlation-surface"] = "CS";
|
---|
112 | ShortFormMap["parse-xyz"] = "p";
|
---|
113 | ShortFormMap["remove-atom"] = "r";
|
---|
114 | ShortFormMap["remove-sphere"] = "R";
|
---|
115 | ShortFormMap["repeat-box"] = "d";
|
---|
116 | ShortFormMap["rotate-to-pas"] = "m";
|
---|
117 | ShortFormMap["save-adjacency"] = "J";
|
---|
118 | ShortFormMap["save-bonds"] = "j";
|
---|
119 | ShortFormMap["save-temperature"] = "S";
|
---|
120 | ShortFormMap["scale-box"] = "s";
|
---|
121 | ShortFormMap["set-basis"] = "M";
|
---|
122 | ShortFormMap["subspace-dissect"] = "I";
|
---|
123 | ShortFormMap["suspend-in-water"] = "U";
|
---|
124 | ShortFormMap["translate-mol"] = "t";
|
---|
125 | ShortFormMap["verbose"] = "v";
|
---|
126 | ShortFormMap["verlet-integrate"] = "P";
|
---|
127 | ShortFormMap["version"] = "V";
|
---|
128 |
|
---|
129 | // value types for the actions
|
---|
130 | TypeMap["add-atom"] = Atom;
|
---|
131 | TypeMap["bond-file"] = String;
|
---|
132 | TypeMap["bond-table"] = String;
|
---|
133 | TypeMap["boundary"] = Vector;
|
---|
134 | TypeMap["bound-in-box"] = ListOfDoubles;
|
---|
135 | TypeMap["center-in-box"] = ListOfDoubles;
|
---|
136 | TypeMap["change-box"] = ListOfDoubles;
|
---|
137 | TypeMap["change-element"] = Element;
|
---|
138 | TypeMap["change-molname"] = String;
|
---|
139 | TypeMap["convex-envelope"] = Molecule;
|
---|
140 | TypeMap["default-molname"] = String;
|
---|
141 | TypeMap["depth-first-search"] = Double;
|
---|
142 | TypeMap["element-db"] = String;
|
---|
143 | TypeMap["end-mol"] = Molecule;
|
---|
144 | TypeMap["fastparsing"] = Boolean;
|
---|
145 | TypeMap["fill-molecule"] = String;
|
---|
146 | TypeMap["fragment-mol"] = Molecule;
|
---|
147 | TypeMap["input"] = String;
|
---|
148 | TypeMap["linear-interpolate"] = String;
|
---|
149 | TypeMap["molecular-volume"] = Molecule;
|
---|
150 | TypeMap["nonconvex-envelope"] = Molecule;
|
---|
151 | TypeMap["parse-xyz"] = String;
|
---|
152 | TypeMap["principal-axis-system"] = Axis;
|
---|
153 | TypeMap["remove-atom"] = Atom;
|
---|
154 | TypeMap["remove-sphere"] = Atom;
|
---|
155 | TypeMap["repeat-box"] = ListOfInts;
|
---|
156 | TypeMap["rotate-to-pas"] = Molecule;
|
---|
157 | TypeMap["save-adjacency"] = String;
|
---|
158 | TypeMap["save-bonds"] = String;
|
---|
159 | TypeMap["save-temperature"] = String;
|
---|
160 | TypeMap["scale-box"] = Vector;
|
---|
161 | TypeMap["set-basis"] = String;
|
---|
162 | TypeMap["start-mol"] = Molecule;
|
---|
163 | TypeMap["suspend-in-water"] = Molecule;
|
---|
164 | TypeMap["translate-mol"] = Vector;
|
---|
165 | TypeMap["verlet-integrate"] = String;
|
---|
166 | TypeMap["verbose"] = Integer;
|
---|
167 | // value types for the values
|
---|
168 | TypeMap["bin-output-file"] = String;
|
---|
169 | TypeMap["bin-end"] = Double;
|
---|
170 | TypeMap["bin-start"] = Double;
|
---|
171 | TypeMap["distance"] = Double;
|
---|
172 | TypeMap["distances"] = ListOfDoubles;
|
---|
173 | TypeMap["elements"] = Element;
|
---|
174 | TypeMap["elements"] = ListOfElements;
|
---|
175 | TypeMap["length"] = Double;
|
---|
176 | TypeMap["lengths"] = ListOfDoubles;
|
---|
177 | TypeMap["MaxDistance"] = Double;
|
---|
178 | TypeMap["molecule-by-id"] = Molecule;
|
---|
179 | TypeMap["output-file"] = String;
|
---|
180 | TypeMap["periodic"] = Boolean;
|
---|
181 | TypeMap["position"] = Vector;
|
---|
182 |
|
---|
183 | // list of generic actions
|
---|
184 | // generic.insert("add-atom");
|
---|
185 | // generic.insert("bond-file");
|
---|
186 | // generic.insert("bond-table");
|
---|
187 | // generic.insert("boundary");
|
---|
188 | // generic.insert("bound-in-box");
|
---|
189 | // generic.insert("center-edge");
|
---|
190 | // generic.insert("center-in-box");
|
---|
191 | // generic.insert("change-box");
|
---|
192 | // generic.insert("change-molname");
|
---|
193 | // generic.insert("change-element");
|
---|
194 | // generic.insert("convex-envelope");
|
---|
195 | // generic.insert("default-molname");
|
---|
196 | // generic.insert("depth-first-search");
|
---|
197 | // generic.insert("element-db");
|
---|
198 | // generic.insert("fastparsing");
|
---|
199 | // generic.insert("fill-molecule");
|
---|
200 | // generic.insert("fragment-mol");
|
---|
201 | generic.insert("help");
|
---|
202 | // generic.insert("linear-interpolate");
|
---|
203 | // generic.insert("molecular-volume");
|
---|
204 | // generic.insert("nonconvex-envelope");
|
---|
205 | // generic.insert("pair-correlation");
|
---|
206 | // generic.insert("pair-correlation-point");
|
---|
207 | // generic.insert("pair-correlation-surface");
|
---|
208 | // generic.insert("parse-xyz");
|
---|
209 | // generic.insert("principal-axis-system");
|
---|
210 | // generic.insert("remove-atom");
|
---|
211 | // generic.insert("remove-sphere");
|
---|
212 | // generic.insert("rotate-to-pas");
|
---|
213 | // generic.insert("save-adjacency");
|
---|
214 | // generic.insert("save-bonds");
|
---|
215 | // generic.insert("save-temperature");
|
---|
216 | // generic.insert("scale-box");
|
---|
217 | // generic.insert("set-basis");
|
---|
218 | // generic.insert("subspace-dissect");
|
---|
219 | // generic.insert("suspend-in-water");
|
---|
220 | // generic.insert("translate-mol");
|
---|
221 | generic.insert("verbose");
|
---|
222 | // generic.insert("verlet-integrate");
|
---|
223 | generic.insert("version");
|
---|
224 | // // list of generic values
|
---|
225 | // generic.insert("bin-output-file");
|
---|
226 | // generic.insert("bin-end");
|
---|
227 | // generic.insert("bin-start");
|
---|
228 | // generic.insert("distance");
|
---|
229 | // generic.insert("distances");
|
---|
230 | // generic.insert("element");
|
---|
231 | // generic.insert("end-mol");
|
---|
232 | generic.insert("input");
|
---|
233 | // generic.insert("length");
|
---|
234 | // generic.insert("lengths");
|
---|
235 | // generic.insert("MaxDistance");
|
---|
236 | // generic.insert("molecule-by-id");
|
---|
237 | // generic.insert("output-file");
|
---|
238 | // generic.insert("periodic");
|
---|
239 | // generic.insert("position");
|
---|
240 | // generic.insert("start-mol");
|
---|
241 |
|
---|
242 | // positional arguments
|
---|
243 | inputfile.insert("input");
|
---|
244 | }
|
---|
245 |
|
---|
246 | /** Destructor of class MapOfActions.
|
---|
247 | *
|
---|
248 | */
|
---|
249 | MapOfActions::~MapOfActions()
|
---|
250 | {
|
---|
251 | DescriptionMap.clear();
|
---|
252 | }
|
---|
253 |
|
---|
254 | /** Adds all options to the CommandLineParser.
|
---|
255 | *
|
---|
256 | */
|
---|
257 | void MapOfActions::AddOptionsToParser()
|
---|
258 | {
|
---|
259 | // add other options
|
---|
260 | for (map< set<string>*, po::options_description* >::iterator ListRunner = CmdParserLookup.begin(); ListRunner != CmdParserLookup.end(); ++ListRunner) {
|
---|
261 | for (set<string>::iterator OptionRunner = ListRunner->first->begin(); OptionRunner != ListRunner->first->end(); ++OptionRunner) {
|
---|
262 | if (hasValue(*OptionRunner)) {
|
---|
263 | DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner] << " to CommandLineParser." << endl);
|
---|
264 | switch((enum OptionTypes) TypeMap[*OptionRunner]) {
|
---|
265 | default:
|
---|
266 | case None:
|
---|
267 | ListRunner->second->add_options()
|
---|
268 | (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
|
---|
269 | ;
|
---|
270 | break;
|
---|
271 | case Boolean:
|
---|
272 | ListRunner->second->add_options()
|
---|
273 | (getKeyAndShortForm(*OptionRunner).c_str(), po::value< bool >(), getDescription(*OptionRunner).c_str())
|
---|
274 | ;
|
---|
275 | break;
|
---|
276 | case Integer:
|
---|
277 | ListRunner->second->add_options()
|
---|
278 | (getKeyAndShortForm(*OptionRunner).c_str(), po::value< int >(), getDescription(*OptionRunner).c_str())
|
---|
279 | ;
|
---|
280 | break;
|
---|
281 | case ListOfInts:
|
---|
282 | ListRunner->second->add_options()
|
---|
283 | (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<int> >()->multitoken(), getDescription(*OptionRunner).c_str())
|
---|
284 | ;
|
---|
285 | break;
|
---|
286 | case Double:
|
---|
287 | ListRunner->second->add_options()
|
---|
288 | (getKeyAndShortForm(*OptionRunner).c_str(), po::value< double >(), getDescription(*OptionRunner).c_str())
|
---|
289 | ;
|
---|
290 | break;
|
---|
291 | case ListOfDoubles:
|
---|
292 | ListRunner->second->add_options()
|
---|
293 | (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<double> >()->multitoken(), getDescription(*OptionRunner).c_str())
|
---|
294 | ;
|
---|
295 | break;
|
---|
296 | case String:
|
---|
297 | ListRunner->second->add_options()
|
---|
298 | (getKeyAndShortForm(*OptionRunner).c_str(), po::value< std::string >(), getDescription(*OptionRunner).c_str())
|
---|
299 | ;
|
---|
300 | break;
|
---|
301 | case Axis:
|
---|
302 | ListRunner->second->add_options()
|
---|
303 | (getKeyAndShortForm(*OptionRunner).c_str(), po::value< int >(), getDescription(*OptionRunner).c_str())
|
---|
304 | ;
|
---|
305 | break;
|
---|
306 | case Vector:
|
---|
307 | ListRunner->second->add_options()
|
---|
308 | (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<double> >(), getDescription(*OptionRunner).c_str())
|
---|
309 | ;
|
---|
310 | break;
|
---|
311 | case Box:
|
---|
312 | ListRunner->second->add_options()
|
---|
313 | (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<double> >(), getDescription(*OptionRunner).c_str())
|
---|
314 | ;
|
---|
315 | break;
|
---|
316 | case Molecule:
|
---|
317 | ListRunner->second->add_options()
|
---|
318 | (getKeyAndShortForm(*OptionRunner).c_str(), po::value< int >(), getDescription(*OptionRunner).c_str())
|
---|
319 | ;
|
---|
320 | break;
|
---|
321 | case ListOfMolecules:
|
---|
322 | ListRunner->second->add_options()
|
---|
323 | (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<int> >()->multitoken(), getDescription(*OptionRunner).c_str())
|
---|
324 | ;
|
---|
325 | break;
|
---|
326 | case Atom:
|
---|
327 | ListRunner->second->add_options()
|
---|
328 | (getKeyAndShortForm(*OptionRunner).c_str(), po::value< int >(), getDescription(*OptionRunner).c_str())
|
---|
329 | ;
|
---|
330 | break;
|
---|
331 | case ListOfAtoms:
|
---|
332 | ListRunner->second->add_options()
|
---|
333 | (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<int> >()->multitoken(), getDescription(*OptionRunner).c_str())
|
---|
334 | ;
|
---|
335 | break;
|
---|
336 | case Element:
|
---|
337 | ListRunner->second->add_options()
|
---|
338 | (getKeyAndShortForm(*OptionRunner).c_str(), po::value< int >(), getDescription(*OptionRunner).c_str())
|
---|
339 | ;
|
---|
340 | break;
|
---|
341 | case ListOfElements:
|
---|
342 | ListRunner->second->add_options()
|
---|
343 | (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<int> >()->multitoken(), getDescription(*OptionRunner).c_str())
|
---|
344 | ;
|
---|
345 | break;
|
---|
346 | }
|
---|
347 | } else {
|
---|
348 | DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl);
|
---|
349 | ListRunner->second->add_options()
|
---|
350 | (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
|
---|
351 | ;
|
---|
352 | }
|
---|
353 | }
|
---|
354 | }
|
---|
355 | // add positional arguments
|
---|
356 | for (set<string>::iterator OptionRunner = inputfile.begin(); OptionRunner != inputfile.end(); ++OptionRunner) {
|
---|
357 | DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to positional CommandLineParser." << endl);
|
---|
358 | CommandLineParser::getInstance().inputfile.add((*OptionRunner).c_str(), -1);
|
---|
359 | }
|
---|
360 | cout << "Name for position 1: " << CommandLineParser::getInstance().inputfile.name_for_position(1) << endl;
|
---|
361 | }
|
---|
362 |
|
---|
363 | /** Getter for MapOfActions:DescriptionMap.
|
---|
364 | * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
|
---|
365 | * \param actionname name of the action to lookup
|
---|
366 | * \return Description of the action
|
---|
367 | */
|
---|
368 | std::string MapOfActions::getDescription(string actionname)
|
---|
369 | {
|
---|
370 | ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescription");
|
---|
371 | return DescriptionMap[actionname];
|
---|
372 | }
|
---|
373 |
|
---|
374 | /** Specific Getter for a MapOfActions:ShortFormMap.
|
---|
375 | * If action has a short for, then combination is as "actionname,ShortForm" (this is
|
---|
376 | * the desired format for boost::program_options). If no short form exists in the map,
|
---|
377 | * just actionname will be returned
|
---|
378 | * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
|
---|
379 | * \param actionname name of the action to lookup
|
---|
380 | * \return actionname,ShortForm or Description of the action
|
---|
381 | */
|
---|
382 | std::string MapOfActions::getKeyAndShortForm(string actionname)
|
---|
383 | {
|
---|
384 | stringstream output;
|
---|
385 | ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescriptionAndShortForm");
|
---|
386 | output << actionname;
|
---|
387 | if (ShortFormMap.find(actionname) != DescriptionMap.end())
|
---|
388 | output << "," << ShortFormMap[actionname];
|
---|
389 | return output.str();
|
---|
390 | }
|
---|
391 |
|
---|
392 | /** Getter for MapOfActions:ShortFormMap.
|
---|
393 | * Note that we assert when action does not exist CommandLineParser::ShortFormMap.
|
---|
394 | * \param actionname name of the action to lookup
|
---|
395 | * \return ShortForm of the action
|
---|
396 | */
|
---|
397 | std::string MapOfActions::getShortForm(string actionname)
|
---|
398 | {
|
---|
399 | ASSERT(ShortFormMap.find(actionname) != ShortFormMap.end(), "Unknown action name passed to MapOfActions::getShortForm");
|
---|
400 | return ShortFormMap[actionname];
|
---|
401 | }
|
---|
402 |
|
---|
403 | /** Returns whether the given action needs a value or not.
|
---|
404 | * \param actionname name of the action to look up
|
---|
405 | * \return true - value is needed, false - no value is stored in MapOfActions::TypeMap
|
---|
406 | */
|
---|
407 | bool MapOfActions::hasValue(string actionname)
|
---|
408 | {
|
---|
409 | return (TypeMap.find(actionname) != TypeMap.end());
|
---|
410 | }
|
---|
411 |
|
---|
412 | /** Getter for MapOfActions::TypeMap.
|
---|
413 | * \param actionname name of the action to look up
|
---|
414 | * \return type of the action
|
---|
415 | */
|
---|
416 | enum MapOfActions::OptionTypes MapOfActions::getValueType(string actionname)
|
---|
417 | {
|
---|
418 | return TypeMap[actionname];
|
---|
419 | }
|
---|
420 |
|
---|
421 | /** Searches whether action is registered with CommandLineParser.
|
---|
422 | * Note that this method is only meant transitionally for ParseCommandLineOptions' removal.
|
---|
423 | * I.e. All actions that are already handled by the new CommandLineUIFactory can be checked
|
---|
424 | * by this function.
|
---|
425 | * \param shortform command short form to look for
|
---|
426 | * \return true - action has been registered, false - action has not been registered.
|
---|
427 | */
|
---|
428 | bool MapOfActions::isShortFormPresent(string shortform)
|
---|
429 | {
|
---|
430 | bool result = false;
|
---|
431 | string actionname;
|
---|
432 | for (map<std::string, std::string>::iterator ShortFormRunner = ShortFormMap.begin(); ShortFormRunner != ShortFormMap.end(); ++ShortFormRunner)
|
---|
433 | if (ShortFormRunner->second == shortform) {
|
---|
434 | actionname = ShortFormRunner->first;
|
---|
435 | break;
|
---|
436 | }
|
---|
437 | result = result || (generic.find(actionname) != generic.end());
|
---|
438 | result = result || (config.find(actionname) != config.end());
|
---|
439 | result = result || (hidden.find(actionname) != hidden.end());
|
---|
440 | result = result || (visible.find(actionname) != visible.end());
|
---|
441 | result = result || (inputfile.find(actionname) != inputfile.end());
|
---|
442 | return result;
|
---|
443 | }
|
---|
444 |
|
---|
445 |
|
---|
446 |
|
---|
447 | CONSTRUCT_SINGLETON(MapOfActions)
|
---|