diff options
Diffstat (limited to 'src/optparser.h')
| -rw-r--r-- | src/optparser.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/optparser.h b/src/optparser.h new file mode 100644 index 0000000..39f048d --- /dev/null +++ b/src/optparser.h | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | #ifndef BU_OPT_PARSER_H | ||
| 2 | #define BU_OPT_PARSER_H | ||
| 3 | |||
| 4 | #include "bu/fstring.h" | ||
| 5 | #include "bu/list.h" | ||
| 6 | #include "bu/hash.h" | ||
| 7 | |||
| 8 | namespace Bu | ||
| 9 | { | ||
| 10 | class OptParser | ||
| 11 | { | ||
| 12 | public: | ||
| 13 | class Option | ||
| 14 | { | ||
| 15 | public: | ||
| 16 | Option(); | ||
| 17 | virtual ~Option(); | ||
| 18 | |||
| 19 | char cOpt; | ||
| 20 | Bu::FString sOpt; | ||
| 21 | Bu::FString sDesc; | ||
| 22 | }; | ||
| 23 | |||
| 24 | public: | ||
| 25 | OptParser(); | ||
| 26 | virtual ~OptParser(); | ||
| 27 | |||
| 28 | void parse( int argc, char *argv[] ); | ||
| 29 | |||
| 30 | void addOption( const Option &opt ); | ||
| 31 | |||
| 32 | template<typename c> | ||
| 33 | void callback( c *pObj, int (c::*fnc)( int, char *[] ) ) | ||
| 34 | { | ||
| 35 | (pObj->*fnc)( 0, NULL ); | ||
| 36 | } | ||
| 37 | |||
| 38 | private: | ||
| 39 | Bu::FString format( const Bu::FString &sIn, int iWidth, int iIndent ); | ||
| 40 | |||
| 41 | typedef Bu::List<Option> OptionList; | ||
| 42 | typedef Bu::Hash<char, Option *> ShortOptionHash; | ||
| 43 | typedef Bu::Hash<Bu::FString, Option *> LongOptionHash; | ||
| 44 | |||
| 45 | OptionList lOption; | ||
| 46 | ShortOptionHash hsOption; | ||
| 47 | LongOptionHash hlOption; | ||
| 48 | }; | ||
| 49 | }; | ||
| 50 | |||
| 51 | #endif | ||
