⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asl_ini.h

📁 泡泡堂单机版(含ASL游戏引擎源码 泡泡堂单机版(含ASL游戏引擎源码
💻 H
字号:
//-----------------------------------------------------------------------------
//
//    ____ Azure Star Game Engine 蓝星游戏引擎 ____
//
//    Copyright (c) 2006, 蓝星工作室
//    All rights reserved.
//
//    文件名称: asl_ini.h
//    摘    要: 高效ini文件读写类定义
//
//    当前版本: 1.0
//    作    者: 汤  祺
//    创建日期: 2006-8-16
//
//-----------------------------------------------------------------------------

#ifndef ASL_INI_INCLUDE
#define ASL_INI_INCLUDE

#pragma once

#include "asl_utils.h"
#include "asl_file.h"
#include <string>
#include <list>
#include <vector>

//-----------------------------------------------------------------------------
namespace ASL
{

//-----------------------------------------------------------------------------
// ASLIni类定义
//     本类将ini文件载入内存, 通过链表将文件按行存放, 同时记录每段的起始位置,
//     以快速定位. 使用时须先设置当前段, 再读写内容. 与使用WIN32API读写ini文
//     件相比, 有大量读写操作时效率要高很多.
//-----------------------------------------------------------------------------
class ASLIni
{

// 段结构级类型定义
private:
	struct SectionInfo								// 段信息结构
	{
		std::string strName;						// 段名
		std::list<std::string>::iterator itPos;		// 段在链表中的位置
	};

	typedef std::list<std::string> List;			// 存放string的链表
	typedef std::list<std::string>::iterator Iter;	// 链表游标
	typedef std::vector<SectionInfo> Vect;			// 存放段信息的数组



// 公有函数
public:
	// 构造函数
	ASLIni(void) : m_nCurrent(-1) {}
	
	// 析构函数
	~ASLIni(void) {}

	// 加载ini文件
	void Load(ASLFile *pFile);

	// 保存ini文件
	void Save(LPCSTR szFileName);

	// 设置当前段
	void SetSection(LPCSTR szSection);



// 读信息函数
public:
	// 读字符串
	std::string ReadString(LPCSTR szSection, LPCSTR szKey, LPCSTR szDefault);
	std::string ReadString(LPCSTR szKey, LPCSTR szDefault);
	std::string SafeReadString(LPCSTR szSection, LPCSTR szKey) throw(ASLIniException);
	std::string SafeReadString(LPCSTR szKey) throw(ASLIniException);
	
	// 读整型值
	int ReadInteger(LPCSTR szSection, LPCSTR szKey, int nDefault);
	int ReadInteger(LPCSTR szKey, int nDefault);
	int SafeReadInteger(LPCSTR szSection, LPCSTR szKey) throw(ASLIniException);
	int SafeReadInteger(LPCSTR szKey) throw(ASLIniException);
	
	// 读浮点值
	double ReadFloat(LPCSTR szSection, LPCSTR szKey, double lfDefault);
	double ReadFloat(LPCSTR szKey, double lfDefault);
	double SafeReadFloat(LPCSTR szSection, LPCSTR szKey) throw(ASLIniException);
	double SafeReadFloat(LPCSTR szKey) throw(ASLIniException);
	
	// 读布尔值
	bool ReadBoolean(LPCSTR szSection, LPCSTR szKey, bool bDefault);
	bool ReadBoolean(LPCSTR szKey, bool bDefault);
	bool SafeReadBoolean(LPCSTR szSection, LPCSTR szKey) throw(ASLIniException);
	bool SafeReadBoolean(LPCSTR szKey) throw(ASLIniException);
	


// 写信息函数
public:
	// 写字符串
	void WriteString(LPCSTR szSection, LPCSTR szKey, LPCSTR szValue);
	void WriteString(LPCSTR szKey, LPCSTR szValue);
	
	// 写整型值
	void WriteInteger(LPCSTR szSection, LPCSTR szKey, int nValue);
	void WriteInteger(LPCSTR szKey, int nValue);
	
	// 写浮点值
	void WriteFloat(LPCSTR szSection, LPCSTR szKey, double lfValue);
	void WriteFloat(LPCSTR szKey, double lfValue);
	
	// 写布尔值
	void WriteBoolean(LPCSTR szSection, LPCSTR szKey, bool bValue);
	void WriteBoolean(LPCSTR szKey, bool bValue);



// 成员变量
private:
	List m_lData;					// 文件内容链表
	Vect m_vSection;				// 段信息数组
	int  m_nCurrent;				// 当前段
	char m_szFileName[MAX_PATH];	// 文件名

}; // ASLIni类定义结束

} // namespace ASL

#endif // ASL_INI_INCLUDE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -