source: src/Actions/MapOfActions.cpp@ 0d1ad0

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

ParseCommandLineOptions() is not used anymore.

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