?? asl_ini.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 + -