📄 myini.h
字号:
// MyIni.h: interface for the CMyIni class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MYINI_H__B6531120_B054_4E2F_8482_889CCAB90144__INCLUDED_)
#define AFX_MYINI_H__B6531120_B054_4E2F_8482_889CCAB90144__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//////////////////////////////////////////////////////////////////////
// CMyIni 实现思路是把ini文件中所有的section以字符方式读入内存,通过map容器管理和存取。
// 优点是可以快速查找信息,缺点是消耗较多内存,是一种典型的【内存换时间】的方案。
// 推荐在需要快速存取全局或者静态的ini时使用。ini较小的时候也可建立临时对象存取。
// Note: 支持 ' ', ';', '/', '\' 'TAB' 作为注释符号。
// '=' 两边支持' ', 'TAB';结束符号可以是' ', ';', 'TAB', '\r', '\n'。
//////////////////////////////////////////////////////////////////////
#include <map>
#include "MyLog.h"
#include "MyString.h"
class CMyIni
{
struct SECTION
{
std::map<CMyString, CMyString> setInfo;
};
std::map<CMyString, SECTION> m_setSection;
public:
CMyIni(bool bCritical);
CMyIni(const char* pszFile, bool bCritical);
virtual ~CMyIni();
bool SearchSection (const char* pszSection) const;
int GetData (const char* pszSection, const char* pszIndex) const;
const char* GetString (const char* pszSection, const char* pszIndex) const;
private:
bool Open (const char* pszIniFile);
bool OpenByBuf (void* buf, DWORD dwSize, const char* pszFileName);
bool ParseSection(char* pszLine, CMyString& str) const;
bool ParseContent(char* pszLine, CMyString& strIndex, CMyString& strContent) const;
bool IsValidLine (const char* pszLine) const;
bool m_bCritical;
std::string m_strFileName;
public:
static CMyIni* CreateNew (const char* pszIniFile, bool bCritical = false);
static CMyIni* CreateNewByBuf (void* buf, DWORD dwSize, const char* pszFileName, bool bCritical = false);
};
#endif // !defined(AFX_MYINI_H__B6531120_B054_4E2F_8482_889CCAB90144__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -