| Line |   | 
|---|
| 1 | /*! | 
|---|
| 2 |  * @file cmdline_parser.h | 
|---|
| 3 |  * @brief Definition of ... | 
|---|
| 4 |  */ | 
|---|
| 5 |  | 
|---|
| 6 | #ifndef _CMD_LINE_PARSER_H | 
|---|
| 7 | #define _CMD_LINE_PARSER_H | 
|---|
| 8 |  | 
|---|
| 9 | #include <list> | 
|---|
| 10 | #include <string> | 
|---|
| 11 | #include <vector> | 
|---|
| 12 |  | 
|---|
| 13 | #include "lib/util/debug.h" | 
|---|
| 14 | #include "lib/util/multi_type.h" | 
|---|
| 15 |  | 
|---|
| 16 |  | 
|---|
| 17 | struct ArgTableEntry | 
|---|
| 18 | { | 
|---|
| 19 |   unsigned int    id; | 
|---|
| 20 |   std::string     longOption; | 
|---|
| 21 |   char            shortOption; | 
|---|
| 22 |   unsigned int    numArgs; | 
|---|
| 23 |   std::string     argNames; | 
|---|
| 24 |   std::string     help; | 
|---|
| 25 | }; | 
|---|
| 26 |  | 
|---|
| 27 | typedef std::list<ArgTableEntry> ArgTable; | 
|---|
| 28 |  | 
|---|
| 29 | typedef bool (*ArgParserCallback)( ArgTableEntry, void*, const std::string &, const std::vector<MultiType> & ); | 
|---|
| 30 |  | 
|---|
| 31 |  | 
|---|
| 32 | //! A class for parsing command line arguments | 
|---|
| 33 | class CmdLineParser { | 
|---|
| 34 |  | 
|---|
| 35 |   public: | 
|---|
| 36 |     CmdLineParser(); | 
|---|
| 37 |     virtual ~CmdLineParser(); | 
|---|
| 38 |  | 
|---|
| 39 |     bool add( int id, const std::string& longOption, char shortOption, int numArgs, const std::string & argNames, const std::string& help, bool back=false ); | 
|---|
| 40 |  | 
|---|
| 41 |     bool parse( ArgParserCallback cb, void* data, int argc, char** argv ); | 
|---|
| 42 |  | 
|---|
| 43 |     void showHelp(); | 
|---|
| 44 |  | 
|---|
| 45 |   private: | 
|---|
| 46 |     ArgTable argTable; | 
|---|
| 47 |     std::string exeName; | 
|---|
| 48 |  | 
|---|
| 49 |     inline bool matches( ArgTableEntry entry, std::string arg, bool & finish ); | 
|---|
| 50 |  | 
|---|
| 51 | }; | 
|---|
| 52 |  | 
|---|
| 53 | #endif /* _CMD_LINE_PARSER_H */ | 
|---|
       
      
      Note: See 
TracBrowser
        for help on using the repository browser.