source: src/Actions/MapOfActions.cpp@ a02462

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since a02462 was a02462, checked in by Frederik Heber <heber@…>, 15 years ago

Case 'L' is now handled by CommandLineUI.

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