source: src/Actions/MapOfActions.cpp@ 980dd6

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

Case 'N' is now handled by CommandLineUI.

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