source: src/Actions/MapOfActions.cpp@ bdaacd

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

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