source: src/Actions/MapOfActions.cpp@ 4e145c

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

Actions can now be called non-interactively, MissingValueException thrown.

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