D:/Zythum/DinoKod/Common/Ini.h

00001 #ifndef __INI_H__
00002 #define __INI_H__
00003 
00004 #include "Common/CommonDll.h"
00005 #include "Common/Types.h"
00006 #include "Common/List.h"
00007 
00008 class KFile;
00009 
00010 //--------------------------------------------------------------------------------------------------------------------------
00011 class COMMON_API KIniKey
00012 {
00013 public:
00014         char*                   m_pKey;
00015         char*                   m_pValue;
00016 
00017         KIniKey( char* pKey, char* pValue )
00018         {
00019                 m_pKey          = strdup( pKey );
00020                 m_pValue        = strdup( pValue );
00021         }
00022 
00023         ~KIniKey()
00024         {
00025                 if( m_pKey )
00026                         Freep( m_pKey );
00027                 if( m_pValue )
00028                         Freep( m_pValue );
00029         }
00030 };
00031 
00032 //--------------------------------------------------------------------------------------------------------------------------
00033 class COMMON_API KIniSection
00034 {
00035 private:
00036         KList<KIniKey*> m_KeysList;
00037 
00038 public:
00039         char*                   m_pSection;
00040 
00041         KIniSection( char* pSection )
00042         {
00043                 m_pSection = strdup( pSection );
00044         }
00045 
00046         ~KIniSection()
00047         {
00048                 if( m_pSection )
00049                         Freep( m_pSection );
00050 
00051                 KIniKey*        pKey;
00052                 for( pKey = m_KeysList.GetFirst(); pKey; pKey = m_KeysList.GetNext( pKey ) )
00053                         delete pKey;
00054                 
00055                 m_KeysList.Clear();
00056         }
00057 
00058         void                    AddpKey( KIniKey* pKey )                { m_KeysList.Add( pKey );                               }
00059         void                    RemovepKey( KIniKey* pKey )             { m_KeysList.Remove( pKey );                    }
00060         KIniKey*                GetpFirstKey()                                  { return m_KeysList.GetFirst();                 }
00061         KIniKey*                GetpNextKey( KIniKey* pKey )    { return m_KeysList.GetNext( pKey );    }
00062 };
00063 
00064 //--------------------------------------------------------------------------------------------------------------------------
00065 class COMMON_API KIni
00066 {
00067 private:
00068         KList<KIniSection*>     m_SectionsList;
00069 
00070 protected:
00071         KFile*                          m_pFile;
00072         bool                            m_bMustCloseFile;
00073         bool                            m_bHasChanged;
00074 
00075         void                            LoadCache();
00076         void                            SaveCache();
00077 
00078         char*                           FindKey( char* pSection, char* pKey, bool bShowError = true );
00079         void                            SetKey( char* pSection, char* pKey, char* pString );
00080 
00081 public:
00082                                                 KIni( KFile& File );
00083                                                 KIni( char*     pFileName );
00084                                                 ~KIni();
00085                                                 
00086         const char*                     ReadString( char* pSection, char* pKey, char* DefaultString );
00087         s32                                     ReadInt( char* pSection, char* pKey, s32 DefaultValue );
00088         float                           ReadFloat( char* pSection, char* pKey, float DefaultValue );
00089         void                            WriteString( char* pSection, char* pKey, char* pString );
00090         void                            WriteInt( char* pSection, char* pKey, s32 Value );
00091         void                            WriteFloat( char* pSection, char* pKey, float Value );
00092 };
00093 
00094 #endif  __INI_H__

Generated on Sun Mar 25 20:02:10 2007 for Zythum Project by  doxygen 1.5.1-p1