| 1 | /*
|
|---|
| 2 | * CommandLineParser.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: May 8, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifndef COMMANDLINEPARSER_HPP_
|
|---|
| 9 | #define COMMANDLINEPARSER_HPP_
|
|---|
| 10 |
|
|---|
| 11 | // include config.h
|
|---|
| 12 | #ifdef HAVE_CONFIG_H
|
|---|
| 13 | #include <config.h>
|
|---|
| 14 | #endif
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 | #include <boost/program_options.hpp>
|
|---|
| 18 |
|
|---|
| 19 | namespace po = boost::program_options;
|
|---|
| 20 |
|
|---|
| 21 | #include "CodePatterns/Singleton.hpp"
|
|---|
| 22 | #include "UIElements/CommandLineUI/TypeEnumContainer.hpp"
|
|---|
| 23 |
|
|---|
| 24 | #include <map>
|
|---|
| 25 |
|
|---|
| 26 | namespace MoleCuilder {
|
|---|
| 27 | class Action;
|
|---|
| 28 | class OptionTrait;
|
|---|
| 29 | }
|
|---|
| 30 | class CommandLineParser_ActionRegistry_ConsistenyTest;
|
|---|
| 31 |
|
|---|
| 32 | /** This class is a wrapper for boost::program_options.
|
|---|
| 33 | *
|
|---|
| 34 | */
|
|---|
| 35 | class CommandLineParser : public Singleton<CommandLineParser> {
|
|---|
| 36 | friend class Singleton<CommandLineParser>;
|
|---|
| 37 |
|
|---|
| 38 | //!> test needs to access CmdParserLookup to see whether menus are missing
|
|---|
| 39 | friend class CommandLineParser_ActionRegistry_ConsistencyTest;
|
|---|
| 40 | public:
|
|---|
| 41 |
|
|---|
| 42 | // Parses the command line arguments in CommandLineParser::**argv with currently known options.
|
|---|
| 43 | void Run(int _argc, char **_argv);
|
|---|
| 44 |
|
|---|
| 45 | // Initialises all options from ActionRegistry.
|
|---|
| 46 | void InitializeCommandArguments();
|
|---|
| 47 |
|
|---|
| 48 | // Checks whether there have been any commands on the command line.
|
|---|
| 49 | bool isEmpty();
|
|---|
| 50 |
|
|---|
| 51 | /* boost's program_options are sorted into three categories:
|
|---|
| 52 | * -# generic options: option available to both command line and config
|
|---|
| 53 | * -# config options: only available in the config file
|
|---|
| 54 | * -# hidden options: options which the user is not shown on "help"
|
|---|
| 55 | */
|
|---|
| 56 | po::options_description analysis;
|
|---|
| 57 | po::options_description atom;
|
|---|
| 58 | po::options_description bond;
|
|---|
| 59 | po::options_description command;
|
|---|
| 60 | po::options_description edit;
|
|---|
| 61 | po::options_description fill;
|
|---|
| 62 | po::options_description shape;
|
|---|
| 63 | po::options_description fragmentation;
|
|---|
| 64 | po::options_description graph;
|
|---|
| 65 | po::options_description molecule;
|
|---|
| 66 | po::options_description options;
|
|---|
| 67 | po::options_description parser;
|
|---|
| 68 | po::options_description potential;
|
|---|
| 69 | po::options_description selection;
|
|---|
| 70 | po::options_description tesselation;
|
|---|
| 71 | po::options_description world;
|
|---|
| 72 |
|
|---|
| 73 | po::options_description visible;
|
|---|
| 74 |
|
|---|
| 75 | po::variables_map vm;
|
|---|
| 76 |
|
|---|
| 77 | // private sequence of actions as they appeared on the command line
|
|---|
| 78 | std::list<std::string> SequenceOfActions;
|
|---|
| 79 |
|
|---|
| 80 | private:
|
|---|
| 81 | // private constructor and destructor
|
|---|
| 82 | CommandLineParser();
|
|---|
| 83 | virtual ~CommandLineParser();
|
|---|
| 84 |
|
|---|
| 85 | /* The following program_options options_decriptions are used to
|
|---|
| 86 | * generate the various cases and call differently in Parse().
|
|---|
| 87 | */
|
|---|
| 88 | po::options_description cmdline_options;
|
|---|
| 89 | po::options_description config_file_options;
|
|---|
| 90 |
|
|---|
| 91 | // adds options to the parser
|
|---|
| 92 | void AddOptionToParser(const MoleCuilder::OptionTrait * const currentOption, po::options_description* OptionList);
|
|---|
| 93 |
|
|---|
| 94 | // creates a map from short forms to action tokens needed to parse command line
|
|---|
| 95 | std::map <std::string, std::string> getShortFormToActionMap() const;
|
|---|
| 96 |
|
|---|
| 97 | typedef std::map< std::string , po::options_description *> CmdParserLookupMap;
|
|---|
| 98 |
|
|---|
| 99 | // lookup list from "configmenus" to the ones of CommandLineParser
|
|---|
| 100 | CmdParserLookupMap CmdParserLookup;
|
|---|
| 101 |
|
|---|
| 102 | // Sets the options from the three cases.
|
|---|
| 103 | void setOptions(int _argc, char **_argv);
|
|---|
| 104 |
|
|---|
| 105 | // Parses all options from command line and config file
|
|---|
| 106 | void Parse();
|
|---|
| 107 |
|
|---|
| 108 | // as boost's program_options does not care about of order of appearance but we do for actions,
|
|---|
| 109 | // we have to have a list and a function to obtain it.
|
|---|
| 110 | void scanforSequenceOfArguments();
|
|---|
| 111 |
|
|---|
| 112 | TypeEnumContainer TypeToEnums;
|
|---|
| 113 |
|
|---|
| 114 | // argument counter and array passed on from main()
|
|---|
| 115 | int argc;
|
|---|
| 116 | char **argv;
|
|---|
| 117 | };
|
|---|
| 118 |
|
|---|
| 119 | #endif /* COMMANDLINEPARSER_HPP_ */
|
|---|