C++客户端开发接口库 V5.1.8.15
连接信创集成中间件服务程序的二次开发接口
载入中...
搜索中...
未找到
IniHelper.h
1#pragma once
2
3#ifdef QT_CORE_LIB
4#include <QtCore>
5#endif
6#include <string>
7#include <vector>
8#include <map>
9#include "mdwclient_global.h"
10
12struct KeyNode
13{
15 std::string section;
17 std::string key;
19 std::string value;
21 std::string memo;
23 KeyNode(const std::string& ssection, const std::string& skey, const std::string& svalue, const std::string& smemo = "")
24 {
25 section = ssection;
26 key = skey;
27 value = svalue;
28 memo = smemo;
29 }
30};
31
33typedef std::vector<KeyNode> KeyNodes;
34
37{
39 std::string key;
41 std::string value;
43 std::string memo;
45 SectionValue() = default;
47 SectionValue(const std::string& skey, const std::string& svalue, const std::string& smemo = "")
48 {
49 key = skey;
50 value = svalue;
51 memo = smemo;
52 }
53};
54
56typedef std::map<std::string, SectionValue> SectionValues;
57
59typedef std::map<std::string, SectionValues> SectionNodes;
60
62class MDWC_COMPLILE CIniHelper
63{
64private:
66 SectionNodes m_Nodes;
68 bool m_bSaveGBKCode;
70 std::vector<std::string> m_vSectionNames;
72 std::string m_sLastError;
73private:
81 bool isGBKBuffer(const uint8_t* data, size_t len);
83 int GetSize() { return (int)m_Nodes.size(); }
84public:
86 CIniHelper() { m_bSaveGBKCode = false; }
88 ~CIniHelper() { m_Nodes.clear(); m_vSectionNames.clear(); }
95 bool ReadFile(const std::string& path);
102 bool WriteFile(const std::string& path);
104 void SetGBKCode(bool bIsGBKCode) { m_bSaveGBKCode = bIsGBKCode; }
106 std::vector<std::string> GetSectionNames() { return m_vSectionNames; }
108 std::string GetValue(const std::string& section, const std::string& key, const std::string& sDefValue = "");
110 int GetIntValue(const std::string& section, const std::string& key, int iDefValue = 0);
112 float GetFloatValue(const std::string& section, const std::string& key, float fDefValue = 0);
114 bool GetBoolValue(const std::string& section, const std::string& key, bool fDefValue = false);
115
117 bool SetValue(const std::string& section, const std::string& key, const std::string& value);
119 bool SetIntValue(const std::string& section, const std::string& key, int iValue);
121 bool SetFloatValue(const std::string& section, const std::string& key, float fValue);
123 bool SetBoolValue(const std::string& section, const std::string& key, bool bValue);
125 bool DeleteKey(const std::string& section, const std::string& key);
127 bool DeleteSection(const std::string& section);
129 void Clear() { m_Nodes.clear(); m_vSectionNames.clear(); }
131 bool KeyExist(const std::string& section, const std::string& key);
133 bool SectionExist(const std::string& section);
135 SectionValues GetSectionValues(const std::string& section);
137 SectionNodes GetAllSectionValues() { return m_Nodes; }
138#ifdef QT_CORE_LIB
140 QString GetLastError() { return QString::fromStdString(m_sLastError); }
142 QString GetUSValue(const std::string& section, const std::string& key, const std::string& sDefValue = "");
144 int SetUSValue(const std::string& section, const std::string& key, const QString& value);
145#else
147 std::string GetLastError() { return m_sLastError; }
148#endif
149};
std::string GetLastError()
定义 IniHelper.h:147
~CIniHelper()
定义 IniHelper.h:88
CIniHelper()
定义 IniHelper.h:86
std::vector< std::string > GetSectionNames()
定义 IniHelper.h:106
SectionNodes GetAllSectionValues()
定义 IniHelper.h:137
void Clear()
定义 IniHelper.h:129
void SetGBKCode(bool bIsGBKCode)
定义 IniHelper.h:104
std::string value
定义 IniHelper.h:19
std::string key
定义 IniHelper.h:17
KeyNode(const std::string &ssection, const std::string &skey, const std::string &svalue, const std::string &smemo="")
定义 IniHelper.h:23
std::string section
定义 IniHelper.h:15
std::string memo
定义 IniHelper.h:21
std::string memo
定义 IniHelper.h:43
std::string value
定义 IniHelper.h:41
SectionValue()=default
SectionValue(const std::string &skey, const std::string &svalue, const std::string &smemo="")
定义 IniHelper.h:47
std::string key
定义 IniHelper.h:39