MercuryINI.h

Go to the documentation of this file.
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  * Copyright (c) 2005-2006, Charles Lohr
00088  * All rights reserved.
00089  *
00090  * Redistribution and use in source and binary forms, with or
00091  * without modification, are permitted provided that the following
00092  * conditions are met:
00093  *  -   Redistributions of source code must retain the above
00094  *      copyright notice, this list of conditions and the following disclaimer.
00095  *  -   Redistributions in binary form must reproduce the above copyright
00096  *      notice, this list of conditions and the following disclaimer in
00097  *      the documentation and/or other materials provided with the distribution.
00098  *  -   Neither the name of the Mercury Engine nor the names of its
00099  *      contributors may be used to endorse or promote products derived from
00100  *      this software without specific prior written permission.
00101  *
00102  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00103  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00104  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00105  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00106  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00107  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00108  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00109  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00110  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00111  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00112  */

Hosted by SourceForge.net Logo