123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- // Ini.h: Schnittstelle für die Klasse CIni.
- // Autor: Michael Schikora
- // Mail: schiko@schikos.de
- //
- // If you found this code useful,
- // please let me know
- //
- // How to use:
- //
- //
- //void CMyClass::UpdateFromIni(BOOL bFromIni)
- //{
- // CIni ini(m_strFileName,m_strSection);
- // ini.SER_GET(bFromIni,m_nValueXY);
- // ini.SER_GET(bFromIni,m_strValue);
- // ini.SER_ARR(bFromIni,m_arValue,MAX_AR);
- // ini.SER_ARR(bFromIni,m_ar3D,3);
- // //ore with default values
- // ini.SER_GETD(bFromIni,m_nValueXY,5);
- // ini.SER_GETD(bFromIni,m_strValue,"Hello");
- // ini.SER_ARRD(bFromIni,m_arValue,MAX_AR,10);
- // ini.SER_ARRD(bFromIni,m_ar3D,3,5);
- //}
- #if !defined(AFX_INI_H__EEBAF800_182A_11D3_B51F_00104B4A13B4__INCLUDED_)
- #define AFX_INI_H__EEBAF800_182A_11D3_B51F_00104B4A13B4__INCLUDED_
- #if _MSC_VER >= 1000
- #pragma once
- #endif // _MSC_VER >= 1000
- #define SER_GET(bGet,value) SerGet(bGet,value,#value)
- #define SER_ARR(bGet,value,n) SerGet(bGet,value,n,#value)
- #define SER_GETD(bGet,value,default) SerGet(bGet,value,#value,NULL,default)
- #define SER_ARRD(bGet,value,n,default) SerGet(bGet,value,n,#value,default)
- class CIni
- {
- public:
- #ifdef __NEVER_DEFINED__
- // MAKRO: SerGet(bGet,value,#value)
- int SER_GET(BOOL bGet,int value);
- // MAKRO: SerGet(bGet,value,n,#value)
- int SER_ARR(bGet,int* value,int n);
- #endif
- // If the IniFilename contains no path,
- // the module-directory will be add to the FileName,
- // to avoid storing in the windows-directory
- // bModulPath=TRUE: ModulDir, bModulPath=FALSE: CurrentDir
- static void AddModulPath(DString& strFileName,BOOL bModulPath = TRUE);
- static DString GetDefaultSection();
- static DString GetDefaultIniFile(BOOL bModulPath = TRUE);
- CIni( BOOL bModulPath = TRUE);
- CIni(CIni const& Ini, BOOL bModulPath = TRUE);
- CIni(DString const& strFileName, BOOL bModulPath = TRUE);
- CIni(DString const& strFileName, DString const& strSection, BOOL bModulPath = TRUE);
- virtual ~CIni();
- void SetFileName(DString const& strFileName);
- void SetSection(DString const& strSection);
- DString const& GetFileName() const;
- DString const& GetSection() const;
- private:
- void Init(LPCSTR strIniFile, LPCSTR strSection = NULL);
- public:
- DString GetString(DString strEntry, LPCSTR strDefault=NULL, LPCSTR strSection = NULL);
- double GetDouble(DString strEntry, double fDefault = 0.0, LPCSTR strSection = NULL);
- float GetFloat(DString strEntry, float fDefault = 0.0, LPCSTR strSection = NULL);
- int GetInt(DString strEntry, int nDefault = 0, LPCSTR strSection = NULL);
- DWORD GetDWORD(DString strEntry, DWORD nDefault = 0, LPCSTR strSection = NULL);
- BOOL GetBool(DString strEntry, BOOL bDefault = FALSE, LPCSTR strSection = NULL);
- void WriteString(DString strEntry,DString str, LPCSTR strSection = NULL);
- void WriteDouble(DString strEntry,double f, LPCSTR strSection = NULL);
- void WriteFloat(DString strEntry,float f, LPCSTR strSection = NULL);
- void WriteInt(DString strEntry,int n, LPCSTR strSection = NULL);
- void WriteDWORD(DString strEntry,DWORD n, LPCSTR strSection = NULL);
- void WriteBool(DString strEntry,BOOL b, LPCSTR strSection = NULL);
- void SerGetString( BOOL bGet,DString & str, DString strEntry, LPCSTR strSection = NULL, LPCSTR strDefault=NULL);
- void SerGetDouble( BOOL bGet,double & f, DString strEntry, LPCSTR strSection = NULL, double fDefault = 0.0);
- void SerGetFloat( BOOL bGet,float & f, DString strEntry, LPCSTR strSection = NULL, float fDefault = 0.0);
- void SerGetInt( BOOL bGet,int & n, DString strEntry, LPCSTR strSection = NULL, int nDefault = 0);
- void SerGetDWORD( BOOL bGet,DWORD & n, DString strEntry, LPCSTR strSection = NULL, DWORD nDefault = 0);
- void SerGetBool( BOOL bGet,BOOL & b, DString strEntry, LPCSTR strSection = NULL, BOOL bDefault = FALSE);
- void SerGet( BOOL bGet,DString & str, DString strEntry, LPCSTR strSection = NULL, LPCSTR strDefault=NULL);
- void SerGet( BOOL bGet,double & f, DString strEntry, LPCSTR strSection = NULL, double fDefault = 0.0);
- void SerGet( BOOL bGet,float & f, DString strEntry, LPCSTR strSection = NULL, float fDefault = 0.0);
- void SerGet( BOOL bGet,int & n, DString strEntry, LPCSTR strSection = NULL, int nDefault = 0);
- void SerGet( BOOL bGet,short & n, DString strEntry, LPCSTR strSection = NULL, int nDefault = 0);
- void SerGet( BOOL bGet,DWORD & n, DString strEntry, LPCSTR strSection = NULL, DWORD nDefault = 0);
- void SerGet( BOOL bGet,WORD & n, DString strEntry, LPCSTR strSection = NULL, DWORD nDefault = 0);
- // void SerGet( BOOL bGet,BOOL & b, DString strEntry, LPCSTR strSection = NULL, BOOL bDefault = FALSE);
-
- //ARRAYs
- void SerGet( BOOL bGet,DString * str, int nCount, DString strEntry, LPCSTR strSection = NULL, LPCSTR strDefault=NULL);
- void SerGet( BOOL bGet,double * f, int nCount, DString strEntry, LPCSTR strSection = NULL, double fDefault = 0.0);
- void SerGet( BOOL bGet,float * f, int nCount, DString strEntry, LPCSTR strSection = NULL, float fDefault = 0.0);
- void SerGet( BOOL bGet,int * n, int nCount, DString strEntry, LPCSTR strSection = NULL, int nDefault = 0);
- void SerGet( BOOL bGet,short * n, int nCount, DString strEntry, LPCSTR strSection = NULL, int nDefault = 0);
- void SerGet( BOOL bGet,DWORD * n, int nCount, DString strEntry, LPCSTR strSection = NULL, DWORD nDefault = 0);
- void SerGet( BOOL bGet,WORD * n, int nCount, DString strEntry, LPCSTR strSection = NULL, DWORD nDefault = 0);
- //MAKRO :
- //SERGET(bGet,value) SerGet(bGet,value,#value)
- private:
- char* GetLPCSTR(DString strEntry,LPCSTR strSection,LPCSTR strDefault);
- BOOL m_bModulPath; //TRUE: Filenames without path take the Modulepath
- //FALSE: Filenames without path take the CurrentDirectory
- #define MAX_INI_BUFFER 256
- char m_chBuffer[MAX_INI_BUFFER];
- DString m_strFileName;
- DString m_strSection;
- //////////////////////////////////////////////////////////////////////
- // statische Methoden
- //////////////////////////////////////////////////////////////////////
- public:
- static DString Read( DString const& strFileName, DString const& strSection, DString const& strEntry, DString const& strDefault);
- static void Write(DString const& strFileName, DString const& strSection, DString const& strEntry, DString const& strValue);
- };
- #endif // !defined(AFX_INI_H__EEBAF800_182A_11D3_B51F_00104B4A13B4__INCLUDED_)
|