PCMConfigOptions.h
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00027 
00028 #ifndef __PCM_CONFIGOPTIONS_H__
00029 #  define __PCM_CONFIGOPTIONS_H__
00030 
00031 
00032 
00033 
00034 
00035 #  include "PCMPremeditations.h"
00036 
00037 #  include "PCMException.h"
00038 
00039 #  include "PCMLogger.h"
00040 
00041 #  include "PCMPointer.h"
00042 
00043 #  include "PCMContainer.h"
00044 
00045 
00046 
00047 
00048 
00049 #  include <string>
00050 
00051 #  include <map>
00052 
00053 namespace ParCompMark
00054 {
00055 
00060   class ConfigOptions
00061   {
00062 
00063         
00064         
00065         
00066 #  ifdef PARCOMPMARK_TEST
00067         friend class ParCompMarkTest::TestConfigOptions;
00068 #  endif
00069 
00070         
00071         
00072         
00073 
00074    protected:
00075 
00077         enum OptionType
00078         {
00079 
00081          STRING,
00082 
00084          BOOL,
00085 
00087          INTEGER,
00088 
00090          REAL
00091         };
00092 
00093         
00094         
00095         
00096 
00097    public:
00098 
00100         typedef Pointer < ConfigOptions,
00101         Mutex > Pointer;
00102 
00103    protected:
00104 
00106         typedef struct Option
00107 
00108         {                 
00110          OptionType type;                                                 
00112          void *value;                                                                                            
00114           std::string description;                                                                                                                                                                       
00115          typedef ParCompMark::Pointer < Option,
00116 
00117           DummyLock > Pointer;                                                                                                                                                                                                                                                                          
00118         public: ~Option()
00119          {
00120                 if(type != STRING)
00121                  delete[](u8 *) value;
00122                 else
00123                  delete static_cast < std::string * >(value);
00124          }
00125         }
00126         Option;
00127 
00128         
00129         
00130         
00131 
00133 
00134 
00135    protected:
00136 
00142         Container < ConfigOptions::Option, Mutex >::Pointer mOptions;
00143 
00149         bool mInitialized;
00150 
00152 
00153         
00154         
00155         
00156 
00158 
00159 
00160    public:
00161 
00165         ConfigOptions();
00166 
00170         virtual ~ ConfigOptions();
00171 
00173 
00174         
00175         
00176         
00177 
00179 
00180 
00181    public:
00182 
00188         const bool & getInitialized() const;
00189 
00191 
00192         
00193         
00194         
00195 
00197 
00198 
00199    public:
00200 
00204         virtual void initialize();
00205 
00209         virtual void finalize();
00210 
00216         virtual bool hasOption(const std::string & name);
00217 
00223         virtual std::string getString(const std::string & name);
00224 
00230         virtual bool getBool(const std::string & name);
00231 
00237         virtual s32 getInteger(const std::string & name);
00238 
00244         virtual Real getReal(const std::string & name);
00245 
00252         virtual bool testString(const std::string & name, const std::string & value);
00253 
00260         virtual void setString(const std::string & name, const std::string & value,
00261                            const std::string & description = "");
00262 
00269         virtual void setBool(const std::string & name, const bool & value,
00270                           const std::string & description = "");
00271 
00278         virtual void setInteger(const std::string & name, const s32 & value,
00279                                 const std::string & description = "");
00280 
00287         virtual void setReal(const std::string & name, const Real & value,
00288                           const std::string & description = "");
00289 
00294         virtual void removeOption(const std::string & name);
00295 
00300         virtual void saveToIniFile(const std::string & filename);
00301 
00306         virtual void loadFromIniFile(const std::string & filename);
00307 
00308    protected:
00309 
00316         virtual ConfigOptions::Option::Pointer getValue(const std::string & name,
00317                                                         const ConfigOptions::OptionType & type);
00318 
00326         virtual void setValue(const std::string & name, const void *value,
00327                           const ConfigOptions::OptionType & type, const std::string & description);
00328 
00334         virtual u32 getOptionTypeSize(const ConfigOptions::OptionType & type);
00335 
00341         virtual std::string optionToString(ConfigOptions::Option::Pointer & option);
00342 
00344 
00345   };
00346 
00347   
00348   
00349   
00350 
00351 #  include "PCMConfigOptions_impl.h"
00352 
00353 }
00354 
00355 #endif