source: src/Actions/MapOfActions.cpp@ 39b639

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

Lots of small fixes to MapOfActions:

  • Property mode set to 100644
File size: 43.5 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 "Actions/MapOfActions.hpp"
13#include "Descriptors/AtomIdDescriptor.hpp"
14#include "Descriptors/MoleculeIdDescriptor.hpp"
15#include "Helpers/Assert.hpp"
16#include "Patterns/Singleton_impl.hpp"
17
18#include <boost/lexical_cast.hpp>
19#include <boost/optional.hpp>
20#include <boost/program_options.hpp>
21
22#include <iostream>
23
24#include "atom.hpp"
25#include "Box.hpp"
26#include "CommandLineParser.hpp"
27#include "element.hpp"
28#include "log.hpp"
29#include "Matrix.hpp"
30#include "molecule.hpp"
31#include "periodentafel.hpp"
32#include "vector.hpp"
33#include "verbose.hpp"
34
35#include "Actions/ActionRegistry.hpp"
36#include "Actions/AnalysisAction/MolecularVolumeAction.hpp"
37#include "Actions/AnalysisAction/PairCorrelationAction.hpp"
38#include "Actions/AnalysisAction/PointCorrelationAction.hpp"
39#include "Actions/AnalysisAction/PrincipalAxisSystemAction.hpp"
40#include "Actions/AnalysisAction/SurfaceCorrelationAction.hpp"
41#include "Actions/AtomAction/AddAction.hpp"
42#include "Actions/AtomAction/ChangeElementAction.hpp"
43#include "Actions/AtomAction/RemoveAction.hpp"
44#include "Actions/CmdAction/BondLengthTableAction.hpp"
45#include "Actions/CmdAction/ElementDbAction.hpp"
46#include "Actions/CmdAction/FastParsingAction.hpp"
47#include "Actions/CmdAction/HelpAction.hpp"
48#include "Actions/CmdAction/VerboseAction.hpp"
49#include "Actions/CmdAction/VersionAction.hpp"
50#include "Actions/FragmentationAction/DepthFirstSearchAction.hpp"
51#include "Actions/FragmentationAction/SubgraphDissectionAction.hpp"
52#include "Actions/FragmentationAction/FragmentationAction.hpp"
53#include "Actions/MoleculeAction/BondFileAction.hpp"
54#include "Actions/MoleculeAction/ChangeNameAction.hpp"
55#include "Actions/MoleculeAction/FillWithMoleculeAction.hpp"
56#include "Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.hpp"
57#include "Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.hpp"
58#include "Actions/MoleculeAction/SaveAdjacencyAction.hpp"
59#include "Actions/MoleculeAction/SaveBondsAction.hpp"
60#include "Actions/MoleculeAction/SaveTemperatureAction.hpp"
61#include "Actions/MoleculeAction/SuspendInWaterAction.hpp"
62#include "Actions/MoleculeAction/TranslateAction.hpp"
63#include "Actions/MoleculeAction/VerletIntegrationAction.hpp"
64#include "Actions/ParserAction/LoadXyzAction.hpp"
65#include "Actions/ParserAction/SaveXyzAction.hpp"
66#include "Actions/TesselationAction/ConvexEnvelopeAction.hpp"
67#include "Actions/TesselationAction/NonConvexEnvelopeAction.hpp"
68#include "Actions/WorldAction/AddEmptyBoundaryAction.hpp"
69#include "Actions/WorldAction/BoundInBoxAction.hpp"
70#include "Actions/WorldAction/CenterInBoxAction.hpp"
71#include "Actions/WorldAction/CenterOnEdgeAction.hpp"
72#include "Actions/WorldAction/ChangeBoxAction.hpp"
73#include "Actions/WorldAction/InputAction.hpp"
74#include "Actions/WorldAction/OutputAction.hpp"
75#include "Actions/WorldAction/RemoveSphereOfAtomsAction.hpp"
76#include "Actions/WorldAction/RepeatBoxAction.hpp"
77#include "Actions/WorldAction/ScaleBoxAction.hpp"
78#include "Actions/WorldAction/SetDefaultNameAction.hpp"
79#include "Actions/WorldAction/SetGaussianBasisAction.hpp"
80#include "Actions/WorldAction/SetOutputFormatsAction.hpp"
81#include "Actions/Values.hpp"
82
83void validate(boost::any& v, const std::vector<std::string>& values, VectorValue *, int)
84{
85 VectorValue VV;
86 std::vector<std::string> components;
87
88 // split comma-separated values
89 if (values.size() != 1) {
90 cerr << "Not one vector but " << components.size() << " given " << endl;
91 throw boost::program_options::validation_error("Unequal to one vector given");
92 }
93 std::string argument(values.at(0));
94 std::string::iterator Aiter = argument.begin();
95 std::string::iterator Biter = argument.begin();
96 for (; Aiter != argument.end(); ++Aiter) {
97 if (*Aiter == ',') {
98 components.push_back(string(Biter,Aiter));
99 do {
100 Aiter++;
101 } while (*Aiter == ' ' || *Aiter == '\t');
102 Biter = Aiter;
103 }
104 }
105 components.push_back(string(Biter,argument.end()));
106
107 if (components.size() != 3) {
108 cerr << "Specified vector does not have three components but " << components.size() << endl;
109 throw boost::program_options::validation_error("Specified vector does not have three components");
110 }
111 VV.x = boost::lexical_cast<double>(components.at(0));
112 VV.y = boost::lexical_cast<double>(components.at(1));
113 VV.z = boost::lexical_cast<double>(components.at(2));
114 v = boost::any(VectorValue(VV));
115}
116
117void validate(boost::any& v, const std::vector<std::string>& values, BoxValue *, int)
118{
119 BoxValue BV;
120 std::vector<std::string> components;
121
122 // split comma-separated values
123 if (values.size() != 1) {
124 cerr << "Not one vector but " << components.size() << " given " << endl;
125 throw boost::program_options::validation_error("Unequal to one vector given");
126 }
127 std::string argument(values.at(0));
128 std::string::iterator Aiter = argument.begin();
129 std::string::iterator Biter = argument.begin();
130 for (; Aiter != argument.end(); ++Aiter) {
131 if (*Aiter == ',') {
132 components.push_back(string(Biter,Aiter));
133 do {
134 Aiter++;
135 } while (*Aiter == ' ' || *Aiter == '\t');
136 Biter = Aiter;
137 }
138 }
139 components.push_back(string(Biter,argument.end()));
140
141 if (components.size() != 6) {
142 cerr << "Specified vector does not have three components but " << components.size() << endl;
143 throw boost::program_options::validation_error("Specified symmetric box matrix does not have six components");
144 }
145 BV.xx = boost::lexical_cast<double>(components.at(0));
146 BV.xy = boost::lexical_cast<double>(components.at(1));
147 BV.xz = boost::lexical_cast<double>(components.at(2));
148 BV.yy = boost::lexical_cast<double>(components.at(3));
149 BV.yz = boost::lexical_cast<double>(components.at(4));
150 BV.zz = boost::lexical_cast<double>(components.at(5));
151 v = boost::any(BoxValue(BV));
152}
153
154/** Constructor of class MapOfActions.
155 *
156 */
157MapOfActions::MapOfActions()
158{
159 // initialise lookup map
160 CmdParserLookup[&generic] = &(CommandLineParser::getInstance().generic);
161 CmdParserLookup[&config] = &(CommandLineParser::getInstance().config);
162 CmdParserLookup[&hidden] = &(CommandLineParser::getInstance().hidden);
163 CmdParserLookup[&visible] = &(CommandLineParser::getInstance().visible);
164
165 // keys for actions
166 DescriptionMap["add-atom"] = "add atom of specified element";
167 DescriptionMap["bond-table"] = "setting name of the bond length table file";
168 DescriptionMap["bond-file"] = "name of the bond file";
169 DescriptionMap["boundary"] = "change box to add an empty boundary around all atoms";
170 DescriptionMap["bound-in-box"] = "bound all atoms in the domain";
171 DescriptionMap["center-edge"] = "center edge of all atoms on (0,0,0)";
172 DescriptionMap["center-in-box"] = "center all atoms in the domain";
173 DescriptionMap["change-box"] = "change the symmetrc matrix of the simulation domain";
174 DescriptionMap["change-element"] = "change the element of an atom";
175 DescriptionMap["change-molname"] = "change the name of a molecule";
176 DescriptionMap["convex-envelope"] = "create the convex envelope for a molecule";
177 DescriptionMap["default-molname"] = "set the default name of new molecules";
178 DescriptionMap["depth-first-search"] = "Depth-First Search analysis of the molecular system";
179 DescriptionMap["element-db"] = "setting the path where the element databases can be found";
180 DescriptionMap["fastparsing"] = "setting whether trajectories shall be parsed completely (n) or just first step (y)";
181 DescriptionMap["fill-molecule"] = "fill empty space of box with a filler molecule";
182 DescriptionMap["fragment-mol"] = "create for a given molecule into fragments up to given order";
183 DescriptionMap["help"] = "Give this help screen";
184 DescriptionMap["input"] = "specify input files";
185 DescriptionMap["linear-interpolate"] = "linear interpolation in discrete steps between start and end position of a molecule";
186 DescriptionMap["molecular-volume"] = "calculate the volume of a given molecule";
187 DescriptionMap["nonconvex-envelope"] = "create the non-convex envelope for a molecule";
188 DescriptionMap["output"] = "write output files";
189 DescriptionMap["set-output"] = "specify output formats";
190 DescriptionMap["pair-correlation"] = "pair correlation analysis between two elements, element and point or element and surface";
191 DescriptionMap["parse-xyz"] = "parse xyz file into World";
192 DescriptionMap["principal-axis-system"] = "calculate the principal axis system of the specified molecule";
193 DescriptionMap["remove-atom"] = "remove a specified atom";
194 DescriptionMap["remove-sphere"] = "remove sphere of atoms of around a specified atom";
195 DescriptionMap["repeat-box"] = "create periodic copies of the simulation box per axis";
196 DescriptionMap["rotate-to-pas"] = "calculate the principal axis system of the specified molecule and rotate specified axis to align with main axis";
197 DescriptionMap["save-adjacency"] = "name of the adjacency file to write to";
198 DescriptionMap["save-bonds"] = "name of the bonds file to write to";
199 DescriptionMap["save-temperature"] = "name of the temperature file to write to";
200 DescriptionMap["SaveXyz"] = "save world as xyz file";
201 DescriptionMap["scale-box"] = "scale box and atomic positions inside";
202 DescriptionMap["set-basis"] = "set the name of the gaussian basis set for MPQC";
203 DescriptionMap["set-output"] = "specify output formats";
204 DescriptionMap["subgraph-dissect"] = "dissect the molecular system into molecules representing disconnected subgraphs";
205 DescriptionMap["suspend-in-water"] = "suspend the given molecule in water such that in the domain the mean density is as specified";
206 DescriptionMap["translate-mol"] = "translate molecule by given vector";
207 DescriptionMap["verbose"] = "set verbosity level";
208 DescriptionMap["verlet-integrate"] = "perform verlet integration of a given force file";
209 DescriptionMap["version"] = "show version";
210 // keys for values
211 DescriptionMap["atom-by-id"] = "index of an atom";
212 DescriptionMap["bin-output-file"] = "name of the bin output file";
213 DescriptionMap["bin-end"] = "start of the last bin";
214 DescriptionMap["bin-start"] = "start of the first bin";
215 DescriptionMap["bin-width"] = "width of the bins";
216 DescriptionMap["convex-file"] = "filename of the non-convex envelope";
217 DescriptionMap["distance"] = "distance in space";
218 DescriptionMap["distances"] = "list of three of distances in space, one for each axis direction";
219 DescriptionMap["DoRotate"] = "whether to rotate or just report angles";
220 DescriptionMap["element"] = "single element";
221 DescriptionMap["elements"] = "set of elements";
222 DescriptionMap["end-step"] = "last or end step";
223 DescriptionMap["id-mapping"] = "whether the identity shall be used in mapping atoms onto atoms or some closest distance measure shall be used";
224 DescriptionMap["input"] = "name of input file";
225 DescriptionMap["length"] = "length in space";
226 DescriptionMap["lengths"] = "list of three of lengths in space, one for each axis direction";
227 DescriptionMap["MaxDistance"] = "maximum distance in space";
228 DescriptionMap["molecule-by-id"] = "index of a molecule";
229 DescriptionMap["molecule-by-name"] = "name of a molecule";
230 DescriptionMap["nonconvex-file"] = "filename of the non-convex envelope";
231 DescriptionMap["order"] = "order of a discretization, dissection, ...";
232 DescriptionMap["output-file"] = "name of the output file";
233 DescriptionMap["periodic"] = "system is constraint to periodic boundary conditions (y/n)";
234 DescriptionMap["position"] = "position in R^3 space";
235 DescriptionMap["sphere-radius"] = "radius of tesselation sphere";
236 DescriptionMap["start-step"] = "first or start step";
237
238 // short forms for the actions
239 ShortFormMap["add-atom"] = "a";
240 ShortFormMap["bond-table"] = "g";
241 ShortFormMap["bond-file"] = "A";
242 ShortFormMap["boundary"] = "c";
243 ShortFormMap["change-box"] = "B";
244 ShortFormMap["center-edge"] = "O";
245 ShortFormMap["center-in-box"] = "b";
246 ShortFormMap["change-element"] = "E";
247// ShortFormMap["convex-envelope"] = "x";
248 ShortFormMap["default-molname"] = "X";
249 ShortFormMap["depth-first-search"] = "D";
250 ShortFormMap["element-db"] = "e";
251 ShortFormMap["fastparsing"] = "n";
252 ShortFormMap["fill-molecule"] = "F";
253 ShortFormMap["fragment-mol"] = "f";
254 ShortFormMap["help"] = "h";
255 ShortFormMap["input"] = "i";
256 ShortFormMap["linear-interpolate"] = "L";
257 ShortFormMap["nonconvex-envelope"] = "N";
258// ShortFormMap["output"] = "o";
259 ShortFormMap["pair-correlation"] = "C";
260 ShortFormMap["parse-xyz"] = "p";
261 ShortFormMap["remove-atom"] = "r";
262 ShortFormMap["remove-sphere"] = "R";
263 ShortFormMap["repeat-box"] = "d";
264 ShortFormMap["rotate-to-pas"] = "m";
265 ShortFormMap["save-adjacency"] = "J";
266 ShortFormMap["save-bonds"] = "j";
267 ShortFormMap["save-temperature"] = "S";
268 ShortFormMap["scale-box"] = "s";
269 ShortFormMap["set-basis"] = "M";
270 ShortFormMap["set-output"] = "o";
271 ShortFormMap["subgraph-dissect"] = "I";
272 ShortFormMap["suspend-in-water"] = "u";
273 ShortFormMap["translate-mol"] = "t";
274 ShortFormMap["verbose"] = "v";
275 ShortFormMap["verlet-integrate"] = "P";
276 ShortFormMap["version"] = "V";
277
278 // value types for the actions
279 TypeMap["add-atom"] = &typeid(element);
280 TypeMap["bond-file"] = &typeid(std::string);
281 TypeMap["bond-table"] = &typeid(std::string);
282 TypeMap["boundary"] = &typeid(VectorValue);
283 TypeMap["center-in-box"] = &typeid(BoxValue);
284 TypeMap["change-box"] = &typeid(BoxValue);
285 TypeMap["change-element"] = &typeid(element);
286 TypeMap["change-molname"] = &typeid(std::string);
287 TypeMap["convex-envelope"] = &typeid(molecule);
288 TypeMap["default-molname"] = &typeid(std::string);
289 TypeMap["depth-first-search"] = &typeid(double);
290 TypeMap["element-db"] = &typeid(std::string);
291 TypeMap["fastparsing"] = &typeid(bool);
292 TypeMap["fill-molecule"] = &typeid(std::string);
293 TypeMap["fragment-mol"] = &typeid(std::string);
294 TypeMap["input"] = &typeid(std::string);
295 TypeMap["linear-interpolate"] = &typeid(std::string);
296 TypeMap["molecular-volume"] = &typeid(molecule);
297 TypeMap["nonconvex-envelope"] = &typeid(molecule);
298 TypeMap["output"] = &typeid(void);
299 TypeMap["parse-xyz"] = &typeid(std::string);
300 TypeMap["pair-correlation"] = &typeid(std::string);
301 TypeMap["principal-axis-system"] = &typeid(molecule);
302 TypeMap["remove-atom"] = &typeid(atom);
303 TypeMap["remove-sphere"] = &typeid(double);
304 TypeMap["repeat-box"] = &typeid(VectorValue);
305 TypeMap["rotate-to-pas"] = &typeid(molecule);
306 TypeMap["save-adjacency"] = &typeid(std::string);
307 TypeMap["save-bonds"] = &typeid(std::string);
308 TypeMap["save-temperature"] = &typeid(std::string);
309 TypeMap["scale-box"] = &typeid(VectorValue);
310 TypeMap["set-basis"] = &typeid(std::string);
311 TypeMap["set-output"] = &typeid(std::vector<std::string>);
312 TypeMap["subgraph-dissect"] = &typeid(void);
313 TypeMap["suspend-in-water"] = &typeid(double);
314 TypeMap["translate-mol"] = &typeid(VectorValue);
315 TypeMap["verlet-integrate"] = &typeid(std::string);
316 TypeMap["verbose"] = &typeid(int);
317
318 // value types for the values
319 TypeMap["atom-by-id"] = &typeid(atom);
320 TypeMap["bin-output-file"] = &typeid(std::string);
321 TypeMap["bin-end"] = &typeid(double);
322 TypeMap["bin-start"] = &typeid(double);
323 TypeMap["bin-width"] = &typeid(double);
324 TypeMap["convex-file"] = &typeid(std::string);
325 TypeMap["distance"] = &typeid(double);
326 TypeMap["distances"] = &typeid(VectorValue);
327 TypeMap["DoRotate"] = &typeid(bool);
328 TypeMap["element"] = &typeid(element);
329 TypeMap["elements"] = &typeid(std::vector<element *>);
330 TypeMap["end-step"] = &typeid(int);
331 TypeMap["id-mapping"] = &typeid(bool);
332 TypeMap["length"] = &typeid(double);
333 TypeMap["lengths"] = &typeid(VectorValue);
334 TypeMap["MaxDistance"] = &typeid(double);
335 TypeMap["molecule-by-id"] = &typeid(molecule);
336 TypeMap["molecule-by-name"] = &typeid(std::string);
337 TypeMap["nonconvex-file"] = &typeid(std::string);
338 TypeMap["order"] = &typeid(int);
339 TypeMap["output-file"] = &typeid(std::string);
340 TypeMap["periodic"] = &typeid(bool);
341 TypeMap["position"] = &typeid(VectorValue);
342 TypeMap["sphere-radius"] = &typeid(double);
343 TypeMap["start-step"] = &typeid(int);
344
345 TypeEnumMap[&typeid(void)] = None;
346 TypeEnumMap[&typeid(bool)] = Boolean;
347 TypeEnumMap[&typeid(int)] = Integer;
348 TypeEnumMap[&typeid(std::vector<int>)] = ListOfIntegers;
349 TypeEnumMap[&typeid(double)] = Double;
350 TypeEnumMap[&typeid(std::vector<double>)] = ListOfDoubles;
351 TypeEnumMap[&typeid(std::string)] = String;
352 TypeEnumMap[&typeid(std::vector<std::string>)] = ListOfStrings;
353 TypeEnumMap[&typeid(VectorValue)] = Vector;
354 TypeEnumMap[&typeid(std::vector<VectorValue>)] = ListOfVectors;
355 TypeEnumMap[&typeid(BoxValue)] = Box;
356 TypeEnumMap[&typeid(molecule)] = Molecule;
357 TypeEnumMap[&typeid(std::vector<molecule *>)] = ListOfMolecules;
358 TypeEnumMap[&typeid(atom)] = Atom;
359 TypeEnumMap[&typeid(std::vector<atom *>)] = ListOfAtoms;
360 TypeEnumMap[&typeid(element)] = Element;
361 TypeEnumMap[&typeid(std::vector<element *>)] = ListOfElements;
362
363 // default values for any action that needs one (always string!)
364 CurrentValue["bin-width"] = "0.5";
365 CurrentValue["fastparsing"] = "0";
366 CurrentValue["atom-by-id"] = "-1";
367 CurrentValue["molecule-by-id"] = "-1";
368 CurrentValue["periodic"] = "0";
369
370 // put action into each menu category
371 MenuDescription["analysis"] = pair<std::string,std::string>("Analysis (pair correlation, volume)", "Analysis");
372 MenuDescription["atom"] = pair<std::string,std::string>("Edit atoms", "Edit atoms");
373 MenuDescription["command"] = pair<std::string,std::string>("Configuration", "Configuration");
374 MenuDescription["fragmentation"] = pair<std::string,std::string>("Fragmentation", "Fragmentation");
375 MenuDescription["molecule"] = pair<std::string,std::string>("Parse files into system", "Parse files");
376 MenuDescription["parser"] = pair<std::string,std::string>("Edit molecules (load, parse, save)", "Edit molecules");
377 MenuDescription["tesselation"] = pair<std::string,std::string>("Tesselate molecules", "Tesselate molecules");
378 MenuDescription["world"] = pair<std::string,std::string>("Edit world", "Edit world");
379
380 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "molecular-volume") );
381 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "pair-correlation") );
382 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "principal-axis-system") );
383
384 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "add-atom") );
385 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "change-element") );
386 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "remove-atom") );
387
388 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "bond-table") );
389 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "element-db") );
390 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "fastparsing") );
391 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "verbose") );
392 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "version") );
393
394 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "depth-first-search") );
395 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "fragment-mol") );
396 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "subgraph-dissect") );
397
398 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "bond-file") );
399 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "change-molname") );
400 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "fill-molecule") );
401 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "linear-interpolate") );
402 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "rotate-to-pas") );
403 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-adjacency") );
404 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-bonds") );
405 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-temperature") );
406 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "suspend-in-water") );
407 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "translate-mol") );
408 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "verlet-integrate") );
409
410 MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "parse-xyz") );
411 MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "SaveXyz") );
412
413 MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "convex-envelope") );
414 MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "nonconvex-envelope") );
415
416 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "boundary") );
417 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "bound-in-box") );
418 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-in-box") );
419 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-edge") );
420 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "change-box") );
421 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "input") );
422 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "output") );
423 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "remove-sphere") );
424 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "repeat-box") );
425 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "scale-box") );
426 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "default-molname") );
427 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-basis") );
428 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-output") );
429
430 // put actions into command line category
431 generic.insert("add-atom");
432 generic.insert("bond-file");
433 generic.insert("bond-table");
434 generic.insert("boundary");
435// generic.insert("bound-in-box");
436 generic.insert("center-edge");
437 generic.insert("center-in-box");
438 generic.insert("change-box");
439// generic.insert("change-molname");
440 generic.insert("change-element");
441 generic.insert("convex-envelope");
442 generic.insert("default-molname");
443 generic.insert("depth-first-search");
444 generic.insert("element-db");
445 generic.insert("fastparsing");
446 generic.insert("fill-molecule");
447 generic.insert("fragment-mol");
448 generic.insert("help");
449 generic.insert("input");
450 generic.insert("linear-interpolate");
451// generic.insert("molecular-volume");
452 generic.insert("nonconvex-envelope");
453 generic.insert("output");
454 generic.insert("pair-correlation");
455 generic.insert("parse-xyz");
456// generic.insert("principal-axis-system");
457 generic.insert("remove-atom");
458 generic.insert("remove-sphere");
459 generic.insert("repeat-box");
460 generic.insert("rotate-to-pas");
461 generic.insert("save-adjacency");
462 generic.insert("save-bonds");
463 generic.insert("save-temperature");
464 generic.insert("scale-box");
465 generic.insert("set-basis");
466 generic.insert("set-output");
467 generic.insert("subgraph-dissect");
468 generic.insert("suspend-in-water");
469 generic.insert("translate-mol");
470 generic.insert("verbose");
471 generic.insert("verlet-integrate");
472 generic.insert("version");
473
474 // positional arguments
475 generic.insert("input");
476 inputfile.insert("input");
477
478 // hidden arguments
479 generic.insert("atom-by-id");
480 generic.insert("bin-end");
481 generic.insert("bin-output-file");
482 generic.insert("bin-start");
483 generic.insert("bin-width");
484 generic.insert("convex-file");
485 generic.insert("distance");
486 generic.insert("DoRotate");
487 generic.insert("distances");
488 generic.insert("element");
489 generic.insert("elements");
490 generic.insert("end-step");
491 generic.insert("id-mapping");
492 generic.insert("lengths");
493 generic.insert("MaxDistance");
494 generic.insert("molecule-by-id");
495 generic.insert("molecule-by-name");
496 generic.insert("nonconvex-file");
497 generic.insert("order");
498 generic.insert("output-file");
499 generic.insert("periodic");
500 generic.insert("position");
501 generic.insert("sphere-radius");
502 generic.insert("start-step");
503}
504
505/** Destructor of class MapOfActions.
506 *
507 */
508MapOfActions::~MapOfActions()
509{
510 DescriptionMap.clear();
511}
512
513void MapOfActions::queryCurrentValue(const char * name, class atom * &_T)
514{
515 int atomID = -1;
516 if (typeid( atom ) == *TypeMap[name]) {
517 if (CurrentValue.find(name) == CurrentValue.end())
518 throw MissingValueException(__FILE__, __LINE__);
519 atomID = lexical_cast<int>(CurrentValue[name].c_str());
520 CurrentValue.erase(name);
521 } else
522 throw IllegalTypeException(__FILE__,__LINE__);
523 _T = World::getInstance().getAtom(AtomById(atomID));
524}
525
526void MapOfActions::queryCurrentValue(const char * name, class element * &_T) {
527 int Z = -1;
528 if (typeid( element ) == *TypeMap[name]) {
529 if (CurrentValue.find(name) == CurrentValue.end())
530 throw MissingValueException(__FILE__, __LINE__);
531 Z = lexical_cast<int>(CurrentValue[name].c_str());
532 CurrentValue.erase(name);
533 } else
534 throw IllegalTypeException(__FILE__,__LINE__);
535 _T = World::getInstance().getPeriode()->FindElement(Z);
536}
537
538void MapOfActions::queryCurrentValue(const char * name, class molecule * &_T) {
539 int molID = -1;
540 if (typeid( molecule ) == *TypeMap[name]) {
541 if (CurrentValue.find(name) == CurrentValue.end())
542 throw MissingValueException(__FILE__, __LINE__);
543 molID = lexical_cast<int>(CurrentValue[name].c_str());
544 CurrentValue.erase(name);
545 } else
546 throw IllegalTypeException(__FILE__,__LINE__);
547 _T = World::getInstance().getMolecule(MoleculeById(molID));
548}
549
550void MapOfActions::queryCurrentValue(const char * name, class Box &_T) {
551 Matrix M;
552 double tmp;
553 if (typeid( BoxValue ) == *TypeMap[name]) {
554 if (CurrentValue.find(name) == CurrentValue.end())
555 throw MissingValueException(__FILE__, __LINE__);
556 std::istringstream stream(CurrentValue[name]);
557 stream >> tmp;
558 M.set(0,0,tmp);
559 stream >> tmp;
560 M.set(0,1,tmp);
561 M.set(1,0,tmp);
562 stream >> tmp;
563 M.set(0,2,tmp);
564 M.set(2,0,tmp);
565 stream >> tmp;
566 M.set(1,1,tmp);
567 stream >> tmp;
568 M.set(1,2,tmp);
569 M.set(2,1,tmp);
570 stream >> tmp;
571 M.set(2,2,tmp);
572 _T = M;
573 CurrentValue.erase(name);
574 } else
575 throw IllegalTypeException(__FILE__,__LINE__);
576}
577
578void MapOfActions::queryCurrentValue(const char * name, class Vector &_T) {
579 if (typeid( VectorValue ) == *TypeMap[name]) {
580 std::istringstream stream(CurrentValue[name]);
581 CurrentValue.erase(name);
582 stream >> _T[0];
583 stream >> _T[1];
584 stream >> _T[2];
585 } else
586 throw IllegalTypeException(__FILE__,__LINE__);
587}
588
589void MapOfActions::queryCurrentValue(const char * name, std::vector<atom *>&_T)
590{
591 int atomID = -1;
592 atom *Walker = NULL;
593 if (typeid( std::vector<atom *> ) == *TypeMap[name]) {
594 if (CurrentValue.find(name) == CurrentValue.end())
595 throw MissingValueException(__FILE__, __LINE__);
596 std::istringstream stream(CurrentValue[name]);
597 CurrentValue.erase(name);
598 while (!stream.fail()) {
599 stream >> atomID;
600 Walker = World::getInstance().getAtom(AtomById(atomID));
601 if (Walker != NULL)
602 _T.push_back(Walker);
603 }
604 } else
605 throw IllegalTypeException(__FILE__,__LINE__);
606}
607
608void MapOfActions::queryCurrentValue(const char * name, std::vector<element *>&_T)
609{
610 int Z = -1;
611 element *elemental = NULL;
612 if (typeid( std::vector<element *> ) == *TypeMap[name]) {
613 if (CurrentValue.find(name) == CurrentValue.end())
614 throw MissingValueException(__FILE__, __LINE__);
615 std::istringstream stream(CurrentValue[name]);
616 CurrentValue.erase(name);
617 while (!stream.fail()) {
618 stream >> Z;
619 elemental = World::getInstance().getPeriode()->FindElement(Z);
620 if (elemental != NULL)
621 _T.push_back(elemental);
622 }
623 } else
624 throw IllegalTypeException(__FILE__,__LINE__);
625}
626
627void MapOfActions::queryCurrentValue(const char * name, std::vector<molecule *>&_T)
628{
629 int molID = -1;
630 molecule *mol = NULL;
631 if (typeid( std::vector<molecule *> ) == *TypeMap[name]) {
632 if (CurrentValue.find(name) == CurrentValue.end())
633 throw MissingValueException(__FILE__, __LINE__);
634 std::istringstream stream(CurrentValue[name]);
635 CurrentValue.erase(name);
636 while (!stream.fail()) {
637 stream >> molID;
638 mol = World::getInstance().getMolecule(MoleculeById(molID));
639 if (mol != NULL)
640 _T.push_back(mol);
641 }
642 } else
643 throw IllegalTypeException(__FILE__,__LINE__);
644}
645
646
647void MapOfActions::setCurrentValue(const char * name, class atom * &_T)
648{
649 if (typeid( atom ) == *TypeMap[name]) {
650 std::ostringstream stream;
651 stream << _T->getId();
652 CurrentValue[name] = stream.str();
653 } else
654 throw IllegalTypeException(__FILE__,__LINE__);
655}
656
657void MapOfActions::setCurrentValue(const char * name, class element * &_T)
658{
659 if (typeid( element ) == *TypeMap[name]) {
660 std::ostringstream stream;
661 stream << _T->Z;
662 CurrentValue[name] = stream.str();
663 } else
664 throw IllegalTypeException(__FILE__,__LINE__);
665}
666
667void MapOfActions::setCurrentValue(const char * name, class molecule * &_T)
668{
669 if (typeid( molecule ) == *TypeMap[name]) {
670 std::ostringstream stream;
671 stream << _T->getId();
672 CurrentValue[name] = stream.str();
673 } else
674 throw IllegalTypeException(__FILE__,__LINE__);
675}
676
677void MapOfActions::setCurrentValue(const char * name, class Box &_T)
678{
679 const Matrix &M = _T.getM();
680 if (typeid( BoxValue ) == *TypeMap[name]) {
681 std::ostringstream stream;
682 stream << M.at(0,0) << " ";
683 stream << M.at(0,1) << " ";
684 stream << M.at(0,2) << " ";
685 stream << M.at(1,1) << " ";
686 stream << M.at(1,2) << " ";
687 stream << M.at(2,2) << " ";
688 CurrentValue[name] = stream.str();
689 } else
690 throw IllegalTypeException(__FILE__,__LINE__);
691}
692
693void MapOfActions::setCurrentValue(const char * name, class Vector &_T)
694{
695 if (typeid( VectorValue ) == *TypeMap[name]){
696 std::ostringstream stream;
697 stream << _T[0] << " ";
698 stream << _T[1] << " ";
699 stream << _T[2] << " ";
700 CurrentValue[name] = stream.str();
701 } else
702 throw IllegalTypeException(__FILE__,__LINE__);
703}
704
705void MapOfActions::setCurrentValue(const char * name, std::vector<atom *>&_T)
706{
707 if (typeid( std::vector<atom *> ) == *TypeMap[name]) {
708 std::ostringstream stream;
709 for (std::vector<atom *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
710 stream << (*iter)->getId() << " ";
711 }
712 CurrentValue[name] = stream.str();
713 } else
714 throw IllegalTypeException(__FILE__,__LINE__);
715}
716
717void MapOfActions::setCurrentValue(const char * name, std::vector<element *>&_T)
718{
719 if (typeid( std::vector<element *> ) == *TypeMap[name]) {
720 std::ostringstream stream;
721 for (std::vector<element *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
722 stream << (*iter)->Z << " ";
723 }
724 CurrentValue[name] = stream.str();
725 } else
726 throw IllegalTypeException(__FILE__,__LINE__);
727}
728
729void MapOfActions::setCurrentValue(const char * name, std::vector<molecule *>&_T)
730{
731 if (typeid( std::vector<molecule *> ) == *TypeMap[name]) {
732 std::ostringstream stream;
733 for (std::vector<molecule *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
734 stream << (*iter)->getId() << " ";
735 }
736 CurrentValue[name] = stream.str();
737 } else
738 throw IllegalTypeException(__FILE__,__LINE__);
739}
740
741
742
743void MapOfActions::populateActions()
744{
745 new AnalysisMolecularVolumeAction();
746 new AnalysisPairCorrelationAction();
747 new AnalysisPointCorrelationAction();
748 new AnalysisPrincipalAxisSystemAction();
749 new AnalysisSurfaceCorrelationAction();
750
751 new AtomAddAction();
752 new AtomChangeElementAction();
753 new AtomRemoveAction();
754
755 new CommandLineBondLengthTableAction();
756 new CommandLineElementDbAction();
757 new CommandLineFastParsingAction();
758 new CommandLineHelpAction();
759 new CommandLineVerboseAction();
760 new CommandLineVersionAction();
761
762 new FragmentationDepthFirstSearchAction();
763 new FragmentationFragmentationAction();
764 new FragmentationSubgraphDissectionAction();
765
766 new MoleculeBondFileAction();
767 new MoleculeChangeNameAction();
768 new MoleculeFillWithMoleculeAction();
769 new MoleculeLinearInterpolationofTrajectoriesAction();
770 new MoleculeRotateToPrincipalAxisSystemAction();
771 new MoleculeSaveAdjacencyAction();
772 new MoleculeSaveBondsAction();
773 new MoleculeSaveTemperatureAction();
774 new MoleculeSuspendInWaterAction();
775 new MoleculeTranslateAction();
776 new MoleculeVerletIntegrationAction();
777
778 new ParserLoadXyzAction();
779 new ParserSaveXyzAction();
780
781 new TesselationConvexEnvelopeAction();
782 new TesselationNonConvexEnvelopeAction();
783
784 new WorldAddEmptyBoundaryAction();
785 new WorldBoundInBoxAction();
786 new WorldCenterInBoxAction();
787 new WorldCenterOnEdgeAction();
788 new WorldChangeBoxAction();
789 new WorldInputAction();
790 new WorldOutputAction();
791 new WorldRemoveSphereOfAtomsAction();
792 new WorldRepeatBoxAction();
793 new WorldScaleBoxAction();
794 new WorldSetDefaultNameAction();
795 new WorldSetGaussianBasisAction();
796 new WorldSetOutputFormatsAction();
797}
798
799/** Adds all options to the CommandLineParser.
800 *
801 */
802void MapOfActions::AddOptionsToParser()
803{
804 // add other options
805 for (map< set<string>*, po::options_description* >::iterator ListRunner = CmdParserLookup.begin(); ListRunner != CmdParserLookup.end(); ++ListRunner) {
806 for (set<string>::iterator OptionRunner = ListRunner->first->begin(); OptionRunner != ListRunner->first->end(); ++OptionRunner) {
807 if (hasValue(*OptionRunner)) {
808 DoLog(3) && (Log() << Verbose(3) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner]->name() << " to CommandLineParser." << endl);
809 switch(TypeEnumMap[TypeMap[*OptionRunner]]) {
810 default:
811 case None:
812 ListRunner->second->add_options()
813 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
814 ;
815 break;
816 case Boolean:
817 ListRunner->second->add_options()
818 (getKeyAndShortForm(*OptionRunner).c_str(),
819 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
820 po::value< bool >()->default_value(lexical_cast<int>(CurrentValue[*OptionRunner].c_str())) :
821 po::value< bool >(),
822 getDescription(*OptionRunner).c_str())
823 ;
824 break;
825 case Box:
826 ListRunner->second->add_options()
827 (getKeyAndShortForm(*OptionRunner).c_str(),
828 po::value<BoxValue>(),
829 getDescription(*OptionRunner).c_str())
830 ;
831 break;
832 case Integer:
833 ListRunner->second->add_options()
834 (getKeyAndShortForm(*OptionRunner).c_str(),
835 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
836 po::value< int >()->default_value(lexical_cast<int>(CurrentValue[*OptionRunner].c_str())) :
837 po::value< int >(),
838 getDescription(*OptionRunner).c_str())
839 ;
840 break;
841 case ListOfIntegers:
842 ListRunner->second->add_options()
843 (getKeyAndShortForm(*OptionRunner).c_str(),
844 po::value< vector<int> >()->multitoken(),
845 getDescription(*OptionRunner).c_str())
846 ;
847 break;
848 case Double:
849 ListRunner->second->add_options()
850 (getKeyAndShortForm(*OptionRunner).c_str(),
851 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
852 po::value< double >()->default_value(lexical_cast<double>(CurrentValue[*OptionRunner].c_str())) :
853 po::value< double >(),
854 getDescription(*OptionRunner).c_str())
855 ;
856 break;
857 case ListOfDoubles:
858 ListRunner->second->add_options()
859 (getKeyAndShortForm(*OptionRunner).c_str(),
860 po::value< vector<double> >()->multitoken(),
861 getDescription(*OptionRunner).c_str())
862 ;
863 break;
864 case String:
865 ListRunner->second->add_options()
866 (getKeyAndShortForm(*OptionRunner).c_str(),
867 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
868 po::value< std::string >()->default_value(CurrentValue[*OptionRunner]) :
869 po::value< std::string >(),
870 getDescription(*OptionRunner).c_str())
871 ;
872 break;
873 case ListOfStrings:
874 ListRunner->second->add_options()
875 (getKeyAndShortForm(*OptionRunner).c_str(),
876 po::value< vector<std::string> >()->multitoken(),
877 getDescription(*OptionRunner).c_str())
878 ;
879 break;
880 case Vector:
881 ListRunner->second->add_options()
882 (getKeyAndShortForm(*OptionRunner).c_str(),
883 po::value<VectorValue>(),
884 getDescription(*OptionRunner).c_str())
885 ;
886 break;
887 case ListOfVectors:
888 ListRunner->second->add_options()
889 (getKeyAndShortForm(*OptionRunner).c_str(),
890 po::value< vector<VectorValue> >()->multitoken(),
891 getDescription(*OptionRunner).c_str())
892 ;
893 break;
894 case Molecule:
895 ListRunner->second->add_options()
896 (getKeyAndShortForm(*OptionRunner).c_str(),
897 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
898 po::value< int >()->default_value(lexical_cast<int>(CurrentValue[*OptionRunner].c_str())) :
899 po::value< int >(),
900 getDescription(*OptionRunner).c_str())
901 ;
902 break;
903 case ListOfMolecules:
904 ListRunner->second->add_options()
905 (getKeyAndShortForm(*OptionRunner).c_str(),
906 po::value< vector<int> >()->multitoken(),
907 getDescription(*OptionRunner).c_str())
908 ;
909 break;
910 case Atom:
911 ListRunner->second->add_options()
912 (getKeyAndShortForm(*OptionRunner).c_str(),
913 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
914 po::value< int >()->default_value(lexical_cast<int>(CurrentValue[*OptionRunner].c_str())) :
915 po::value< int >(),
916 getDescription(*OptionRunner).c_str())
917 ;
918 break;
919 case ListOfAtoms:
920 ListRunner->second->add_options()
921 (getKeyAndShortForm(*OptionRunner).c_str(),
922 po::value< vector<int> >()->multitoken(),
923 getDescription(*OptionRunner).c_str())
924 ;
925 break;
926 case Element:
927 ListRunner->second->add_options()
928 (getKeyAndShortForm(*OptionRunner).c_str(),
929 po::value< int >(),
930 getDescription(*OptionRunner).c_str())
931 ;
932 break;
933 case ListOfElements:
934 ListRunner->second->add_options()
935 (getKeyAndShortForm(*OptionRunner).c_str(),
936 po::value< vector<int> >()->multitoken(),
937 getDescription(*OptionRunner).c_str())
938 ;
939 break;
940 }
941 } else {
942 DoLog(3) && (Log() << Verbose(3) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl);
943 ListRunner->second->add_options()
944 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
945 ;
946 }
947 }
948 }
949 // add positional arguments
950 for (set<string>::iterator OptionRunner = inputfile.begin(); OptionRunner != inputfile.end(); ++OptionRunner) {
951 DoLog(3) && (Log() << Verbose(3) << "Adding option " << *OptionRunner << " to positional CommandLineParser." << endl);
952 CommandLineParser::getInstance().inputfile.add((*OptionRunner).c_str(), -1);
953 }
954 cout << "Name for position 1: " << CommandLineParser::getInstance().inputfile.name_for_position(1) << endl;
955}
956
957/** Getter for MapOfActions:DescriptionMap.
958 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
959 * \param actionname name of the action to lookup
960 * \return Description of the action
961 */
962std::string MapOfActions::getDescription(string actionname)
963{
964 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescription");
965 return DescriptionMap[actionname];
966}
967
968/** Specific Getter for a MapOfActions:ShortFormMap.
969 * If action has a short for, then combination is as "actionname,ShortForm" (this is
970 * the desired format for boost::program_options). If no short form exists in the map,
971 * just actionname will be returned
972 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
973 * \param actionname name of the action to lookup
974 * \return actionname,ShortForm or Description of the action
975 */
976std::string MapOfActions::getKeyAndShortForm(string actionname)
977{
978 stringstream output;
979 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescriptionAndShortForm");
980 output << actionname;
981 if (ShortFormMap.find(actionname) != DescriptionMap.end())
982 output << "," << ShortFormMap[actionname];
983 return output.str();
984}
985
986/** Getter for MapOfActions:ShortFormMap.
987 * Note that we assert when action does not exist CommandLineParser::ShortFormMap.
988 * \param actionname name of the action to lookup
989 * \return ShortForm of the action
990 */
991std::string MapOfActions::getShortForm(string actionname)
992{
993 ASSERT(ShortFormMap.find(actionname) != ShortFormMap.end(), "Unknown action name passed to MapOfActions::getShortForm");
994 return ShortFormMap[actionname];
995}
996
997/** Returns whether the given action needs a value or not.
998 * \param actionname name of the action to look up
999 * \return true - value is needed, false - no value is stored in MapOfActions::TypeMap
1000 */
1001bool MapOfActions::hasValue(string actionname)
1002{
1003 return (TypeMap.find(actionname) != TypeMap.end());
1004}
1005
1006/** Getter for MapOfActions::TypeMap.
1007 * \param actionname name of the action to look up
1008 * \return type of the action
1009 */
1010std::string MapOfActions::getValueType(string actionname)
1011{
1012 return TypeMap[actionname]->name();
1013}
1014
1015/** Searches whether action is registered with CommandLineParser.
1016 * Note that this method is only meant transitionally for ParseCommandLineOptions' removal.
1017 * I.e. All actions that are already handled by the new CommandLineUIFactory can be checked
1018 * by this function.
1019 * \param shortform command short form to look for
1020 * \return true - action has been registered, false - action has not been registered.
1021 */
1022bool MapOfActions::isShortFormPresent(string shortform)
1023{
1024 bool result = false;
1025 string actionname;
1026 for (map<std::string, std::string>::iterator ShortFormRunner = ShortFormMap.begin(); ShortFormRunner != ShortFormMap.end(); ++ShortFormRunner)
1027 if (ShortFormRunner->second == shortform) {
1028 actionname = ShortFormRunner->first;
1029 break;
1030 }
1031 result = result || (generic.find(actionname) != generic.end());
1032 result = result || (config.find(actionname) != config.end());
1033 result = result || (hidden.find(actionname) != hidden.end());
1034 result = result || (visible.find(actionname) != visible.end());
1035 result = result || (inputfile.find(actionname) != inputfile.end());
1036 return result;
1037}
1038
1039/** Returns the inverse to MapOfActions::ShortFormMap, i.e. lookup actionname for its short form.
1040 * \return map from short form of action to name of action
1041 */
1042map <std::string, std::string> MapOfActions::getShortFormToActionMap()
1043{
1044 map <std::string, std::string> result;
1045
1046 for (map<std::string, std::string>::iterator iter = ShortFormMap.begin(); iter != ShortFormMap.end(); ++iter)
1047 result[iter->second] = iter->first;
1048
1049 return result;
1050}
1051
1052
1053CONSTRUCT_SINGLETON(MapOfActions)
Note: See TracBrowser for help on using the repository browser.