00001 #ifndef MERCURY_INI_H
00002 #define MERCURY_INI_H
00003
00004 #include <map>
00005 #include "MercuryString.h"
00006 #include "MercuryVector.h"
00007
00009 class MercuryINI
00010 {
00011 public:
00012 MercuryINI( ) { m_bSaveOnExit = false; }
00013 MercuryINI( const MString &sFileName, bool bSaveOnExit );
00014 ~MercuryINI( );
00015
00017 bool Open( const MString &sFileName, bool bAddIncludes = true, bool bClearToStart = false );
00019 bool Load( const char * sIniText, long slen );
00021 bool Load( const MString &sIniText ) { return Load( sIniText.c_str(), sIniText.length() ); }
00022
00024 bool Save( const MString sFileName = "" );
00026 void Dump( MString & data );
00028 long Dump( char * & toDump );
00029
00031 void EnumerateKeys( MVector< MString > &keys );
00033 void EnumerateValues( const MString &key, MVector< MString > &values );
00035 void EnumerateValues( const MString &key, std::map< MString, MString > & values ) { values = m_mDatas[key]; }
00036
00038 MString GetValueS( const MString &key, const MString &value, MString sDefaultValue="", bool bMakeValIfNoExist=false );
00040 long GetValueI( const MString &key, const MString &value, long iDefaultValue=0, bool bMakeValIfNoExist=false );
00042 float GetValueF( const MString &key, const MString &value, float fDefaultValue=0, bool bMakeValIfNoExist=false );
00044 bool GetValueB( const MString &key, const MString &value, bool bDefaultValue=0, bool bMakeValIfNoExist=false );
00045
00047 bool GetValue( const MString &key, const MString &value, MString &data );
00048
00050 void SetValue( const MString &key, const MString &value, const MString &data );
00051
00053 bool RemoveValue( const MString &key, const MString &value );
00054
00056 MString GetLastError() { return m_sLastError; }
00057
00058 void ToggleSaveOnExit(bool toggle) { m_bSaveOnExit = toggle; }
00059
00060 private:
00062 bool m_bSaveOnExit;
00063 MString m_sLastError;
00064 MString m_sFileName;
00065 std::map< MString, std::map< MString, MString > > m_mDatas;
00066 std::map< MString, bool > m_mLoaded;
00067 };
00068
00070 extern MercuryINI * PREFSMAN;
00071
00073
00075 inline void CheckPREFSMANSetup() {
00076 if ( PREFSMAN == NULL )
00077 {
00078 PREFSMAN = new MercuryINI( "Mercury.ini", true );
00079 PREFSMAN->ToggleSaveOnExit( PREFSMAN->GetValueB( "Options", "WriteINI", true, true ) );
00080 }
00081 }
00082
00083
00084 #endif
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112