source: src/Actions/MapOfActions.cpp@ d55743e

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 d55743e was d55743e, checked in by Frederik Heber <heber@…>, 15 years ago

Case 'r' is now handled by CommandLineUI.

  • Property mode set to 100644
File size: 23.2 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-mol"] = "last or end step";
116 DescriptionMap["input"] = "name of input file";
117 DescriptionMap["length"] = "length in space";
118 DescriptionMap["lengths"] = "list of three of lengths in space, one for each axis direction";
119 DescriptionMap["MaxDistance"] = "maximum distance in space";
120 DescriptionMap["molecule-by-id"] = "index of a molecule";
121 DescriptionMap["molecule-by-name"] = "name of a molecule";
122 DescriptionMap["order"] = "order of a discretization, dissection, ...";
123 DescriptionMap["output-file"] = "name of the output file";
124 DescriptionMap["periodic"] = "system is constraint to periodic boundary conditions (y/n)";
125 DescriptionMap["position"] = "position in R^3 space";
126 DescriptionMap["start-mol"] = "first or start step";
127
128 // short forms for the actions
129 ShortFormMap["add-atom"] = "a";
130 ShortFormMap["bond-table"] = "g";
131 ShortFormMap["bond-file"] = "A";
132 ShortFormMap["boundary"] = "c";
133 ShortFormMap["change-box"] = "B";
134 ShortFormMap["center-edge"] = "O";
135 ShortFormMap["center-in-box"] = "b";
136 ShortFormMap["change-element"] = "E";
137 ShortFormMap["convex-envelope"] = "o";
138 ShortFormMap["default-molname"] = "X";
139 ShortFormMap["depth-first-search"] = "D";
140 ShortFormMap["element-db"] = "e";
141 ShortFormMap["fastparsing"] = "n";
142 ShortFormMap["fill-molecule"] = "F";
143 ShortFormMap["fragment-mol"] = "f";
144 ShortFormMap["help"] = "h";
145 ShortFormMap["input"] = "i";
146 ShortFormMap["linear-interpolate"] = "L";
147 ShortFormMap["nonconvex-envelope"] = "N";
148 ShortFormMap["pair-correlation"] = "C";
149 ShortFormMap["parse-xyz"] = "p";
150 ShortFormMap["remove-atom"] = "r";
151 ShortFormMap["remove-sphere"] = "R";
152 ShortFormMap["repeat-box"] = "d";
153 ShortFormMap["rotate-to-pas"] = "m";
154 ShortFormMap["save-adjacency"] = "J";
155 ShortFormMap["save-bonds"] = "j";
156 ShortFormMap["save-temperature"] = "S";
157 ShortFormMap["scale-box"] = "s";
158 ShortFormMap["set-basis"] = "M";
159 ShortFormMap["subspace-dissect"] = "I";
160 ShortFormMap["suspend-in-water"] = "u";
161 ShortFormMap["translate-mol"] = "t";
162 ShortFormMap["verbose"] = "v";
163 ShortFormMap["verlet-integrate"] = "P";
164 ShortFormMap["version"] = "V";
165
166 // value types for the actions
167 TypeMap["add-atom"] = Element;
168 TypeMap["bond-file"] = String;
169 TypeMap["bond-table"] = String;
170 TypeMap["boundary"] = Vector;
171 TypeMap["center-in-box"] = Box;
172 TypeMap["change-box"] = Box;
173 TypeMap["change-element"] = Atom;
174 TypeMap["change-molname"] = String;
175 TypeMap["convex-envelope"] = Molecule;
176 TypeMap["default-molname"] = String;
177 TypeMap["depth-first-search"] = Double;
178 TypeMap["element-db"] = String;
179 TypeMap["end-mol"] = Molecule;
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"] = Atom;
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["start-mol"] = Molecule;
200 TypeMap["suspend-in-water"] = Double;
201 TypeMap["translate-mol"] = Vector;
202 TypeMap["verlet-integrate"] = String;
203 TypeMap["verbose"] = Integer;
204
205 // value types for the values
206 TypeMap["atom-by-id"] = Atom;
207 TypeMap["bin-output-file"] = String;
208 TypeMap["bin-end"] = Double;
209 TypeMap["bin-start"] = Double;
210 TypeMap["bin-width"] = Double;
211 TypeMap["distance"] = Double;
212 TypeMap["distances"] = Vector;
213 TypeMap["DoRotate"] = Boolean;
214 TypeMap["element"] = Element;
215 TypeMap["elements"] = ListOfElements;
216 TypeMap["length"] = Double;
217 TypeMap["lengths"] = Vector;
218 TypeMap["MaxDistance"] = Double;
219 TypeMap["molecule-by-id"] = Molecule;
220 TypeMap["molecule-by-name"] = Molecule;
221 TypeMap["order"] = Integer;
222 TypeMap["output-file"] = String;
223 TypeMap["periodic"] = Boolean;
224 TypeMap["position"] = Vector;
225
226 // default values for any action that needs one (always string!)
227 DefaultValue["bin-width"] = "0.5";
228 DefaultValue["fastparsing"] = "0";
229 DefaultValue["atom-by-id"] = "-1";
230 DefaultValue["molecule-by-id"] = "-1";
231 DefaultValue["periodic"] = "0";
232
233
234 // list of generic actions
235 generic.insert("add-atom");
236// generic.insert("bond-file");
237 generic.insert("bond-table");
238 generic.insert("boundary");
239// generic.insert("bound-in-box");
240 generic.insert("center-edge");
241 generic.insert("center-in-box");
242 generic.insert("change-box");
243// generic.insert("change-molname");
244 generic.insert("change-element");
245// generic.insert("convex-envelope");
246 generic.insert("default-molname");
247 generic.insert("depth-first-search");
248 generic.insert("element-db");
249 generic.insert("fastparsing");
250 generic.insert("fill-molecule");
251 generic.insert("fragment-mol");
252 generic.insert("help");
253// generic.insert("linear-interpolate");
254// generic.insert("molecular-volume");
255// generic.insert("nonconvex-envelope");
256 generic.insert("pair-correlation");
257// generic.insert("parse-xyz");
258// generic.insert("principal-axis-system");
259 generic.insert("remove-atom");
260// generic.insert("remove-sphere");
261 generic.insert("repeat-box");
262 generic.insert("rotate-to-pas");
263 generic.insert("save-adjacency");
264 generic.insert("save-bonds");
265// generic.insert("save-temperature");
266 generic.insert("scale-box");
267 generic.insert("set-basis");
268// generic.insert("subspace-dissect");
269 generic.insert("suspend-in-water");
270// generic.insert("translate-mol");
271 generic.insert("verbose");
272// generic.insert("verlet-integrate");
273 generic.insert("version");
274// // list of generic values
275// generic.insert("distance");
276// generic.insert("distances");
277// generic.insert("element");
278// generic.insert("end-mol");
279 generic.insert("input");
280// generic.insert("length");
281// generic.insert("start-mol");
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("lengths");
298 generic.insert("MaxDistance");
299 generic.insert("molecule-by-id");
300 generic.insert("molecule-by-name");
301 generic.insert("order");
302 generic.insert("output-file");
303 generic.insert("periodic");
304 generic.insert("position");
305}
306
307/** Destructor of class MapOfActions.
308 *
309 */
310MapOfActions::~MapOfActions()
311{
312 DescriptionMap.clear();
313}
314
315/** Adds all options to the CommandLineParser.
316 *
317 */
318void MapOfActions::AddOptionsToParser()
319{
320 // add other options
321 for (map< set<string>*, po::options_description* >::iterator ListRunner = CmdParserLookup.begin(); ListRunner != CmdParserLookup.end(); ++ListRunner) {
322 for (set<string>::iterator OptionRunner = ListRunner->first->begin(); OptionRunner != ListRunner->first->end(); ++OptionRunner) {
323 if (hasValue(*OptionRunner)) {
324 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner] << " to CommandLineParser." << endl);
325 switch((enum OptionTypes) TypeMap[*OptionRunner]) {
326 default:
327 case None:
328 ListRunner->second->add_options()
329 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
330 ;
331 break;
332 case Boolean:
333 ListRunner->second->add_options()
334 (getKeyAndShortForm(*OptionRunner).c_str(),
335 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
336 po::value< bool >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
337 po::value< bool >(),
338 getDescription(*OptionRunner).c_str())
339 ;
340 break;
341 case Box:
342 ListRunner->second->add_options()
343 (getKeyAndShortForm(*OptionRunner).c_str(),
344 po::value<BoxValue>()->multitoken(),
345 getDescription(*OptionRunner).c_str())
346 ;
347 break;
348 case Integer:
349 ListRunner->second->add_options()
350 (getKeyAndShortForm(*OptionRunner).c_str(),
351 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
352 po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
353 po::value< int >(),
354 getDescription(*OptionRunner).c_str())
355 ;
356 break;
357 case ListOfInts:
358 ListRunner->second->add_options()
359 (getKeyAndShortForm(*OptionRunner).c_str(),
360 po::value< vector<int> >()->multitoken(),
361 getDescription(*OptionRunner).c_str())
362 ;
363 break;
364 case Double:
365 ListRunner->second->add_options()
366 (getKeyAndShortForm(*OptionRunner).c_str(),
367 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
368 po::value< double >()->default_value(atof(DefaultValue[*OptionRunner].c_str())) :
369 po::value< double >(),
370 getDescription(*OptionRunner).c_str())
371 ;
372 break;
373 case ListOfDoubles:
374 ListRunner->second->add_options()
375 (getKeyAndShortForm(*OptionRunner).c_str(),
376 po::value< vector<double> >()->multitoken(),
377 getDescription(*OptionRunner).c_str())
378 ;
379 break;
380 case String:
381 ListRunner->second->add_options()
382 (getKeyAndShortForm(*OptionRunner).c_str(),
383 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
384 po::value< std::string >()->default_value(DefaultValue[*OptionRunner]) :
385 po::value< std::string >(),
386 getDescription(*OptionRunner).c_str())
387 ;
388 break;
389 case Axis:
390 ListRunner->second->add_options()
391 (getKeyAndShortForm(*OptionRunner).c_str(),
392 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
393 po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
394 po::value< int >(),
395 getDescription(*OptionRunner).c_str())
396 ;
397 break;
398 case Vector:
399 ListRunner->second->add_options()
400 (getKeyAndShortForm(*OptionRunner).c_str(),
401 po::value<VectorValue>()->multitoken(),
402 getDescription(*OptionRunner).c_str())
403 ;
404 break;
405 case Molecule:
406 ListRunner->second->add_options()
407 (getKeyAndShortForm(*OptionRunner).c_str(),
408 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
409 po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
410 po::value< int >(),
411 getDescription(*OptionRunner).c_str())
412 ;
413 break;
414 case ListOfMolecules:
415 ListRunner->second->add_options()
416 (getKeyAndShortForm(*OptionRunner).c_str(),
417 po::value< vector<int> >()->multitoken(),
418 getDescription(*OptionRunner).c_str())
419 ;
420 break;
421 case Atom:
422 ListRunner->second->add_options()
423 (getKeyAndShortForm(*OptionRunner).c_str(),
424 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
425 po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
426 po::value< int >(),
427 getDescription(*OptionRunner).c_str())
428 ;
429 break;
430 case ListOfAtoms:
431 ListRunner->second->add_options()
432 (getKeyAndShortForm(*OptionRunner).c_str(),
433 po::value< vector<int> >()->multitoken(),
434 getDescription(*OptionRunner).c_str())
435 ;
436 break;
437 case Element:
438 ListRunner->second->add_options()
439 (getKeyAndShortForm(*OptionRunner).c_str(),
440 po::value< vector<int> >(),
441 getDescription(*OptionRunner).c_str())
442 ;
443 break;
444 case ListOfElements:
445 ListRunner->second->add_options()
446 (getKeyAndShortForm(*OptionRunner).c_str(),
447 po::value< vector<int> >()->multitoken(),
448 getDescription(*OptionRunner).c_str())
449 ;
450 break;
451 }
452 } else {
453 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl);
454 ListRunner->second->add_options()
455 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
456 ;
457 }
458 }
459 }
460 // add positional arguments
461 for (set<string>::iterator OptionRunner = inputfile.begin(); OptionRunner != inputfile.end(); ++OptionRunner) {
462 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to positional CommandLineParser." << endl);
463 CommandLineParser::getInstance().inputfile.add((*OptionRunner).c_str(), -1);
464 }
465 cout << "Name for position 1: " << CommandLineParser::getInstance().inputfile.name_for_position(1) << endl;
466}
467
468/** Getter for MapOfActions:DescriptionMap.
469 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
470 * \param actionname name of the action to lookup
471 * \return Description of the action
472 */
473std::string MapOfActions::getDescription(string actionname)
474{
475 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescription");
476 return DescriptionMap[actionname];
477}
478
479/** Specific Getter for a MapOfActions:ShortFormMap.
480 * If action has a short for, then combination is as "actionname,ShortForm" (this is
481 * the desired format for boost::program_options). If no short form exists in the map,
482 * just actionname will be returned
483 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
484 * \param actionname name of the action to lookup
485 * \return actionname,ShortForm or Description of the action
486 */
487std::string MapOfActions::getKeyAndShortForm(string actionname)
488{
489 stringstream output;
490 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescriptionAndShortForm");
491 output << actionname;
492 if (ShortFormMap.find(actionname) != DescriptionMap.end())
493 output << "," << ShortFormMap[actionname];
494 return output.str();
495}
496
497/** Getter for MapOfActions:ShortFormMap.
498 * Note that we assert when action does not exist CommandLineParser::ShortFormMap.
499 * \param actionname name of the action to lookup
500 * \return ShortForm of the action
501 */
502std::string MapOfActions::getShortForm(string actionname)
503{
504 ASSERT(ShortFormMap.find(actionname) != ShortFormMap.end(), "Unknown action name passed to MapOfActions::getShortForm");
505 return ShortFormMap[actionname];
506}
507
508/** Returns whether the given action needs a value or not.
509 * \param actionname name of the action to look up
510 * \return true - value is needed, false - no value is stored in MapOfActions::TypeMap
511 */
512bool MapOfActions::hasValue(string actionname)
513{
514 return (TypeMap.find(actionname) != TypeMap.end());
515}
516
517/** Getter for MapOfActions::TypeMap.
518 * \param actionname name of the action to look up
519 * \return type of the action
520 */
521enum MapOfActions::OptionTypes MapOfActions::getValueType(string actionname)
522{
523 return TypeMap[actionname];
524}
525
526/** Searches whether action is registered with CommandLineParser.
527 * Note that this method is only meant transitionally for ParseCommandLineOptions' removal.
528 * I.e. All actions that are already handled by the new CommandLineUIFactory can be checked
529 * by this function.
530 * \param shortform command short form to look for
531 * \return true - action has been registered, false - action has not been registered.
532 */
533bool MapOfActions::isShortFormPresent(string shortform)
534{
535 bool result = false;
536 string actionname;
537 for (map<std::string, std::string>::iterator ShortFormRunner = ShortFormMap.begin(); ShortFormRunner != ShortFormMap.end(); ++ShortFormRunner)
538 if (ShortFormRunner->second == shortform) {
539 actionname = ShortFormRunner->first;
540 break;
541 }
542 result = result || (generic.find(actionname) != generic.end());
543 result = result || (config.find(actionname) != config.end());
544 result = result || (hidden.find(actionname) != hidden.end());
545 result = result || (visible.find(actionname) != visible.end());
546 result = result || (inputfile.find(actionname) != inputfile.end());
547 return result;
548}
549
550/** Returns the inverse to MapOfActions::ShortFormMap, i.e. lookup actionname for its short form.
551 * \return map from short form of action to name of action
552 */
553map <std::string, std::string> MapOfActions::getShortFormToActionMap()
554{
555 map <std::string, std::string> result;
556
557 for (map<std::string, std::string>::iterator iter = ShortFormMap.begin(); iter != ShortFormMap.end(); ++iter)
558 result[iter->second] = iter->first;
559
560 return result;
561}
562
563
564CONSTRUCT_SINGLETON(MapOfActions)
Note: See TracBrowser for help on using the repository browser.