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