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BFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>GetDumySection()<EFBFBD><EFBFBD>ȡ
|
|
|
|
|
DumySection<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD>ܹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>Python<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
2016-12-06 17:05:56 +00:00
|
|
|
|
|
2016-12-14 15:34:44 +00:00
|
|
|
|
#include "ex_str.h"
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
|
|
typedef std::map<ex_wstr, ex_wstr> ex_ini_kvs;
|
|
|
|
|
|
|
|
|
|
class ExIniSection
|
2016-12-06 17:05:56 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
2016-12-14 15:34:44 +00:00
|
|
|
|
ExIniSection();
|
|
|
|
|
ExIniSection(const ex_wstr& strSectionName);
|
|
|
|
|
~ExIniSection();
|
2016-12-06 17:05:56 +00:00
|
|
|
|
|
|
|
|
|
void ClearUp(void);
|
|
|
|
|
|
|
|
|
|
ex_wstr Name(void) { return m_strName; }
|
|
|
|
|
|
|
|
|
|
void GetStr(const ex_wstr& strKey, ex_wstr& strValue, const ex_wstr& strDefault);
|
|
|
|
|
bool GetStr(const ex_wstr& strKey, ex_wstr& strValue);
|
|
|
|
|
|
|
|
|
|
void GetInt(const ex_wstr& strKey, int& iValue, int iDefault);
|
|
|
|
|
bool GetInt(const ex_wstr& strKey, int& iValue);
|
|
|
|
|
|
|
|
|
|
void GetBool(const ex_wstr& strKey, bool& bValue, bool bDefault);
|
|
|
|
|
bool GetBool(const ex_wstr& strKey, bool& bValue);
|
|
|
|
|
|
|
|
|
|
bool SetValue(const ex_wstr& strKey, const ex_wstr& strValue, bool bAddIfNotExists = false);
|
|
|
|
|
|
2016-12-14 15:34:44 +00:00
|
|
|
|
ex_ini_kvs& GetKeyValues(void) { return m_kvs; }
|
2016-12-06 17:05:56 +00:00
|
|
|
|
|
|
|
|
|
int Count(void) const
|
|
|
|
|
{
|
|
|
|
|
return m_kvs.size();
|
|
|
|
|
}
|
|
|
|
|
void Save(FILE* file, int codepage);
|
2016-12-14 15:34:44 +00:00
|
|
|
|
#ifdef EX_DEBUG
|
2016-12-06 17:05:56 +00:00
|
|
|
|
void Dump(void);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
bool _IsKeyExists(const ex_wstr& strKey);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ex_wstr m_strName;
|
2016-12-14 15:34:44 +00:00
|
|
|
|
ex_ini_kvs m_kvs;
|
2016-12-06 17:05:56 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2016-12-14 15:34:44 +00:00
|
|
|
|
typedef std::map<ex_wstr, ExIniSection*> ex_ini_sections;
|
2016-12-06 17:05:56 +00:00
|
|
|
|
|
|
|
|
|
// Ini file
|
2016-12-14 15:34:44 +00:00
|
|
|
|
class ExIniFile
|
2016-12-06 17:05:56 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
enum PARSE_RV
|
|
|
|
|
{
|
|
|
|
|
PARSE_ERROR,
|
|
|
|
|
PARSE_SECTION,
|
|
|
|
|
PARSE_KEYVALUE,
|
|
|
|
|
PARSE_COMMENT,
|
|
|
|
|
PARSE_OTHER
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public:
|
2016-12-14 15:34:44 +00:00
|
|
|
|
ExIniFile();
|
|
|
|
|
~ExIniFile();
|
2016-12-06 17:05:56 +00:00
|
|
|
|
|
|
|
|
|
void ClearUp(void);
|
|
|
|
|
|
|
|
|
|
// Read and parse special file.
|
|
|
|
|
bool LoadFromFile(const ex_wstr& strFileName, bool bClearOld = true);
|
|
|
|
|
bool LoadFromMemory(const ex_wstr& strData, bool bClearOld = true);
|
|
|
|
|
|
2017-01-08 15:53:37 +00:00
|
|
|
|
ex_ini_sections& GetAllSections(void) { return m_secs; }
|
|
|
|
|
|
2016-12-14 15:34:44 +00:00
|
|
|
|
ExIniSection* GetSection(const ex_wstr& strName, bool bCreateIfNotExists = false);
|
|
|
|
|
ExIniSection* GetDumySection(void) { return &m_dumy_sec; }
|
2016-12-06 17:05:56 +00:00
|
|
|
|
|
|
|
|
|
int Count(void) const
|
|
|
|
|
{
|
|
|
|
|
return m_secs.size();
|
|
|
|
|
}
|
|
|
|
|
void Save(int codepage = EX_CODEPAGE_UTF8);
|
2016-12-14 15:34:44 +00:00
|
|
|
|
#ifdef EX_DEBUG
|
2016-12-06 17:05:56 +00:00
|
|
|
|
void Dump(void);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
static PARSE_RV _ParseLine(const ex_wstr& strLine, ex_wstr& strKey, ex_wstr& strValue);
|
2016-12-14 15:34:44 +00:00
|
|
|
|
bool _ProcessLine(const ex_wstr strLine, ExIniSection** pCurSection);
|
2016-12-06 17:05:56 +00:00
|
|
|
|
|
|
|
|
|
private:
|
2016-12-14 15:34:44 +00:00
|
|
|
|
ex_ini_sections m_secs;
|
|
|
|
|
ExIniSection m_dumy_sec;
|
2016-12-06 17:05:56 +00:00
|
|
|
|
ex_wstr m_file_path;
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-14 15:34:44 +00:00
|
|
|
|
#endif // __EX_INI_H__
|