source: src/Actions/MapOfActions.cpp@ e6317b

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 e6317b was e6317b, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Broken: Merge commit 'Gitosis/stable' into stable

Conflicts:

molecuilder/src/Actions/AnalysisAction/PairCorrelationToPointAction.cpp
molecuilder/src/Actions/AnalysisAction/PairCorrelationToSurfaceAction.cpp
molecuilder/src/Makefile.am

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