configuration.h

Go to the documentation of this file.
00001 //======================================================================
00002 // File:        configuration.h
00003 // Author:      Matthias Toussaint
00004 // Created:     Sun Dec  3 10:31:50 CET 2006
00005 // Project:     QtDMM
00006 // Description: Commandline parsing and configuration file reading
00007 //----------------------------------------------------------------------
00008 // This file  may  be used under  the terms of  the GNU  General Public
00009 // License  version 2.0 as published   by the Free Software  Foundation
00010 // and appearing  in the file LICENSE.GPL included  in the packaging of
00011 // this file.
00012 // 
00013 // This file is provided AS IS with  NO WARRANTY OF ANY KIND, INCLUDING 
00014 // THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00015 // PURPOSE.
00016 //----------------------------------------------------------------------
00017 // Copyright 2006 Matthias Toussaint
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

Generated on Mon Jan 22 23:24:18 2007 for cdmm by  doxygen 1.4.6