source: src/UIElements/CommandLineUI/CommandLineParser.cpp@ f4b6bc9

Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.1 ChemicalSpaceEvaluator Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Exclude_Hydrogens_annealWithBondGraph ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_contraction-expansion Gui_displays_atomic_force_velocity JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool PythonUI_with_named_parameters StoppableMakroAction TremoloParser_IncreasedPrecision
Last change on this file since f4b6bc9 was 78ea3c, checked in by Frederik Heber <frederik.heber@…>, 8 years ago

Merge branch 'Docu_Python_wait' into Candidate_v1.6.1

Conflicts:

tests/Python/AllActions/options.dat

  • two options introduced at same place, both get in.
  • Property mode set to 100644
File size: 24.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * CommandLineParser.cpp
25 *
26 * Created on: May 8, 2010
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35//#include "CodePatterns/MemDebug.hpp"
36
37#include <boost/filesystem.hpp>
38#include <boost/lexical_cast.hpp>
39#include <boost/program_options/option.hpp>
40#include <boost/program_options/value_semantic.hpp>
41#include <boost/program_options.hpp>
42#include <fstream>
43#include <iostream>
44#include <set>
45#include <map>
46
47#include "Actions/Action.hpp"
48#include "Actions/ActionQueue.hpp"
49#include "Actions/ActionTrait.hpp"
50#include "Actions/OptionRegistry.hpp"
51#include "Actions/OptionTrait.hpp"
52#include "Actions/Values.hpp"
53#include "CodePatterns/Log.hpp"
54#include "CodePatterns/Verbose.hpp"
55#include "CommandLineParser.hpp"
56#include "CommandLineParser_validate.hpp"
57#include "Parameters/Specifics/KeyValuePair.hpp"
58#include "World.hpp"
59
60#include "CodePatterns/Singleton_impl.hpp"
61
62using namespace MoleCuilder;
63
64class element;
65
66/** Constructor of class CommandLineParser.
67 *
68 */
69CommandLineParser::CommandLineParser() :
70 analysis("Analysis options"),
71 atom("Atom options"),
72 bond("Bond options"),
73 command("Command options"),
74 fill("fill options"),
75 shape("shape options"),
76 fragmentation("Fragmentation options"),
77 geometry("Geometry options"),
78 graph("Graph options"),
79 molecule("Molecule options"),
80 options("Secondary options"),
81 parser("Parser options"),
82 potential("Potential options"),
83 selection("Selection options"),
84 tesselation("Tesselation options"),
85 world("World options")
86{
87 // put all options lists into a lookup
88 CmdParserLookup["analysis"] = &analysis;
89 CmdParserLookup["atom"] = &atom;
90 CmdParserLookup["bond"] = &bond;
91 CmdParserLookup["command"] = &command;
92 CmdParserLookup["edit"] = &edit;
93 CmdParserLookup["fill"] = &fill;
94 CmdParserLookup["shape"] = &shape;
95 CmdParserLookup["fragmentation"] = &fragmentation;
96 CmdParserLookup["geometry"] = &geometry;
97 CmdParserLookup["graph"] = &graph;
98 CmdParserLookup["options"] = &options;
99 CmdParserLookup["molecule"] = &molecule;
100 CmdParserLookup["parser"] = &parser;
101 CmdParserLookup["potential"] = &potential;
102 CmdParserLookup["selection"] = &selection;
103 CmdParserLookup["tesselation"] = &tesselation;
104 CmdParserLookup["world"] = &world;
105}
106
107/** Destructor of class CommandLineParser.
108 *
109 */
110CommandLineParser::~CommandLineParser()
111{}
112
113/** Initializes command arguments to accept.
114 * Goes through ActionRegistry and puts all actions therein into the map.
115 */
116void CommandLineParser::InitializeCommandArguments()
117{
118 // we need a list of already added options, otherwise we get ambigious exceptions
119 std::set<std::string> AlreadyAddedOptionNames;
120
121 bool ActionAlreadyAdded_flag = false;
122 ActionQueue &AQ = ActionQueue::getInstance();
123 ActionQueue::ActionTokens_t tokens = AQ.getListOfActions();
124 for (ActionQueue::ActionTokens_t::const_iterator iter = tokens.begin();
125 iter != tokens.end(); ++iter) {
126 const ActionTrait &CurrentTrait = AQ.getActionsTrait(*iter);
127 ActionAlreadyAdded_flag = false;
128 //std::cout << "Current Action to initialize is: " << actioniter->first << std::endl;
129
130 for (ActionTrait::options_const_iterator optioniter = CurrentTrait.getBeginIter();
131 optioniter != CurrentTrait.getEndIter();
132 ++optioniter) {
133 if (optioniter->first == *iter)
134 ActionAlreadyAdded_flag = true;
135 ASSERT( OptionRegistry::getInstance().isOptionPresentByName(optioniter->first),
136 "CommandLineParser::Init() - Option "+optioniter->first+" not present in OptionRegistry." );
137 const OptionTrait* const currentOption = OptionRegistry::getInstance().getOptionByName(optioniter->first);
138
139 if (AlreadyAddedOptionNames.find(optioniter->first) == AlreadyAddedOptionNames.end()) {
140 // add the option
141// std::cout << "Registering Option "
142// << currentOption->getName()
143// << " with type '" << currentOption->getTypeName() << "' "
144// << " with description '" << currentOption->getDescription() << "' ";
145// if (currentOption->hasShortForm())
146// std::cout << ", with short form " << currentOption->getShortForm();
147// else
148// std::cout << ", with no short form ";
149// if (currentOption->hasDefaultValue())
150// std::cout << ", with default value " << currentOption->getDefaultValue();
151// else
152// std::cout << ", with no default value ";
153// std::cout << std::endl;
154
155 AddOptionToParser(currentOption, (CmdParserLookup["options"]),
156 (optioniter->first == *iter) ?
157 true : false);
158
159 AlreadyAddedOptionNames.insert(optioniter->first);
160 } else {
161// std::cout << "Option " << currentOption->getName() << " already registered." << std::endl;
162 }
163 }
164
165 if (!ActionAlreadyAdded_flag) {
166 // add the action
167// std::cout << "Registering Action "
168// << currentAction->Traits.getName()
169// << " in menu " << currentAction->Traits.getMenuName()
170// << " with type '" << currentAction->Traits.getTypeName() << "' "
171// << " with description '" << currentAction->Traits.getDescription() << "' ";
172// if (currentAction->Traits.hasShortForm())
173// std::cout << ", with short form " << currentAction->Traits.getShortForm();
174// else
175// std::cout << ", with no short form ";
176// if (currentAction->Traits.hasDefaultValue())
177// std::cout << ", with default value " << currentAction->Traits.getDefaultValue();
178// else
179// std::cout << ", with no default value ";
180// std::cout << std::endl;
181
182 ASSERT(CmdParserLookup.find(CurrentTrait.getMenuName()) != CmdParserLookup.end(),
183 "CommandLineParser: boost::program_options::options_description for this Action not present.");
184 AddOptionToParser(
185 dynamic_cast<const OptionTrait * const>(&CurrentTrait),
186 (CmdParserLookup[CurrentTrait.getMenuName()]),
187 false);
188 }
189 }
190 // note: positioning is not important on the command line
191}
192
193/** Adds an Action or Option to the CommandLineParser.
194 * Note that Action is derived from Option(Trait)
195 *
196 * This ugly switch function is necessary because of the compile-time problem:
197 * po::value<T> has to be instantiated at compile-time however we do know the type not until run-time.
198 * Not even a templated function like po::value<T> getProgramOptionValuefromType() does help, specialized
199 * to each available type, as the signatures of all the functions differ. Hence, they cannot not put into
200 * one type_info -> po::value<T> map ...
201 *
202 * \param *currentOption pointer to Action/Option to add
203 * \param *OptionList program_options list to add to
204 * \param _DefaultAsImplicit whether to add a default value as default_value or
205 * as implicit_value (default = option token present or not, implicit =
206 option token present but not necessarily followed by argument)
207 */
208void CommandLineParser::AddOptionToParser(
209 const OptionTrait * const currentOption,
210 po::options_description* OptionList,
211 const bool _DefaultAsImplicit)
212{
213 // check whether dynamic_cast in Init() suceeded
214 ASSERT(currentOption != NULL, "CommandLineParser::AddOptionToParser() - currentOption is NULL!");
215 // add other options
216// std::cout << "Adding Action " << currentOption->getName() << " with type "
217// << currentOption->getType()->name() << ", " << (currentOption->hasDefaultValue() ? "with" : "without")
218// << " default value, and KeyandShortform " << currentOption->getKeyAndShortForm()
219// << " to CommandLineParser." << std::endl;
220 switch(TypeToEnums.getEnumforType(currentOption->getType())) {
221 default:
222 case TypeEnumContainer::NoneType:
223 OptionList->add_options()
224 (currentOption->getKeyAndShortForm().c_str(), currentOption->getDescription().c_str())
225 ;
226 break;
227 case TypeEnumContainer::BooleanType:
228 OptionList->add_options()
229 (currentOption->getKeyAndShortForm().c_str(),
230 currentOption->hasDefaultValue() ?
231 (_DefaultAsImplicit ?
232 po::value < bool >()->implicit_value(boost::lexical_cast<int>(currentOption->getDefaultValue().c_str())) :
233 po::value < bool >()->default_value(boost::lexical_cast<int>(currentOption->getDefaultValue().c_str()))) :
234 po::value < bool >(),
235 currentOption->getDescription().c_str())
236 ;
237 break;
238 case TypeEnumContainer::FileType:
239 OptionList->add_options()
240 (currentOption->getKeyAndShortForm().c_str(),
241// currentOption->hasDefaultValue() ?
242// po::value < boost::filesystem::path >()->default_value(boost::lexical_cast<boost::filesystem::path>(currentOption->getDefaultValue().c_str())) :
243 po::value < boost::filesystem::path >(),
244 currentOption->getDescription().c_str())
245 ;
246 break;
247 case TypeEnumContainer::ListOfFilesType:
248 OptionList->add_options()
249 (currentOption->getKeyAndShortForm().c_str(),
250// currentOption->hasDefaultValue() ?
251// po::value < std::vector<boost::filesystem::path> >()->default_value(boost::lexical_cast< std::vector<boost::filesystem::path> >(currentOption->getDefaultValue().c_str())) :
252 po::value < std::vector<boost::filesystem::path> >()->multitoken(),
253 currentOption->getDescription().c_str())
254 ;
255 break;
256 case TypeEnumContainer::IntegerType:
257 OptionList->add_options()
258 (currentOption->getKeyAndShortForm().c_str(),
259 currentOption->hasDefaultValue() ?
260 (_DefaultAsImplicit ?
261 po::value < int >()->implicit_value(boost::lexical_cast<int>(currentOption->getDefaultValue().c_str())) :
262 po::value < int >()->default_value(boost::lexical_cast<int>(currentOption->getDefaultValue().c_str()))) :
263 po::value < int >(),
264 currentOption->getDescription().c_str())
265 ;
266 break;
267 case TypeEnumContainer::ListOfIntegersType:
268 OptionList->add_options()
269 (currentOption->getKeyAndShortForm().c_str(),
270// currentOption->hasDefaultValue() ?
271// po::value < std::vector<int> >()->default_value(boost::lexical_cast< std::vector<int> >(currentOption->getDefaultValue().c_str())) :
272 po::value < std::vector<int> >()->multitoken(),
273 currentOption->getDescription().c_str())
274 ;
275 break;
276 case TypeEnumContainer::UnsignedIntegerType:
277 OptionList->add_options()
278 (currentOption->getKeyAndShortForm().c_str(),
279 currentOption->hasDefaultValue() ?
280 (_DefaultAsImplicit ?
281 po::value < unsigned int >()->implicit_value(boost::lexical_cast<unsigned int>(currentOption->getDefaultValue().c_str())) :
282 po::value < unsigned int >()->default_value(boost::lexical_cast<unsigned int>(currentOption->getDefaultValue().c_str()))) :
283 po::value < unsigned int >(),
284 currentOption->getDescription().c_str())
285 ;
286 break;
287 case TypeEnumContainer::ListOfUnsignedIntegersType:
288 OptionList->add_options()
289 (currentOption->getKeyAndShortForm().c_str(),
290// currentOption->hasDefaultValue() ?
291// po::value < std::vector<unsigned int> >()->default_value(boost::lexical_cast< std::vector<unsigned int> >(currentOption->getDefaultValue().c_str())) :
292 po::value < std::vector<unsigned int> >()->multitoken(),
293 currentOption->getDescription().c_str())
294 ;
295 break;
296 case TypeEnumContainer::DoubleType:
297 OptionList->add_options()
298 (currentOption->getKeyAndShortForm().c_str(),
299 currentOption->hasDefaultValue() ?
300 (_DefaultAsImplicit ?
301 po::value < double >()->implicit_value(boost::lexical_cast<double>(currentOption->getDefaultValue().c_str())) :
302 po::value < double >()->default_value(boost::lexical_cast<double>(currentOption->getDefaultValue().c_str()))) :
303 po::value < double >(),
304 currentOption->getDescription().c_str())
305 ;
306 break;
307 case TypeEnumContainer::ListOfDoublesType:
308 OptionList->add_options()
309 (currentOption->getKeyAndShortForm().c_str(),
310// currentOption->hasDefaultValue() ?
311// po::value < std::vector<double> >()->default_value(boost::lexical_cast< std::vector<double> >(currentOption->getDefaultValue().c_str())) :
312 po::value < std::vector<double> >()->multitoken(),
313 currentOption->getDescription().c_str())
314 ;
315 break;
316 case TypeEnumContainer::StringType:
317 OptionList->add_options()
318 (currentOption->getKeyAndShortForm().c_str(),
319 currentOption->hasDefaultValue() ?
320 (_DefaultAsImplicit ?
321 po::value < std::string >()->implicit_value(currentOption->getDefaultValue()) :
322 po::value < std::string >()->default_value(currentOption->getDefaultValue())) :
323 po::value < std::string >(),
324 currentOption->getDescription().c_str())
325 ;
326 break;
327 case TypeEnumContainer::ListOfStringsType:
328 OptionList->add_options()
329 (currentOption->getKeyAndShortForm().c_str(),
330// currentOption->hasDefaultValue() ?
331// po::value < std::vector<std::string> >()->default_value(boost::lexical_cast< std::vector<std::string> >(currentOption->getDefaultValue().c_str())) :
332 po::value < std::vector<std::string> >()->multitoken(),
333 currentOption->getDescription().c_str())
334 ;
335 break;
336 case TypeEnumContainer::VectorType:
337 OptionList->add_options()
338 (currentOption->getKeyAndShortForm().c_str(),
339// currentOption->hasDefaultValue() ?
340// po::value < VectorValue >()->default_value(boost::lexical_cast<VectorValue>(currentOption->getDefaultValue().c_str())) :
341 po::value < VectorValue >(),
342 currentOption->getDescription().c_str())
343 ;
344 break;
345 case TypeEnumContainer::ListOfVectorsType:
346 OptionList->add_options()
347 (currentOption->getKeyAndShortForm().c_str(),
348// currentOption->hasDefaultValue() ?
349// po::value < std::vector<VectorValue> >()->default_value(boost::lexical_cast< std::vector<VectorValue> >(currentOption->getDefaultValue().c_str())) :
350 po::value < std::vector<VectorValue> >()->multitoken(),
351 currentOption->getDescription().c_str())
352 ;
353 break;
354 case TypeEnumContainer::MoleculeType:
355 OptionList->add_options()
356 (currentOption->getKeyAndShortForm().c_str(),
357// currentOption->hasDefaultValue() ?
358// po::value < const molecule * >()->default_value(boost::lexical_cast<const molecule *>(currentOption->getDefaultValue().c_str())) :
359 po::value < int >(),
360 currentOption->getDescription().c_str())
361 ;
362 break;
363 case TypeEnumContainer::ListOfMoleculesType:
364 OptionList->add_options()
365 (currentOption->getKeyAndShortForm().c_str(),
366// currentOption->hasDefaultValue() ?
367// po::value < std::vector<const molecule *> >()->default_value(boost::lexical_cast< std::vector<const molecule *> >(currentOption->getDefaultValue().c_str())) :
368 po::value < std::vector<int> >()->multitoken(),
369 currentOption->getDescription().c_str())
370 ;
371 break;
372 case TypeEnumContainer::AtomType:
373 OptionList->add_options()
374 (currentOption->getKeyAndShortForm().c_str(),
375 currentOption->hasDefaultValue() ?
376 (_DefaultAsImplicit ?
377 po::value < int >()->implicit_value(boost::lexical_cast<int>(currentOption->getDefaultValue().c_str())) :
378 po::value < int >()->default_value(boost::lexical_cast<int>(currentOption->getDefaultValue().c_str()))) :
379 po::value < int >(),
380 currentOption->getDescription().c_str())
381 ;
382 break;
383 case TypeEnumContainer::ListOfAtomsType:
384 OptionList->add_options()
385 (currentOption->getKeyAndShortForm().c_str(),
386// currentOption->hasDefaultValue() ?
387// po::value < std::vector<const atom *> >()->default_value(boost::lexical_cast< std::vector<const atom *> >(currentOption->getDefaultValue().c_str())) :
388 po::value < std::vector<int> >()->multitoken(),
389 currentOption->getDescription().c_str())
390 ;
391 break;
392 case TypeEnumContainer::ElementType:
393 OptionList->add_options()
394 (currentOption->getKeyAndShortForm().c_str(),
395// currentOption->hasDefaultValue() ?
396// po::value < const element * >()->default_value(boost::lexical_cast<const element *>(currentOption->getDefaultValue().c_str())) :
397 po::value < std::string >(),
398 currentOption->getDescription().c_str())
399 ;
400 break;
401 case TypeEnumContainer::ListOfElementsType:
402 OptionList->add_options()
403 (currentOption->getKeyAndShortForm().c_str(),
404// currentOption->hasDefaultValue() ?
405// po::value < std::vector<const element *> >()->default_value(boost::lexical_cast< std::vector<const element *> >(currentOption->getDefaultValue().c_str())) :
406 po::value < std::vector<std::string> >()->multitoken(),
407 currentOption->getDescription().c_str())
408 ;
409 break;
410 case TypeEnumContainer::RealSpaceMatrixType:
411 OptionList->add_options()
412 (currentOption->getKeyAndShortForm().c_str(),
413// currentOption->hasDefaultValue() ?
414// po::value < RealSpaceMatrixValue >()->default_value(boost::lexical_cast<BoxValue>(currentOption->getDefaultValue().c_str())) :
415 po::value < RealSpaceMatrixValue >(),
416 currentOption->getDescription().c_str())
417 ;
418 break;
419 case TypeEnumContainer::KeyValueType:
420 OptionList->add_options()
421 (currentOption->getKeyAndShortForm().c_str(),
422 currentOption->hasDefaultValue() ?
423 (_DefaultAsImplicit ?
424 po::value < KeyValuePair >()->implicit_value(boost::lexical_cast< KeyValuePair >(currentOption->getDefaultValue().c_str())) :
425 po::value < KeyValuePair >()->default_value(boost::lexical_cast< KeyValuePair >(currentOption->getDefaultValue().c_str()))) :
426 po::value < KeyValuePair >(),
427 currentOption->getDescription().c_str())
428 ;
429 break;
430 case TypeEnumContainer::ListOfKeyValuesType:
431 OptionList->add_options()
432 (currentOption->getKeyAndShortForm().c_str(),
433// currentOption->hasDefaultValue() ?
434// po::value < std::vector<KeyValuePair> >()->default_value(boost::lexical_cast< std::vector<KeyValuePair> >(currentOption->getDefaultValue().c_str())) :
435 po::value < std::vector<KeyValuePair> >()->multitoken(),
436 currentOption->getDescription().c_str())
437 ;
438 break;
439 }
440}
441
442/** States whether there are command line arguments.
443 * \return true - there are none, false - there is at least one command line argument
444 */
445bool CommandLineParser::isEmpty()
446{
447 return vm.empty();
448}
449
450/** Sets the options.
451 * \param _argc arg count from main()
452 * \param **_argv argument array from main()
453 */
454void CommandLineParser::setOptions(int _argc, char **_argv)
455{
456 argc = _argc;
457 argv = _argv;
458 config_file_options.add(options);
459 // append all option_descriptions to both cmdline_options and visible
460 for (CmdParserLookupMap::iterator iter = CmdParserLookup.begin();
461 iter != CmdParserLookup.end();
462 ++iter) {
463 cmdline_options.add(*(iter->second));
464 visible.add(*(iter->second));
465 }
466}
467
468/** This is due to the answer by Aleksey Vitebskiy
469 * in http://stackoverflow.com/questions/4107087/accepting-negative-doubles-with-boostprogram-options
470 *
471 */
472std::vector<po::option> ignore_numbers(std::vector<std::string>& args)
473{
474 std::vector<po::option> result;
475 int pos = 0;
476 while(!args.empty()) {
477 const std::string& arg = args[0];
478 bool isNumber = true;
479 try {
480 boost::lexical_cast<double>(arg);
481 } catch(boost::bad_lexical_cast) {
482 isNumber = false;
483 }
484 if (isNumber) {
485 result.push_back(po::option());
486 po::option& opt = result.back();
487
488 opt.position_key = pos++;
489 opt.value.push_back(arg);
490 opt.original_tokens.push_back(arg);
491
492 args.erase(args.begin());
493 } else {
494 break;
495 }
496 }
497
498 return result;
499}
500
501/** Parses the command line arguments.
502 * Calls program_options::store() and program_options::notify()
503 *
504 * @return true - all is ok, false - command-line options could not be parsed
505 * correctly
506 */
507bool CommandLineParser::Parse()
508{
509 bool status = true;
510 try {
511 po::store(po::command_line_parser(argc,argv).extra_style_parser(&ignore_numbers).options(cmdline_options).run(), vm);
512 } catch (std::exception &e) {
513 std::cerr << "Something went wrong with parsing the command-line arguments: "
514 << e.what() << std::endl;
515 World::getInstance().setExitFlag(134);
516#ifdef HAVE_ACTION_THREAD
517 // force action queue to stop thread
518 ActionQueue::getInstance().stop();
519 ActionQueue::getInstance().clearTempQueue();
520#endif
521 ActionQueue::getInstance().clearQueue();
522 status = false;
523 }
524 if (status) {
525 std::ifstream input;
526 input.open("example.cfg");
527 if (!input.fail())
528 po::store(po::parse_config_file(input, config_file_options), vm);
529 input.close();
530 po::notify(vm);
531 }
532 return status;
533}
534
535/** Scan the argument list for -a or --arguments and store their order for later use.
536 */
537void CommandLineParser::scanforSequenceOfArguments()
538{
539 std::map <std::string, std::string> ShortFormToActionMap = getShortFormToActionMap();
540 LOG(0, "Scanning command line arguments and recognizing Actions.");
541 // go through all arguments
542 for (int i=1;i<argc;i++) {
543 LOG(2, "Checking on " << argv[i]);
544 // check whether they
545 if (argv[i][0] == '-') { // .. begin with -
546 LOG(2, "Possible argument: " << argv[i]);
547 if (argv[i][1] == '-') { // .. or --
548 LOG(1, "Putting " << argv[i] << " into the sequence.");
549 SequenceOfActions.push_back(&(argv[i][2]));
550 // .. and check that next letter is not numeric, if so insert
551 } else if (((argv[i][1] < '0') || (argv[i][1] > '9')) && ((argv[i][1] != '.'))) {
552 std::map <std::string, std::string>::iterator iter = ShortFormToActionMap.find(&(argv[i][1]));
553 if (iter != ShortFormToActionMap.end()) {
554 LOG(1, "Putting " << iter->second << " for " << iter->first << " into the sequence.");
555 SequenceOfActions.push_back(iter->second);
556 }
557 }
558 }
559 }
560}
561
562/** Makes the Parser parse the command line options with current known options.
563 * \param _argc arg count from main()
564 * \param **_argv argument array from main()
565 */
566void CommandLineParser::Run(int _argc, char **_argv)
567{
568 setOptions(_argc,_argv);
569 const bool status = Parse();
570 if (status)
571 scanforSequenceOfArguments();
572}
573
574/** Go through all Actions and create a map from short form to their token.
575 * \return map from Action's ShortForm to token.
576 */
577std::map <std::string, std::string> CommandLineParser::getShortFormToActionMap() const
578{
579 std::map <std::string, std::string> result;
580
581 ActionQueue &AQ = ActionQueue::getInstance();
582 ActionQueue::ActionTokens_t tokens = AQ.getListOfActions();
583 for (ActionQueue::ActionTokens_t::const_iterator iter = tokens.begin();
584 iter != tokens.end(); ++iter) {
585 const ActionTrait &CurrentTrait = AQ.getActionsTrait(*iter);
586 if (CurrentTrait.hasShortForm()) {
587 ASSERT(result.find(CurrentTrait.getShortForm()) == result.end(),
588 "Short form "+toString(CurrentTrait.getShortForm())+
589 " for action "+toString(*iter)+" already present from "+
590 std::string(result[CurrentTrait.getShortForm()])+"!");
591 result[CurrentTrait.getShortForm()] = *iter;
592 }
593 }
594
595 return result;
596}
597
598CONSTRUCT_SINGLETON(CommandLineParser)
Note: See TracBrowser for help on using the repository browser.