| [c6efc1] | 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 | 
 | 
|---|
| [56f73b] | 11 | // include config.h
 | 
|---|
 | 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 13 | #include <config.h>
 | 
|---|
 | 14 | #endif
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | 
 | 
|---|
| [c6efc1] | 17 | #include <boost/program_options.hpp>
 | 
|---|
 | 18 | 
 | 
|---|
 | 19 | namespace po = boost::program_options;
 | 
|---|
 | 20 | 
 | 
|---|
| [ad011c] | 21 | #include "CodePatterns/Singleton.hpp"
 | 
|---|
| [e4afb4] | 22 | #include "UIElements/CommandLineUI/TypeEnumContainer.hpp"
 | 
|---|
| [c6efc1] | 23 | 
 | 
|---|
| [e4afb4] | 24 | #include <map>
 | 
|---|
 | 25 | 
 | 
|---|
| [ce7fdc] | 26 | namespace MoleCuilder {
 | 
|---|
 | 27 |   class Action;
 | 
|---|
 | 28 |   class OptionTrait;
 | 
|---|
 | 29 | }
 | 
|---|
 | 30 | class CommandLineParser_ActionRegistry_ConsistenyTest;
 | 
|---|
| [c6efc1] | 31 | 
 | 
|---|
| [de8e45] | 32 | /** This class is a wrapper for boost::program_options.
 | 
|---|
 | 33 |  *
 | 
|---|
 | 34 |  */
 | 
|---|
| [bcd072] | 35 | class CommandLineParser : public Singleton<CommandLineParser> {
 | 
|---|
 | 36 |   friend class Singleton<CommandLineParser>;
 | 
|---|
| [19290f] | 37 | 
 | 
|---|
 | 38 |   //!> test needs to access CmdParserLookup to see whether menus are missing
 | 
|---|
| [552597] | 39 |   friend class CommandLineParser_ActionRegistry_ConsistencyTest;
 | 
|---|
| [c6efc1] | 40 | public:
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 |   // Parses the command line arguments in CommandLineParser::**argv with currently known options.
 | 
|---|
| [e4afb4] | 43 |   void Run(int _argc, char **_argv);
 | 
|---|
 | 44 | 
 | 
|---|
 | 45 |   // Initialises all options from ActionRegistry.
 | 
|---|
 | 46 |   void InitializeCommandArguments();
 | 
|---|
| [c6efc1] | 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 |    */
 | 
|---|
| [e4afb4] | 56 |   po::options_description analysis;
 | 
|---|
 | 57 |   po::options_description atom;
 | 
|---|
| [f63e41] | 58 |   po::options_description bond;
 | 
|---|
| [e4afb4] | 59 |   po::options_description command;
 | 
|---|
 | 60 |   po::options_description edit;
 | 
|---|
| [a88452] | 61 |   po::options_description fill;
 | 
|---|
| [4dc309] | 62 |   po::options_description shape;
 | 
|---|
| [e4afb4] | 63 |   po::options_description fragmentation;
 | 
|---|
| [987145] | 64 |   po::options_description geometry;
 | 
|---|
| [d09093] | 65 |   po::options_description graph;
 | 
|---|
| [e4afb4] | 66 |   po::options_description molecule;
 | 
|---|
| [d09093] | 67 |   po::options_description options;
 | 
|---|
| [e4afb4] | 68 |   po::options_description parser;
 | 
|---|
| [f5724f] | 69 |   po::options_description potential;
 | 
|---|
| [e4afb4] | 70 |   po::options_description selection;
 | 
|---|
 | 71 |   po::options_description tesselation;
 | 
|---|
 | 72 |   po::options_description world;
 | 
|---|
| [c6efc1] | 73 | 
 | 
|---|
| [e3ecc1a] | 74 |   po::options_description visible;
 | 
|---|
 | 75 | 
 | 
|---|
| [bcd072] | 76 |   po::variables_map vm;
 | 
|---|
| [c6efc1] | 77 | 
 | 
|---|
| [7e6b00] | 78 |   // private sequence of actions as they appeared on the command line
 | 
|---|
 | 79 |   std::list<std::string> SequenceOfActions;
 | 
|---|
 | 80 | 
 | 
|---|
| [c6efc1] | 81 | private:
 | 
|---|
| [bcd072] | 82 |   // private constructor and destructor
 | 
|---|
 | 83 |   CommandLineParser();
 | 
|---|
 | 84 |   virtual ~CommandLineParser();
 | 
|---|
 | 85 | 
 | 
|---|
| [c6efc1] | 86 |   /* The following program_options options_decriptions are used to
 | 
|---|
 | 87 |    * generate the various cases and call differently in Parse().
 | 
|---|
 | 88 |    */
 | 
|---|
 | 89 |   po::options_description cmdline_options;
 | 
|---|
 | 90 |   po::options_description config_file_options;
 | 
|---|
 | 91 | 
 | 
|---|
| [e4afb4] | 92 |   // adds options to the parser
 | 
|---|
| [7912e9] | 93 |   void AddOptionToParser(
 | 
|---|
 | 94 |       const MoleCuilder::OptionTrait * const currentOption, 
 | 
|---|
 | 95 |       po::options_description* OptionList,
 | 
|---|
 | 96 |       const bool _DefaultAsImplicit);
 | 
|---|
| [e4afb4] | 97 | 
 | 
|---|
 | 98 |   // creates a map from short forms to action tokens needed to parse command line
 | 
|---|
| [2a0a9e3] | 99 |   std::map <std::string, std::string> getShortFormToActionMap() const;
 | 
|---|
| [e4afb4] | 100 | 
 | 
|---|
| [c6e5eb] | 101 |   typedef std::map< std::string , po::options_description *> CmdParserLookupMap;
 | 
|---|
 | 102 | 
 | 
|---|
| [e4afb4] | 103 |   // lookup list from "configmenus" to the ones of CommandLineParser
 | 
|---|
| [c6e5eb] | 104 |   CmdParserLookupMap CmdParserLookup;
 | 
|---|
| [e4afb4] | 105 | 
 | 
|---|
| [c6efc1] | 106 |   // Sets the options from the three cases.
 | 
|---|
 | 107 |   void setOptions(int _argc, char **_argv);
 | 
|---|
 | 108 | 
 | 
|---|
 | 109 |   // Parses all options from command line and config file
 | 
|---|
| [06b5df] | 110 |   bool Parse();
 | 
|---|
| [c6efc1] | 111 | 
 | 
|---|
| [7e6b00] | 112 |   // as boost's program_options does not care about of order of appearance but we do for actions,
 | 
|---|
 | 113 |   // we have to have a list and a function to obtain it.
 | 
|---|
| [e4afb4] | 114 |   void scanforSequenceOfArguments();
 | 
|---|
 | 115 | 
 | 
|---|
 | 116 |   TypeEnumContainer TypeToEnums;
 | 
|---|
| [7e6b00] | 117 | 
 | 
|---|
| [c6efc1] | 118 |   // argument counter and array passed on from main()
 | 
|---|
 | 119 |   int argc;
 | 
|---|
 | 120 |   char **argv;
 | 
|---|
 | 121 | };
 | 
|---|
 | 122 | 
 | 
|---|
 | 123 | #endif /* COMMANDLINEPARSER_HPP_ */
 | 
|---|