teleport/common/libex/include/ex/ex_ini.h

113 lines
2.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef __EX_INI_H__
#define __EX_INI_H__
/*
<EFBFBD>ر<EFBFBD>ע<EFBFBD>
1. <20><> <20>ֺ<EFBFBD>';' <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>'#' <20><>Ϊע<CEAA><D7A2><EFBFBD>еĵ<D0B5>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD>
2. <20><>֧<EFBFBD><D6A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
3. ֵ<><D6B5><EFBFBD>Ե<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>Ⱥŷָ<C5B7><D6B8><EFBFBD><EFBFBD>Ⱥ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>пո<D0BF><EFBFBD><E1B1BB><EFBFBD>ԣ<EFBFBD>֮<EFBFBD><D6AE>Ŀո<C4BF><EFBFBD><E1B1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>β<EFBFBD>ո<EFBFBD>
4. <20><><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3>С<EFBFBD>ڵ<EFBFBD>ֵ<EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>GetDumySection()<29><>ȡ
DumySection<6F><6E>Ҫ<EFBFBD><D2AA>Ϊ<EFBFBD><CEAA><EFBFBD>ܹ<EFBFBD><DCB9><EFBFBD><EFBFBD>ݼ򵥵<DDBC>Python<6F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
*/
#include "ex_str.h"
#include <map>
typedef std::map<ex_wstr, ex_wstr> ex_ini_kvs;
class ExIniSection
{
public:
ExIniSection();
ExIniSection(const ex_wstr& strSectionName);
~ExIniSection();
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);
ex_ini_kvs& GetKeyValues(void) { return m_kvs; }
int Count(void) const
{
return (int)m_kvs.size();
}
void Save(FILE* file, int codepage);
#ifdef EX_DEBUG
void Dump(void);
#endif
protected:
bool _IsKeyExists(const ex_wstr& strKey);
private:
ex_wstr m_strName;
ex_ini_kvs m_kvs;
};
typedef std::map<ex_wstr, ExIniSection*> ex_ini_sections;
// Ini file
class ExIniFile
{
public:
enum PARSE_RV
{
PARSE_ERROR,
PARSE_SECTION,
PARSE_KEYVALUE,
PARSE_COMMENT,
PARSE_OTHER
};
public:
ExIniFile();
~ExIniFile();
const ex_wstr& get_filename(void){return m_file_path;}
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);
ex_ini_sections& GetAllSections(void) { return m_secs; }
ExIniSection* GetSection(const ex_wstr& strName, bool bCreateIfNotExists = false);
ExIniSection* GetDumySection(void) { return &m_dumy_sec; }
int Count(void) const
{
return (int)(m_secs.size());
}
void Save(int codepage = EX_CODEPAGE_UTF8);
#ifdef EX_DEBUG
void Dump(void);
#endif
protected:
static PARSE_RV _ParseLine(const ex_wstr& strLine, ex_wstr& strKey, ex_wstr& strValue);
bool _ProcessLine(const ex_wstr strLine, ExIniSection** pCurSection);
private:
ex_ini_sections m_secs;
ExIniSection m_dumy_sec;
ex_wstr m_file_path;
};
#endif // __EX_INI_H__