source: src/Actions/MapOfActions.cpp@ 8540f0

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

Case 'D' is now handled by CommandLineUI.

  • Property mode set to 100644
File size: 22.8 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
54/** Constructor of class MapOfActions.
55 *
56 */
57MapOfActions::MapOfActions()
58{
59 // initialise lookup map
60 CmdParserLookup[&generic] = &(CommandLineParser::getInstance().generic);
61 CmdParserLookup[&config] = &(CommandLineParser::getInstance().config);
62 CmdParserLookup[&hidden] = &(CommandLineParser::getInstance().hidden);
63 CmdParserLookup[&visible] = &(CommandLineParser::getInstance().visible);
64
65 // keys for actions
66 DescriptionMap["add-atom"] = "add atom of specified element";
67 DescriptionMap["bond-table"] = "setting name of the bond length table file";
68 DescriptionMap["bond-file"] = "name of the bond file";
69 DescriptionMap["boundary"] = "change box to add an empty boundary around all atoms";
70 DescriptionMap["bound-in-box"] = "bound all atoms in the domain";
71 DescriptionMap["center-edge"] = "center edge of all atoms on (0,0,0)";
72 DescriptionMap["center-in-box"] = "center all atoms in the domain";
73 DescriptionMap["change-box"] = "change the symmetrc matrix of the simulation domain";
74 DescriptionMap["change-element"] = "change the element of an atom";
75 DescriptionMap["change-molname"] = "change the name of a molecule";
76 DescriptionMap["convex-envelope"] = "create the convex envelope for a molecule";
77 DescriptionMap["default-molname"] = "set the default name of new molecules";
78 DescriptionMap["depth-first-search"] = "Depth-First Search analysis of the molecular system";
79 DescriptionMap["element-db"] = "setting the path where the element databases can be found";
80 DescriptionMap["fastparsing"] = "setting whether trajectories shall be parsed completely (n) or just first step (y)";
81 DescriptionMap["fill-molecule"] = "fill empty space of box with a filler molecule";
82 DescriptionMap["fragment-mol"] = "create for a given molecule into fragments up to given order";
83 DescriptionMap["help"] = "Give this help screen";
84 DescriptionMap["linear-interpolate"] = "linear interpolation in discrete steps between start and end position of a molecule";
85 DescriptionMap["nonconvex-envelope"] = "create the non-convex envelope for a molecule";
86 DescriptionMap["molecular-volume"] = "calculate the volume of a given molecule";
87 DescriptionMap["pair-correlation"] = "pair correlation analysis between two elements";
88 DescriptionMap["pair-correlation-point"] = "pair correlation analysis between atoms of a element to a given point";
89 DescriptionMap["pair-correlation-surface"] = "pair correlation analysis between atoms of a given element and a surface";
90 DescriptionMap["parse-xyz"] = "parse xyz file into World";
91 DescriptionMap["principal-axis-system"] = "calculate the principal axis system of the specified molecule";
92 DescriptionMap["remove-atom"] = "remove a specified atom";
93 DescriptionMap["remove-sphere"] = "remove sphere of atoms of around a specified atom";
94 DescriptionMap["repeat-box"] = "create periodic copies of the simulation box per axis";
95 DescriptionMap["rotate-to-pas"] = "calculate the principal axis system of the specified molecule and rotate specified axis to align with main axis";
96 DescriptionMap["set-basis"] = "set the name of the gaussian basis set for MPQC";
97 DescriptionMap["save-adjacency"] = "name of the adjacency file to write to";
98 DescriptionMap["save-bonds"] = "name of the bonds file to write to";
99 DescriptionMap["save-temperature"] = "name of the temperature file to write to";
100 DescriptionMap["scale-box"] = "scale box and atomic positions inside";
101 DescriptionMap["subspace-dissect"] = "dissect the molecular system into molecules representing disconnected subgraphs";
102 DescriptionMap["suspend-in-water"] = "suspend the given molecule in water such that in the domain the mean density is as specified";
103 DescriptionMap["translate-mol"] = "translate molecule by given vector";
104 DescriptionMap["verbose"] = "set verbosity level";
105 DescriptionMap["verlet-integrate"] = "perform verlet integration of a given force file";
106 DescriptionMap["version"] = "show version";
107 // keys for values
108 DescriptionMap["bin-output-file"] = "name of the bin output file";
109 DescriptionMap["bin-end"] = "start of the last bin";
110 DescriptionMap["bin-start"] = "start of the first bin";
111 DescriptionMap["bin-width"] = "width of the bins";
112 DescriptionMap["distance"] = "distance in space";
113 DescriptionMap["distances"] = "list of three of distances in space, one for each axis direction";
114 DescriptionMap["DoRotate"] = "whether to rotate or just report angles";
115 DescriptionMap["element"] = "set of elements";
116 DescriptionMap["end-mol"] = "last or end step";
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["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"] = "CE";
149 ShortFormMap["pair-correlation-point"] = "CP";
150 ShortFormMap["pair-correlation-surface"] = "CS";
151 ShortFormMap["parse-xyz"] = "p";
152 ShortFormMap["remove-atom"] = "r";
153 ShortFormMap["remove-sphere"] = "R";
154 ShortFormMap["repeat-box"] = "d";
155 ShortFormMap["rotate-to-pas"] = "m";
156 ShortFormMap["save-adjacency"] = "J";
157 ShortFormMap["save-bonds"] = "j";
158 ShortFormMap["save-temperature"] = "S";
159 ShortFormMap["scale-box"] = "s";
160 ShortFormMap["set-basis"] = "M";
161 ShortFormMap["subspace-dissect"] = "I";
162 ShortFormMap["suspend-in-water"] = "u";
163 ShortFormMap["translate-mol"] = "t";
164 ShortFormMap["verbose"] = "v";
165 ShortFormMap["verlet-integrate"] = "P";
166 ShortFormMap["version"] = "V";
167
168 // value types for the actions
169 TypeMap["add-atom"] = Atom;
170 TypeMap["bond-file"] = String;
171 TypeMap["bond-table"] = String;
172 TypeMap["boundary"] = Vector;
173 TypeMap["center-in-box"] = Box;
174 TypeMap["change-box"] = Box;
175 TypeMap["change-element"] = Element;
176 TypeMap["change-molname"] = String;
177 TypeMap["convex-envelope"] = Molecule;
178 TypeMap["default-molname"] = String;
179 TypeMap["depth-first-search"] = Double;
180 TypeMap["element-db"] = String;
181 TypeMap["end-mol"] = Molecule;
182 TypeMap["fastparsing"] = Boolean;
183 TypeMap["fill-molecule"] = String;
184 TypeMap["fragment-mol"] = Molecule;
185 TypeMap["input"] = String;
186 TypeMap["linear-interpolate"] = String;
187 TypeMap["molecular-volume"] = Molecule;
188 TypeMap["nonconvex-envelope"] = Molecule;
189 TypeMap["parse-xyz"] = String;
190 TypeMap["principal-axis-system"] = Axis;
191 TypeMap["remove-atom"] = Atom;
192 TypeMap["remove-sphere"] = Atom;
193 TypeMap["repeat-box"] = Vector;
194 TypeMap["rotate-to-pas"] = Molecule;
195 TypeMap["save-adjacency"] = String;
196 TypeMap["save-bonds"] = String;
197 TypeMap["save-temperature"] = String;
198 TypeMap["scale-box"] = Vector;
199 TypeMap["set-basis"] = String;
200 TypeMap["start-mol"] = Molecule;
201 TypeMap["suspend-in-water"] = Double;
202 TypeMap["translate-mol"] = Vector;
203 TypeMap["verlet-integrate"] = String;
204 TypeMap["verbose"] = Integer;
205
206 // value types for the values
207 TypeMap["bin-output-file"] = String;
208 TypeMap["bin-end"] = Double;
209 TypeMap["bin-start"] = Double;
210 TypeMap["distance"] = Double;
211 TypeMap["distances"] = Vector;
212 TypeMap["DoRotate"] = Boolean;
213 TypeMap["elements"] = Element;
214 TypeMap["elements"] = ListOfElements;
215 TypeMap["length"] = Double;
216 TypeMap["lengths"] = Vector;
217 TypeMap["MaxDistance"] = Double;
218 TypeMap["molecule-by-id"] = 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
227
228 // list of generic actions
229// generic.insert("add-atom");
230// generic.insert("bond-file");
231// generic.insert("bond-table");
232 generic.insert("boundary");
233// generic.insert("bound-in-box");
234 generic.insert("center-edge");
235 generic.insert("center-in-box");
236 generic.insert("change-box");
237// generic.insert("change-molname");
238// generic.insert("change-element");
239// generic.insert("convex-envelope");
240// generic.insert("default-molname");
241 generic.insert("depth-first-search");
242// generic.insert("element-db");
243// generic.insert("fastparsing");
244 generic.insert("fill-molecule");
245 generic.insert("fragment-mol");
246 generic.insert("help");
247// generic.insert("linear-interpolate");
248// generic.insert("molecular-volume");
249// generic.insert("nonconvex-envelope");
250// generic.insert("pair-correlation");
251// generic.insert("pair-correlation-point");
252// generic.insert("pair-correlation-surface");
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("bin-output-file");
272// generic.insert("bin-end");
273// generic.insert("bin-start");
274// generic.insert("distance");
275// generic.insert("distances");
276// generic.insert("element");
277// generic.insert("end-mol");
278 generic.insert("input");
279// generic.insert("length");
280// generic.insert("output-file");
281// generic.insert("periodic");
282// generic.insert("position");
283// generic.insert("start-mol");
284
285 // positional arguments
286 inputfile.insert("input");
287
288 // hidden arguments
289 generic.insert("distance");
290 generic.insert("DoRotate");
291 generic.insert("distances");
292 generic.insert("lengths");
293 generic.insert("MaxDistance");
294 generic.insert("molecule-by-id");
295 generic.insert("order");
296}
297
298/** Destructor of class MapOfActions.
299 *
300 */
301MapOfActions::~MapOfActions()
302{
303 DescriptionMap.clear();
304}
305
306/** Adds all options to the CommandLineParser.
307 *
308 */
309void MapOfActions::AddOptionsToParser()
310{
311 // add other options
312 for (map< set<string>*, po::options_description* >::iterator ListRunner = CmdParserLookup.begin(); ListRunner != CmdParserLookup.end(); ++ListRunner) {
313 for (set<string>::iterator OptionRunner = ListRunner->first->begin(); OptionRunner != ListRunner->first->end(); ++OptionRunner) {
314 if (hasValue(*OptionRunner)) {
315 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner] << " to CommandLineParser." << endl);
316 switch((enum OptionTypes) TypeMap[*OptionRunner]) {
317 default:
318 case None:
319 ListRunner->second->add_options()
320 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
321 ;
322 break;
323 case Boolean:
324 ListRunner->second->add_options()
325 (getKeyAndShortForm(*OptionRunner).c_str(),
326 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
327 po::value< bool >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
328 po::value< bool >(),
329 getDescription(*OptionRunner).c_str())
330 ;
331 break;
332 case Box:
333 ListRunner->second->add_options()
334 (getKeyAndShortForm(*OptionRunner).c_str(),
335 po::value<BoxValue>()->multitoken(),
336 getDescription(*OptionRunner).c_str())
337 ;
338 break;
339 case Integer:
340 ListRunner->second->add_options()
341 (getKeyAndShortForm(*OptionRunner).c_str(),
342 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
343 po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
344 po::value< int >(),
345 getDescription(*OptionRunner).c_str())
346 ;
347 break;
348 case ListOfInts:
349 ListRunner->second->add_options()
350 (getKeyAndShortForm(*OptionRunner).c_str(),
351 po::value< vector<int> >()->multitoken(),
352 getDescription(*OptionRunner).c_str())
353 ;
354 break;
355 case Double:
356 ListRunner->second->add_options()
357 (getKeyAndShortForm(*OptionRunner).c_str(),
358 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
359 po::value< double >()->default_value(atof(DefaultValue[*OptionRunner].c_str())) :
360 po::value< double >(),
361 getDescription(*OptionRunner).c_str())
362 ;
363 break;
364 case ListOfDoubles:
365 ListRunner->second->add_options()
366 (getKeyAndShortForm(*OptionRunner).c_str(),
367 po::value< vector<double> >()->multitoken(),
368 getDescription(*OptionRunner).c_str())
369 ;
370 break;
371 case String:
372 ListRunner->second->add_options()
373 (getKeyAndShortForm(*OptionRunner).c_str(),
374 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
375 po::value< std::string >()->default_value(DefaultValue[*OptionRunner]) :
376 po::value< std::string >(),
377 getDescription(*OptionRunner).c_str())
378 ;
379 break;
380 case Axis:
381 ListRunner->second->add_options()
382 (getKeyAndShortForm(*OptionRunner).c_str(),
383 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
384 po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
385 po::value< int >(),
386 getDescription(*OptionRunner).c_str())
387 ;
388 break;
389 case Vector:
390 ListRunner->second->add_options()
391 (getKeyAndShortForm(*OptionRunner).c_str(),
392 po::value<VectorValue>()->multitoken(),
393 getDescription(*OptionRunner).c_str())
394 ;
395 break;
396 case Molecule:
397 ListRunner->second->add_options()
398 (getKeyAndShortForm(*OptionRunner).c_str(),
399 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
400 po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
401 po::value< int >(),
402 getDescription(*OptionRunner).c_str())
403 ;
404 break;
405 case ListOfMolecules:
406 ListRunner->second->add_options()
407 (getKeyAndShortForm(*OptionRunner).c_str(),
408 po::value< vector<int> >()->multitoken(),
409 getDescription(*OptionRunner).c_str())
410 ;
411 break;
412 case Atom:
413 ListRunner->second->add_options()
414 (getKeyAndShortForm(*OptionRunner).c_str(),
415 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
416 po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
417 po::value< int >(),
418 getDescription(*OptionRunner).c_str())
419 ;
420 break;
421 case ListOfAtoms:
422 ListRunner->second->add_options()
423 (getKeyAndShortForm(*OptionRunner).c_str(),
424 po::value< vector<int> >()->multitoken(),
425 getDescription(*OptionRunner).c_str())
426 ;
427 break;
428 case Element:
429 ListRunner->second->add_options()
430 (getKeyAndShortForm(*OptionRunner).c_str(),
431 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
432 po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
433 po::value< int >(),
434 getDescription(*OptionRunner).c_str())
435 ;
436 break;
437 case ListOfElements:
438 ListRunner->second->add_options()
439 (getKeyAndShortForm(*OptionRunner).c_str(),
440 po::value< vector<int> >()->multitoken(),
441 getDescription(*OptionRunner).c_str())
442 ;
443 break;
444 }
445 } else {
446 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl);
447 ListRunner->second->add_options()
448 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
449 ;
450 }
451 }
452 }
453 // add positional arguments
454 for (set<string>::iterator OptionRunner = inputfile.begin(); OptionRunner != inputfile.end(); ++OptionRunner) {
455 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to positional CommandLineParser." << endl);
456 CommandLineParser::getInstance().inputfile.add((*OptionRunner).c_str(), -1);
457 }
458 cout << "Name for position 1: " << CommandLineParser::getInstance().inputfile.name_for_position(1) << endl;
459}
460
461/** Getter for MapOfActions:DescriptionMap.
462 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
463 * \param actionname name of the action to lookup
464 * \return Description of the action
465 */
466std::string MapOfActions::getDescription(string actionname)
467{
468 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescription");
469 return DescriptionMap[actionname];
470}
471
472/** Specific Getter for a MapOfActions:ShortFormMap.
473 * If action has a short for, then combination is as "actionname,ShortForm" (this is
474 * the desired format for boost::program_options). If no short form exists in the map,
475 * just actionname will be returned
476 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
477 * \param actionname name of the action to lookup
478 * \return actionname,ShortForm or Description of the action
479 */
480std::string MapOfActions::getKeyAndShortForm(string actionname)
481{
482 stringstream output;
483 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescriptionAndShortForm");
484 output << actionname;
485 if (ShortFormMap.find(actionname) != DescriptionMap.end())
486 output << "," << ShortFormMap[actionname];
487 return output.str();
488}
489
490/** Getter for MapOfActions:ShortFormMap.
491 * Note that we assert when action does not exist CommandLineParser::ShortFormMap.
492 * \param actionname name of the action to lookup
493 * \return ShortForm of the action
494 */
495std::string MapOfActions::getShortForm(string actionname)
496{
497 ASSERT(ShortFormMap.find(actionname) != ShortFormMap.end(), "Unknown action name passed to MapOfActions::getShortForm");
498 return ShortFormMap[actionname];
499}
500
501/** Returns whether the given action needs a value or not.
502 * \param actionname name of the action to look up
503 * \return true - value is needed, false - no value is stored in MapOfActions::TypeMap
504 */
505bool MapOfActions::hasValue(string actionname)
506{
507 return (TypeMap.find(actionname) != TypeMap.end());
508}
509
510/** Getter for MapOfActions::TypeMap.
511 * \param actionname name of the action to look up
512 * \return type of the action
513 */
514enum MapOfActions::OptionTypes MapOfActions::getValueType(string actionname)
515{
516 return TypeMap[actionname];
517}
518
519/** Searches whether action is registered with CommandLineParser.
520 * Note that this method is only meant transitionally for ParseCommandLineOptions' removal.
521 * I.e. All actions that are already handled by the new CommandLineUIFactory can be checked
522 * by this function.
523 * \param shortform command short form to look for
524 * \return true - action has been registered, false - action has not been registered.
525 */
526bool MapOfActions::isShortFormPresent(string shortform)
527{
528 bool result = false;
529 string actionname;
530 for (map<std::string, std::string>::iterator ShortFormRunner = ShortFormMap.begin(); ShortFormRunner != ShortFormMap.end(); ++ShortFormRunner)
531 if (ShortFormRunner->second == shortform) {
532 actionname = ShortFormRunner->first;
533 break;
534 }
535 result = result || (generic.find(actionname) != generic.end());
536 result = result || (config.find(actionname) != config.end());
537 result = result || (hidden.find(actionname) != hidden.end());
538 result = result || (visible.find(actionname) != visible.end());
539 result = result || (inputfile.find(actionname) != inputfile.end());
540 return result;
541}
542
543
544
545CONSTRUCT_SINGLETON(MapOfActions)
Note: See TracBrowser for help on using the repository browser.