将主要介绍AcGeConfig
类的使用
点击查看`AcGeConfig`类代码
#pragma once
class KY_API AcGeConfig
{
public:
AcGeConfig(void);
~AcGeConfig(void);
public:
bool writeConfigToFile(CString filePath);
bool readConfigFromFile(CString filePath);
public://read
bool read(CString tagString,int &intValue);
bool read(CString tagString,bool &boolValue);
bool read(CString tagString,float &floatValue);
bool read(CString tagString,double &doubleValue);
bool read(CString tagString,CString &stringValue);
bool read(CString tagString,CStringArray &stringValue);
bool read(CString tagString,std::vector<int> &intValue);
bool read(CString tagString,std::vector<bool> &boolValue);
bool read(CString tagString,std::vector<float> &floatValue);
bool read(CString tagString,std::vector<double> &doubleValue);
bool read(CString tagString,std::vector<CString> &stringValue);
bool read(CString tagString,COLORREF &colorValue);
bool read(CString tagString,ColorPoint &sValue);
public://write
void write(CString tagString,int intValue);
void write(CString tagString,bool boolValue);
void write(CString tagString,float floatValue);
void write(CString tagString,double doubleValue);
void write(CString tagString,CString stringValue);
void write(CString tagString,CStringArray &stringValue);
void write(CString tagString,std::vector<int> &intValue);
void write(CString tagString,std::vector<bool> &boolValue);
void write(CString tagString,std::vector<float> &floatValue);
void write(CString tagString,std::vector<double> &doubleValue);
void write(CString tagString,std::vector<CString> &stringValue);
void write(CString tagString,COLORREF colorValue);
void write(CString tagString,ColorPoint sValue);
private:
CString getValueItem(std::vector<CString>&valueList);
void setValueListValue(CString&text,std::vector<CString>&valueList);
void dumpInfo(std::vector<CString>&tagList, std::vector<CString>&valueList);
void createBy(std::vector<CString>&tagList, std::vector<CString>&valueList);
private:
std::map<CString,std::vector<CString>>m_configList;
};
重点内容
bool writeConfigToFile(CString filePath); // 设置写文件路径
bool readConfigFromFile(CString filePath); // 设置读文件路径
// 类型需要对应,k-v
bool read(CString tagString,int &intValue);
void write(CString tagString,int intValue);
使用示例
#define CONFIGFILEPATH "C:\\Users\\Rick\\Downloads\\wecad_sdk_9.23\\3d_cad_2\\dev_apps\\config\\app_kunlunabc.ini"
......
{
CString value = "123Test";
writeConfig(CONFIGFILEPATH, "configTest", value);
}
......
void writeConfig(CString filePath, CString tagString, CString stringValue)
{
{
AcGeConfig* config = new AcGeConfig;
CString a = "123123";
config->write(tagString, a);// 先设置文件内容,再写文件,注意方法调用顺序
config->writeConfigToFile(filePath);
delete(config);
config = nullptr;
}
{
AcGeConfig* config = new AcGeConfig;
config->readConfigFromFile(filePath);
CString IVal;
config->read(tagString, IVal);
AfxMessageBox(IVal);
delete(config);
config = nullptr;
}
}
标签:AcGeConfig,std,read,读写,CString,bool,tagString,config,void
From: https://www.cnblogs.com/SpringBreath/p/17006174.html