/********************************************************************* *文件说明: 配置文件辅助接口 *作者: logos *日期: 2018/09/01 *修改日志: 2018/09/01 增加虚拟类接口,可扩展多个配置文件 ***********************************************************************/ #pragma once #ifndef DLL_INCLUDE_ICONFIG_H #define DLL_INCLUDE_ICONFIG_H #ifndef EXPORT_C #define EXPORT_C extern "C" #endif #ifndef WINAPI #define WINAPI __stdcall #endif struct TConfig; class IConfig {//配置接口类 public: /**************************************************** *Function: 加载文件,必须先加载,否则没有配置项 *Intput: file 文件绝对路径含扩展名 <256字节 *Output: NULL *Return: 成功返回0,失败返回错误码 ******************************************************/ virtual int Load(const char* file = 0) = 0; /**************************************************** *Function: 解析一个配置文件里面的内容 *Intput: pszcontent 配置文件内容 为NULL则配置空 *Output: NULL *Return: 成功返回0,失败返回错误码 *PS: 调用此接口,则之前的配置全部清空 ******************************************************/ virtual int Parse(const char* pszcontent = 0) = 0; /**************************************************** *Function: 保存到文件 *Intput: file 文件绝对路径含扩展名 <256字节 *Output: NULL *Return: 成功返回0,失败返回错误码 *PS: file=NULL时,保存为Load时的路径 ******************************************************/ virtual int Save(const char* file = 0) = 0; /**************************************************** *Function: 增加/修改一个配置项 -- 字符串 *Intput: key 段落名 [xxx] -- 不能包含'/' <32字节 name 关键字 xxx=? <32字节 lpValue 值 ?=xxx <256字节 *Output: NULL *Return: 成功返回0,失败返回错误码 ******************************************************/ virtual int SetString(const char* key, const char* name, const char* lpValue) = 0; /**************************************************** *Function: 获取一个配置项 -- 字符串 *Intput: key 段落名 [xxx] -- 不能包含'/' <32字节 name 关键字 xxx=? <32字节 lpValue 值 ?=xxx <256字节 *Output: lpValue 获取值缓冲区 *Return: 成功返回0,失败返回错误码 ******************************************************/ virtual int GetString(const char* key, const char* name, char* lpValue) = 0; /**************************************************** *Function: 获取一个配置项 -- 字符串 *Intput: key 段落名 [xxx] -- 不能包含'/' <32字节 name 关键字 xxx=? <32字节 *Output: NULL *Return: lpValue 值 ?=xxx <256字节 成功返回lpValue,不存在返回NULL ******************************************************/ virtual const char* GetString(const char* key, const char* name) = 0; /**************************************************** *Function: 增加/修改一个配置项 -- 整型 *Intput: key 段落名 [xxx] -- 不能包含'/' <32字节 name 关键字 xxx=? <32字节 iValue 值 ?=xxx 整型值 *Output: NULL *Return: 成功返回0,失败返回错误码 ******************************************************/ virtual int SetInt(const char* key, const char* name, int iValue) = 0; /**************************************************** *Function: 获取一个配置项 -- 整型 *Intput: key 段落名 [xxx] -- 不能包含'/' <32字节 name 关键字 xxx=? <32字节 *Output: NULL *Return: iValue 值 ?=xxx 整型值 成功返回iValue,失败返回0 ******************************************************/ virtual int GetInt(const char* key, const char* name) = 0; /**************************************************** *Function: 增加/修改一个配置项 -- double型 *Intput: key 段落名 [xxx] -- 不能包含'/' <32字节 name 关键字 xxx=? <32字节 dValue 值 ?=xxx 整型值 *Output: NULL *Return: 成功返回0,失败返回错误码 ******************************************************/ virtual int SetDouble(const char* key, const char* name, double dValue) = 0; /**************************************************** *Function: 获取一个配置项 -- double型 *Intput: key 段落名 [xxx] -- 不能包含'/' <32字节 name 关键字 xxx=? <32字节 *Output: NULL *Return: dValue 值 ?=xxx double值 成功返回dValue,失败返回0 ******************************************************/ virtual double GetDouble(const char* key, const char* name) = 0; /**************************************************** *Function: 获取所有配置项 -- 此接口必须引用config.h *Intput: plist 配置项内容 nsize 缓冲区大小 *Output: plist 配置项内容 *Return: 返回获取到的配置项数量 *PS: 可以先传入NULL获取大小,保证缓冲区够大后再获取数据 ******************************************************/ virtual int GetList(TConfig* plist = 0, int nsize = 0) = 0; }; //导出接口 EXPORT_C int WINAPI IConfig_Load(IConfig* pcfg, const char* file = 0); EXPORT_C int WINAPI IConfig_Save(IConfig* pcfg, const char* file = 0); EXPORT_C int WINAPI IConfig_Parse(IConfig* pcfg, const char* pszcontent = 0); EXPORT_C int WINAPI IConfig_SetString(IConfig* pcfg, const char* key, const char* name, const char* lpValue); EXPORT_C int WINAPI IConfig_GetString(IConfig* pcfg, const char* key, const char* name, char* lpValue); EXPORT_C int WINAPI IConfig_SetInt(IConfig* pcfg, const char* key, const char* name, int iValue); EXPORT_C int WINAPI IConfig_GetInt(IConfig* pcfg, const char* key, const char* name); EXPORT_C int WINAPI IConfig_SetDouble(IConfig* pcfg, const char* key, const char* name, double dValue); EXPORT_C double WINAPI IConfig_GetDouble(IConfig* pcfg, const char* key, const char* name); EXPORT_C int WINAPI IConfig_GetList(IConfig* pcfg, TConfig* plist = 0); /**************************************************** *Function: 创建Iconfig实例 *Intput: NULL *Output: IConfig* 对象指针缓冲区 *Return: 成功返回0,失败返回错误码 ******************************************************/ EXPORT_C int WINAPI create_iconfig(IConfig** h); /**************************************************** *Function: 释放Iconfig实例 *Intput: NULL *Output: IConfig 对象指针 *Return: 成功返回0,失败返回错误码 ******************************************************/ EXPORT_C int WINAPI release_iconfig(IConfig* ph); #endif //防止重复包含头文件