00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _FILEINI_H_
00028 #define _FILEINI_H_
00029
00030
00031 #include <string>
00032 #include <list>
00033 #include <map>
00034 #include "CCTChar.h"
00035
00037 typedef std::list<std::tstring> TCHARSTRLIST;
00039 typedef std::map<std::tstring, std::tstring> TCHARSTR2STR;
00041 typedef std::map<std::tstring, TCHARSTRLIST> TCHARSTR2STRLIST;
00042
00047
00048 #define FILEINI_IGNORE_COMMENTS 0x00000001
00050 #define FILEINI_TRIM 0x00000002
00051
00058 struct INILine
00059 {
00063 INILine()
00064 {
00065 };
00066
00072 INILine(const std::tstring& Key, const std::tstring& Value)
00073 {
00074
00075 sKey = Key;
00076 sValue = Value;
00077 };
00082 INILine(const INILine& line)
00083 {
00084 sKey = line.sKey;
00085 sValue = line.sValue;
00086 };
00088 std::tstring sKey;
00090 std::tstring sValue;
00091 };
00092
00094 typedef std::list<INILine> INILINELIST;
00095
00099 class FileINI
00100 {
00101 public:
00105 FileINI() : m_pData(NULL), m_bOwn(false), m_bUnicode(false), m_nOffset(0) {};
00107 FileINI(LPCTSTR lpFilename);
00109 FileINI(char* pData, DWORD dwSize, bool bOwn = true);
00111 FileINI(bool bUnicode, char* pData, DWORD dwSize, bool bOwn = true);
00115 ~FileINI() {if (m_bOwn && (m_pData != NULL)) delete [] m_pData;};
00116
00117 protected:
00118
00120 char* m_pData;
00122 bool m_bOwn;
00124 bool m_bUnicode;
00126 int m_nOffset;
00127
00128 public:
00129
00134 bool HasData() const {return m_pData != NULL;};
00135
00136
00138 bool LoadINIFile(LPCTSTR lpFilename);
00140 bool GetLines(LPCTSTR pSection, TCHARSTRLIST& listLines, UINT uFlags = 0);
00142 bool GetKeys(LPCTSTR pSection, TCHARSTR2STR& mapKeys, UINT uFlags = 0);
00144 bool GetKeys(LPCTSTR pSection, INILINELIST& listLines, UINT uFlags = 0);
00146 bool GetAllSections(TCHARSTRLIST& lSections);
00147
00148
00150 static bool GetLines(LPCTSTR pFilename, LPCTSTR pSection, TCHARSTRLIST& list, UINT uFlags = 0);
00152 static bool GetKeys(LPCTSTR pFilename, LPCTSTR pSection, TCHARSTR2STR& mapKeys, UINT uFlags = 0);
00154 static bool GetKeys(LPCTSTR pFilename, LPCTSTR pSection, INILINELIST& list, UINT uFlags = 0);
00155
00157 static bool GetVarValues(LPCTSTR pVarValue, TCHARSTRLIST& lValues);
00159 static bool ReplaceVariables(LPCTSTR pValue, const TCHARSTR2STRLIST& lVariables, TCHARSTRLIST& lResults);
00161 static bool GetAllSections(LPCTSTR pFilename, TCHARSTRLIST& lSections);
00162
00163 protected:
00164
00166 static bool CheckLineForSection(const WCHAR* pLine, std::tstring::size_type nLineLen, LPCTSTR pSection, std::tstring::size_type nSectionLen, bool bUnicode, bool& bFoundSection);
00168 static void DoInitLine(const WCHAR* pLine, std::tstring::size_type nLineLen, INILINELIST& list, UINT uFlags, bool bUnicode);
00170 static bool TestUnicode(FILE* pFile);
00171
00173 bool TestUnicode();
00174 };
00175
00176 #endif //#define _FILEINI_H_