00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef CONFIGURATION_HH
00021 #define CONFIGURATION_HH
00022
00023 #include <vector>
00024 #include <string>
00025 #include <sstream>
00026
00046 class Configuration
00047 {
00048 public:
00049 Configuration();
00050 ~Configuration();
00051
00054 class Option
00055 {
00056 public:
00057 Option( const std::string & _shortOption,
00058 const std::string & _longOption,
00059 bool _hasParameter, const std::string & _description ) :
00060 shortOption( _shortOption ),
00061 longOption( _longOption ),
00062 hasParameter( _hasParameter ),
00063 description( _description )
00064 {
00065 }
00067 std::string shortOption;
00069 std::string longOption;
00071 bool hasParameter;
00073 std::string description;
00074 };
00075
00078 class OptionEntry
00079 {
00080 public:
00081 OptionEntry( const std::string & _key,
00082 const std::string & _value ) :
00083 key( _key ),
00084 value( _value )
00085 {
00086 }
00088 std::string key;
00090 std::string value;
00091 };
00099 void addOption( const Option & );
00107 bool setCommandLine( int argc, char **argv );
00108
00109 typedef std::vector<Option> OptionList;
00110 typedef std::vector<OptionEntry> EntryList;
00111
00116 bool hasKey( const std::string & key ) const;
00121 std::string value( const std::string & key ) const;
00126 int intValue( const std::string & key ) const;
00136 bool loadFile( const std::string & filename );
00139 void setHelpText( const std::string & text ) { m_helpText = text; }
00142 std::string helpText() const;
00143
00145 void printEntries() const;
00146
00147 protected:
00149 OptionList m_option;
00151 EntryList m_entry;
00153 std::string m_helpText;
00154
00159 int findOption( const std::string & optionText ) const;
00164 int findShort( const std::string & optionText ) const;
00169 int findLong( const std::string & optionText ) const;
00174 int findEntry( const std::string & key ) const;
00179 void insertEntry( const std::string & key,
00180 const std::string & value );
00181 };
00182
00183 #endif // CONFIGURATION_HH