source: src/Actions/MapOfActions.cpp@ 3037be

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 3037be was 0b0a20, checked in by Frederik Heber <heber@…>, 15 years ago

Inserted all possible queries into MapOfActions.

  • MapOfActions::query/setCurrentValue(): only special classes such as atom, Box, element, molecule, Vector need a specialization of the template.
  • also added missing MissingValueException files.
  • Property mode set to 100644
File size: 43.4 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(BoxValue)] = Box;
355 TypeEnumMap[&typeid(molecule)] = Molecule;
356 TypeEnumMap[&typeid(std::vector<molecule *>)] = ListOfMolecules;
357 TypeEnumMap[&typeid(atom)] = Atom;
358 TypeEnumMap[&typeid(std::vector<atom *>)] = ListOfAtoms;
359 TypeEnumMap[&typeid(element)] = Element;
360 TypeEnumMap[&typeid(std::vector<element *>)] = ListOfElements;
361
362 // default values for any action that needs one (always string!)
363 CurrentValue["bin-width"] = "0.5";
364 CurrentValue["fastparsing"] = "0";
365 CurrentValue["atom-by-id"] = "-1";
366 CurrentValue["molecule-by-id"] = "-1";
367 CurrentValue["periodic"] = "0";
368
369 // put action into each menu category
370 MenuDescription["analysis"] = pair<std::string,std::string>("Analysis (pair correlation, volume)", "Analysis");
371 MenuDescription["atom"] = pair<std::string,std::string>("Edit atoms", "Edit atoms");
372 MenuDescription["command"] = pair<std::string,std::string>("Configuration", "Configuration");
373 MenuDescription["fragmentation"] = pair<std::string,std::string>("Fragmentation", "Fragmentation");
374 MenuDescription["molecule"] = pair<std::string,std::string>("Parse files into system", "Parse files");
375 MenuDescription["parser"] = pair<std::string,std::string>("Edit molecules (load, parse, save)", "Edit molecules");
376 MenuDescription["tesselation"] = pair<std::string,std::string>("Tesselate molecules", "Tesselate molecules");
377 MenuDescription["world"] = pair<std::string,std::string>("Edit world", "Edit world");
378
379 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "molecular-volume") );
380 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "pair-correlation") );
381 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "principal-axis-system") );
382
383 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "add-atom") );
384 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "change-element") );
385 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "remove-atom") );
386
387 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "bond-table") );
388 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "element-db") );
389 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "fastparsing") );
390 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "verbose") );
391 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "version") );
392
393 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "depth-first-search") );
394 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "fragment-mol") );
395 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "subgraph-dissect") );
396
397 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "bond-file") );
398 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "change-molname") );
399 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "fill-molecule") );
400 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "linear-interpolate") );
401 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "rotate-to-pas") );
402 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-adjacency") );
403 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-bonds") );
404 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-temperature") );
405 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "suspend-in-water") );
406 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "translate-mol") );
407 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "verlet-integrate") );
408
409 MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "parse-xyz") );
410 MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "SaveXyz") );
411
412 MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "convex-envelope") );
413 MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "nonconvex-envelope") );
414
415 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "boundary") );
416 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "bound-in-box") );
417 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-in-box") );
418 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-edge") );
419 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "change-box") );
420 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "input") );
421 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "output") );
422 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "remove-sphere") );
423 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "repeat-box") );
424 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "scale-box") );
425 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "default-molname") );
426 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-basis") );
427 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-output") );
428
429 // put actions into command line category
430 generic.insert("add-atom");
431 generic.insert("bond-file");
432 generic.insert("bond-table");
433 generic.insert("boundary");
434// generic.insert("bound-in-box");
435 generic.insert("center-edge");
436 generic.insert("center-in-box");
437 generic.insert("change-box");
438// generic.insert("change-molname");
439 generic.insert("change-element");
440 generic.insert("convex-envelope");
441 generic.insert("default-molname");
442 generic.insert("depth-first-search");
443 generic.insert("element-db");
444 generic.insert("fastparsing");
445 generic.insert("fill-molecule");
446 generic.insert("fragment-mol");
447 generic.insert("help");
448 generic.insert("input");
449 generic.insert("linear-interpolate");
450// generic.insert("molecular-volume");
451 generic.insert("nonconvex-envelope");
452 generic.insert("output");
453 generic.insert("pair-correlation");
454 generic.insert("parse-xyz");
455// generic.insert("principal-axis-system");
456 generic.insert("remove-atom");
457 generic.insert("remove-sphere");
458 generic.insert("repeat-box");
459 generic.insert("rotate-to-pas");
460 generic.insert("save-adjacency");
461 generic.insert("save-bonds");
462 generic.insert("save-temperature");
463 generic.insert("scale-box");
464 generic.insert("set-basis");
465 generic.insert("set-output");
466 generic.insert("subgraph-dissect");
467 generic.insert("suspend-in-water");
468 generic.insert("translate-mol");
469 generic.insert("verbose");
470 generic.insert("verlet-integrate");
471 generic.insert("version");
472
473 // positional arguments
474 generic.insert("input");
475 inputfile.insert("input");
476
477 // hidden arguments
478 generic.insert("atom-by-id");
479 generic.insert("bin-end");
480 generic.insert("bin-output-file");
481 generic.insert("bin-start");
482 generic.insert("bin-width");
483 generic.insert("convex-file");
484 generic.insert("distance");
485 generic.insert("DoRotate");
486 generic.insert("distances");
487 generic.insert("element");
488 generic.insert("elements");
489 generic.insert("end-step");
490 generic.insert("id-mapping");
491 generic.insert("lengths");
492 generic.insert("MaxDistance");
493 generic.insert("molecule-by-id");
494 generic.insert("molecule-by-name");
495 generic.insert("nonconvex-file");
496 generic.insert("order");
497 generic.insert("output-file");
498 generic.insert("periodic");
499 generic.insert("position");
500 generic.insert("sphere-radius");
501 generic.insert("start-step");
502}
503
504/** Destructor of class MapOfActions.
505 *
506 */
507MapOfActions::~MapOfActions()
508{
509 DescriptionMap.clear();
510}
511
512void MapOfActions::queryCurrentValue(const char * name, class atom * &_T)
513{
514 int atomID = -1;
515 if (typeid( atom ) == *TypeMap[name]) {
516 if (CurrentValue.find(name) == CurrentValue.end())
517 throw MissingValueException(__FILE__, __LINE__);
518 atomID = lexical_cast<int>(CurrentValue[name].c_str());
519 CurrentValue.erase(name);
520 } else
521 throw IllegalTypeException(__FILE__,__LINE__);
522 _T = World::getInstance().getAtom(AtomById(atomID));
523}
524
525void MapOfActions::queryCurrentValue(const char * name, class element * &_T) {
526 int Z = -1;
527 if (typeid( element ) == *TypeMap[name]) {
528 if (CurrentValue.find(name) == CurrentValue.end())
529 throw MissingValueException(__FILE__, __LINE__);
530 Z = lexical_cast<int>(CurrentValue[name].c_str());
531 CurrentValue.erase(name);
532 } else
533 throw IllegalTypeException(__FILE__,__LINE__);
534 _T = World::getInstance().getPeriode()->FindElement(Z);
535}
536
537void MapOfActions::queryCurrentValue(const char * name, class molecule * &_T) {
538 int molID = -1;
539 if (typeid( molecule ) == *TypeMap[name]) {
540 if (CurrentValue.find(name) == CurrentValue.end())
541 throw MissingValueException(__FILE__, __LINE__);
542 molID = lexical_cast<int>(CurrentValue[name].c_str());
543 CurrentValue.erase(name);
544 } else
545 throw IllegalTypeException(__FILE__,__LINE__);
546 _T = World::getInstance().getMolecule(MoleculeById(molID));
547}
548
549void MapOfActions::queryCurrentValue(const char * name, class Box &_T) {
550 Matrix M;
551 double tmp;
552 if (typeid( BoxValue ) == *TypeMap[name]) {
553 if (CurrentValue.find(name) == CurrentValue.end())
554 throw MissingValueException(__FILE__, __LINE__);
555 std::istringstream stream(CurrentValue[name]);
556 CurrentValue.erase(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 } else
573 throw IllegalTypeException(__FILE__,__LINE__);
574}
575
576void MapOfActions::queryCurrentValue(const char * name, class Vector &_T) {
577 if (typeid( VectorValue ) == *TypeMap[name]) {
578 std::istringstream stream(CurrentValue[name]);
579 CurrentValue.erase(name);
580 stream >> _T[0];
581 stream >> _T[1];
582 stream >> _T[2];
583 } else
584 throw IllegalTypeException(__FILE__,__LINE__);
585}
586
587void MapOfActions::queryCurrentValue(const char * name, std::vector<atom *>&_T)
588{
589 int atomID = -1;
590 atom *Walker = NULL;
591 if (typeid( std::vector<atom *> ) == *TypeMap[name]) {
592 if (CurrentValue.find(name) == CurrentValue.end())
593 throw MissingValueException(__FILE__, __LINE__);
594 std::istringstream stream(CurrentValue[name]);
595 CurrentValue.erase(name);
596 while (!stream.fail()) {
597 stream >> atomID;
598 Walker = World::getInstance().getAtom(AtomById(atomID));
599 if (Walker != NULL)
600 _T.push_back(Walker);
601 }
602 } else
603 throw IllegalTypeException(__FILE__,__LINE__);
604}
605
606void MapOfActions::queryCurrentValue(const char * name, std::vector<element *>&_T)
607{
608 int Z = -1;
609 element *elemental = NULL;
610 if (typeid( std::vector<element *> ) == *TypeMap[name]) {
611 if (CurrentValue.find(name) == CurrentValue.end())
612 throw MissingValueException(__FILE__, __LINE__);
613 std::istringstream stream(CurrentValue[name]);
614 CurrentValue.erase(name);
615 while (!stream.fail()) {
616 stream >> Z;
617 elemental = World::getInstance().getPeriode()->FindElement(Z);
618 if (elemental != NULL)
619 _T.push_back(elemental);
620 }
621 } else
622 throw IllegalTypeException(__FILE__,__LINE__);
623}
624
625void MapOfActions::queryCurrentValue(const char * name, std::vector<molecule *>&_T)
626{
627 int molID = -1;
628 molecule *mol = NULL;
629 if (typeid( std::vector<molecule *> ) == *TypeMap[name]) {
630 if (CurrentValue.find(name) == CurrentValue.end())
631 throw MissingValueException(__FILE__, __LINE__);
632 std::istringstream stream(CurrentValue[name]);
633 CurrentValue.erase(name);
634 while (!stream.fail()) {
635 stream >> molID;
636 mol = World::getInstance().getMolecule(MoleculeById(molID));
637 if (mol != NULL)
638 _T.push_back(mol);
639 }
640 } else
641 throw IllegalTypeException(__FILE__,__LINE__);
642}
643
644
645void MapOfActions::setCurrentValue(const char * name, class atom * &_T)
646{
647 if (typeid( atom ) == *TypeMap[name]) {
648 std::ostringstream stream;
649 stream << _T->getId();
650 CurrentValue[name] = stream.str();
651 } else
652 throw IllegalTypeException(__FILE__,__LINE__);
653}
654
655void MapOfActions::setCurrentValue(const char * name, class element * &_T)
656{
657 if (typeid( element ) == *TypeMap[name]) {
658 std::ostringstream stream;
659 stream << _T->Z;
660 CurrentValue[name] = stream.str();
661 } else
662 throw IllegalTypeException(__FILE__,__LINE__);
663}
664
665void MapOfActions::setCurrentValue(const char * name, class molecule * &_T)
666{
667 if (typeid( molecule ) == *TypeMap[name]) {
668 std::ostringstream stream;
669 stream << _T->getId();
670 CurrentValue[name] = stream.str();
671 } else
672 throw IllegalTypeException(__FILE__,__LINE__);
673}
674
675void MapOfActions::setCurrentValue(const char * name, class Box &_T)
676{
677 const Matrix &M = _T.getM();
678 if (typeid( Box ) == *TypeMap[name]) {
679 std::ostringstream stream;
680 stream << M.at(0,0) << " ";
681 stream << M.at(0,1) << " ";
682 stream << M.at(0,2) << " ";
683 stream << M.at(1,1) << " ";
684 stream << M.at(1,2) << " ";
685 stream << M.at(2,2) << " ";
686 CurrentValue[name] = stream.str();
687 } else
688 throw IllegalTypeException(__FILE__,__LINE__);
689}
690
691void MapOfActions::setCurrentValue(const char * name, class Vector &_T)
692{
693 if (typeid( Vector ) == *TypeMap[name]){
694 std::ostringstream stream;
695 stream << _T[0] << " ";
696 stream << _T[1] << " ";
697 stream << _T[2] << " ";
698 CurrentValue[name] = stream.str();
699 } else
700 throw IllegalTypeException(__FILE__,__LINE__);
701}
702
703void MapOfActions::setCurrentValue(const char * name, std::vector<atom *>&_T)
704{
705 if (typeid( std::vector<atom *> ) == *TypeMap[name]) {
706 std::ostringstream stream;
707 for (std::vector<atom *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
708 stream << (*iter)->getId() << " ";
709 }
710 CurrentValue[name] = stream.str();
711 } else
712 throw IllegalTypeException(__FILE__,__LINE__);
713}
714
715void MapOfActions::setCurrentValue(const char * name, std::vector<element *>&_T)
716{
717 if (typeid( std::vector<element *> ) == *TypeMap[name]) {
718 std::ostringstream stream;
719 for (std::vector<element *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
720 stream << (*iter)->Z << " ";
721 }
722 CurrentValue[name] = stream.str();
723 } else
724 throw IllegalTypeException(__FILE__,__LINE__);
725}
726
727void MapOfActions::setCurrentValue(const char * name, std::vector<molecule *>&_T)
728{
729 if (typeid( std::vector<molecule *> ) == *TypeMap[name]) {
730 std::ostringstream stream;
731 for (std::vector<molecule *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
732 stream << (*iter)->getId() << " ";
733 }
734 CurrentValue[name] = stream.str();
735 } else
736 throw IllegalTypeException(__FILE__,__LINE__);
737}
738
739
740
741void MapOfActions::populateActions()
742{
743 new AnalysisMolecularVolumeAction();
744 new AnalysisPairCorrelationAction();
745 new AnalysisPointCorrelationAction();
746 new AnalysisPrincipalAxisSystemAction();
747 new AnalysisSurfaceCorrelationAction();
748
749 new AtomAddAction();
750 new AtomChangeElementAction();
751 new AtomRemoveAction();
752
753 new CommandLineBondLengthTableAction();
754 new CommandLineElementDbAction();
755 new CommandLineFastParsingAction();
756 new CommandLineHelpAction();
757 new CommandLineVerboseAction();
758 new CommandLineVersionAction();
759
760 new FragmentationDepthFirstSearchAction();
761 new FragmentationFragmentationAction();
762 new FragmentationSubgraphDissectionAction();
763
764 new MoleculeBondFileAction();
765 new MoleculeChangeNameAction();
766 new MoleculeFillWithMoleculeAction();
767 new MoleculeLinearInterpolationofTrajectoriesAction();
768 new MoleculeRotateToPrincipalAxisSystemAction();
769 new MoleculeSaveAdjacencyAction();
770 new MoleculeSaveBondsAction();
771 new MoleculeSaveTemperatureAction();
772 new MoleculeSuspendInWaterAction();
773 new MoleculeTranslateAction();
774 new MoleculeVerletIntegrationAction();
775
776 new ParserLoadXyzAction();
777 new ParserSaveXyzAction();
778
779 new TesselationConvexEnvelopeAction();
780 new TesselationNonConvexEnvelopeAction();
781
782 new WorldAddEmptyBoundaryAction();
783 new WorldBoundInBoxAction();
784 new WorldCenterInBoxAction();
785 new WorldCenterOnEdgeAction();
786 new WorldChangeBoxAction();
787 new WorldInputAction();
788 new WorldOutputAction();
789 new WorldRemoveSphereOfAtomsAction();
790 new WorldRepeatBoxAction();
791 new WorldScaleBoxAction();
792 new WorldSetDefaultNameAction();
793 new WorldSetGaussianBasisAction();
794 new WorldSetOutputFormatsAction();
795}
796
797/** Adds all options to the CommandLineParser.
798 *
799 */
800void MapOfActions::AddOptionsToParser()
801{
802 // add other options
803 for (map< set<string>*, po::options_description* >::iterator ListRunner = CmdParserLookup.begin(); ListRunner != CmdParserLookup.end(); ++ListRunner) {
804 for (set<string>::iterator OptionRunner = ListRunner->first->begin(); OptionRunner != ListRunner->first->end(); ++OptionRunner) {
805 if (hasValue(*OptionRunner)) {
806 DoLog(3) && (Log() << Verbose(3) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner]->name() << " to CommandLineParser." << endl);
807 switch(TypeEnumMap[TypeMap[*OptionRunner]]) {
808 default:
809 case None:
810 ListRunner->second->add_options()
811 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
812 ;
813 break;
814 case Boolean:
815 ListRunner->second->add_options()
816 (getKeyAndShortForm(*OptionRunner).c_str(),
817 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
818 po::value< bool >()->default_value(atoi(CurrentValue[*OptionRunner].c_str())) :
819 po::value< bool >(),
820 getDescription(*OptionRunner).c_str())
821 ;
822 break;
823 case Box:
824 ListRunner->second->add_options()
825 (getKeyAndShortForm(*OptionRunner).c_str(),
826 po::value<BoxValue>()->multitoken(),
827 getDescription(*OptionRunner).c_str())
828 ;
829 break;
830 case Integer:
831 ListRunner->second->add_options()
832 (getKeyAndShortForm(*OptionRunner).c_str(),
833 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
834 po::value< int >()->default_value(atoi(CurrentValue[*OptionRunner].c_str())) :
835 po::value< int >(),
836 getDescription(*OptionRunner).c_str())
837 ;
838 break;
839 case ListOfIntegers:
840 ListRunner->second->add_options()
841 (getKeyAndShortForm(*OptionRunner).c_str(),
842 po::value< vector<int> >()->multitoken(),
843 getDescription(*OptionRunner).c_str())
844 ;
845 break;
846 case Double:
847 ListRunner->second->add_options()
848 (getKeyAndShortForm(*OptionRunner).c_str(),
849 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
850 po::value< double >()->default_value(atof(CurrentValue[*OptionRunner].c_str())) :
851 po::value< double >(),
852 getDescription(*OptionRunner).c_str())
853 ;
854 break;
855 case ListOfDoubles:
856 ListRunner->second->add_options()
857 (getKeyAndShortForm(*OptionRunner).c_str(),
858 po::value< vector<double> >()->multitoken(),
859 getDescription(*OptionRunner).c_str())
860 ;
861 break;
862 case String:
863 ListRunner->second->add_options()
864 (getKeyAndShortForm(*OptionRunner).c_str(),
865 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
866 po::value< std::string >()->default_value(CurrentValue[*OptionRunner]) :
867 po::value< std::string >(),
868 getDescription(*OptionRunner).c_str())
869 ;
870 break;
871 case ListOfStrings:
872 ListRunner->second->add_options()
873 (getKeyAndShortForm(*OptionRunner).c_str(),
874 po::value< vector<std::string> >()->multitoken(),
875 getDescription(*OptionRunner).c_str())
876 ;
877 break;
878 case Vector:
879 ListRunner->second->add_options()
880 (getKeyAndShortForm(*OptionRunner).c_str(),
881 po::value<VectorValue>(),
882 getDescription(*OptionRunner).c_str())
883 ;
884 break;
885 case ListOfVectors:
886 ListRunner->second->add_options()
887 (getKeyAndShortForm(*OptionRunner).c_str(),
888 po::value< vector<VectorValue> >()->multitoken(),
889 getDescription(*OptionRunner).c_str())
890 ;
891 break;
892 case Molecule:
893 ListRunner->second->add_options()
894 (getKeyAndShortForm(*OptionRunner).c_str(),
895 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
896 po::value< int >()->default_value(atoi(CurrentValue[*OptionRunner].c_str())) :
897 po::value< int >(),
898 getDescription(*OptionRunner).c_str())
899 ;
900 break;
901 case ListOfMolecules:
902 ListRunner->second->add_options()
903 (getKeyAndShortForm(*OptionRunner).c_str(),
904 po::value< vector<int> >()->multitoken(),
905 getDescription(*OptionRunner).c_str())
906 ;
907 break;
908 case Atom:
909 ListRunner->second->add_options()
910 (getKeyAndShortForm(*OptionRunner).c_str(),
911 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
912 po::value< int >()->default_value(atoi(CurrentValue[*OptionRunner].c_str())) :
913 po::value< int >(),
914 getDescription(*OptionRunner).c_str())
915 ;
916 break;
917 case ListOfAtoms:
918 ListRunner->second->add_options()
919 (getKeyAndShortForm(*OptionRunner).c_str(),
920 po::value< vector<int> >()->multitoken(),
921 getDescription(*OptionRunner).c_str())
922 ;
923 break;
924 case Element:
925 ListRunner->second->add_options()
926 (getKeyAndShortForm(*OptionRunner).c_str(),
927 po::value< vector<int> >(),
928 getDescription(*OptionRunner).c_str())
929 ;
930 break;
931 case ListOfElements:
932 ListRunner->second->add_options()
933 (getKeyAndShortForm(*OptionRunner).c_str(),
934 po::value< vector<int> >()->multitoken(),
935 getDescription(*OptionRunner).c_str())
936 ;
937 break;
938 }
939 } else {
940 DoLog(3) && (Log() << Verbose(3) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl);
941 ListRunner->second->add_options()
942 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
943 ;
944 }
945 }
946 }
947 // add positional arguments
948 for (set<string>::iterator OptionRunner = inputfile.begin(); OptionRunner != inputfile.end(); ++OptionRunner) {
949 DoLog(3) && (Log() << Verbose(3) << "Adding option " << *OptionRunner << " to positional CommandLineParser." << endl);
950 CommandLineParser::getInstance().inputfile.add((*OptionRunner).c_str(), -1);
951 }
952 cout << "Name for position 1: " << CommandLineParser::getInstance().inputfile.name_for_position(1) << endl;
953}
954
955/** Getter for MapOfActions:DescriptionMap.
956 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
957 * \param actionname name of the action to lookup
958 * \return Description of the action
959 */
960std::string MapOfActions::getDescription(string actionname)
961{
962 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescription");
963 return DescriptionMap[actionname];
964}
965
966/** Specific Getter for a MapOfActions:ShortFormMap.
967 * If action has a short for, then combination is as "actionname,ShortForm" (this is
968 * the desired format for boost::program_options). If no short form exists in the map,
969 * just actionname will be returned
970 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
971 * \param actionname name of the action to lookup
972 * \return actionname,ShortForm or Description of the action
973 */
974std::string MapOfActions::getKeyAndShortForm(string actionname)
975{
976 stringstream output;
977 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescriptionAndShortForm");
978 output << actionname;
979 if (ShortFormMap.find(actionname) != DescriptionMap.end())
980 output << "," << ShortFormMap[actionname];
981 return output.str();
982}
983
984/** Getter for MapOfActions:ShortFormMap.
985 * Note that we assert when action does not exist CommandLineParser::ShortFormMap.
986 * \param actionname name of the action to lookup
987 * \return ShortForm of the action
988 */
989std::string MapOfActions::getShortForm(string actionname)
990{
991 ASSERT(ShortFormMap.find(actionname) != ShortFormMap.end(), "Unknown action name passed to MapOfActions::getShortForm");
992 return ShortFormMap[actionname];
993}
994
995/** Returns whether the given action needs a value or not.
996 * \param actionname name of the action to look up
997 * \return true - value is needed, false - no value is stored in MapOfActions::TypeMap
998 */
999bool MapOfActions::hasValue(string actionname)
1000{
1001 return (TypeMap.find(actionname) != TypeMap.end());
1002}
1003
1004/** Getter for MapOfActions::TypeMap.
1005 * \param actionname name of the action to look up
1006 * \return type of the action
1007 */
1008std::string MapOfActions::getValueType(string actionname)
1009{
1010 return TypeMap[actionname]->name();
1011}
1012
1013/** Searches whether action is registered with CommandLineParser.
1014 * Note that this method is only meant transitionally for ParseCommandLineOptions' removal.
1015 * I.e. All actions that are already handled by the new CommandLineUIFactory can be checked
1016 * by this function.
1017 * \param shortform command short form to look for
1018 * \return true - action has been registered, false - action has not been registered.
1019 */
1020bool MapOfActions::isShortFormPresent(string shortform)
1021{
1022 bool result = false;
1023 string actionname;
1024 for (map<std::string, std::string>::iterator ShortFormRunner = ShortFormMap.begin(); ShortFormRunner != ShortFormMap.end(); ++ShortFormRunner)
1025 if (ShortFormRunner->second == shortform) {
1026 actionname = ShortFormRunner->first;
1027 break;
1028 }
1029 result = result || (generic.find(actionname) != generic.end());
1030 result = result || (config.find(actionname) != config.end());
1031 result = result || (hidden.find(actionname) != hidden.end());
1032 result = result || (visible.find(actionname) != visible.end());
1033 result = result || (inputfile.find(actionname) != inputfile.end());
1034 return result;
1035}
1036
1037/** Returns the inverse to MapOfActions::ShortFormMap, i.e. lookup actionname for its short form.
1038 * \return map from short form of action to name of action
1039 */
1040map <std::string, std::string> MapOfActions::getShortFormToActionMap()
1041{
1042 map <std::string, std::string> result;
1043
1044 for (map<std::string, std::string>::iterator iter = ShortFormMap.begin(); iter != ShortFormMap.end(); ++iter)
1045 result[iter->second] = iter->first;
1046
1047 return result;
1048}
1049
1050
1051CONSTRUCT_SINGLETON(MapOfActions)
Note: See TracBrowser for help on using the repository browser.