[zhoulongyu]: 完善配置库的Int数据类型

This commit is contained in:
jas 2023-12-12 15:15:39 +08:00
parent d44154773f
commit 730c38b2c1
2 changed files with 16 additions and 12 deletions

View File

@ -21,12 +21,14 @@
IpcConfig::IpcConfig() IpcConfig::IpcConfig()
{ {
mCfgChanged = CONFIG_HAS_NOT_CHANGED; mCfgChanged = CONFIG_HAS_NOT_CHANGED;
mCfgMapInt.insert(std::make_pair<IpcConfigKey, std::reference_wrapper<int>>(
IpcConfigKey::TEST_NUM, std::reference_wrapper<int>(mAllData.testNum)));
std::map<std::string, std::reference_wrapper<CHAR_STRING>> innerMap; std::map<std::string, std::reference_wrapper<int>> innerMapInt;
innerMap.insert(std::make_pair("test_string", std::reference_wrapper<CHAR_STRING>(mAllData.testString))); innerMapInt.insert(std::make_pair("test_num", std::reference_wrapper<int>(mAllData.testNum)));
mCfgMapString.insert(std::make_pair(IpcConfigKey::TEST_STRING, innerMap)); mCfgMapInt.insert(std::make_pair(IpcConfigKey::TEST_NUM, innerMapInt));
std::map<std::string, std::reference_wrapper<CHAR_STRING>> innerMapString;
innerMapString.insert(std::make_pair("test_string", std::reference_wrapper<CHAR_STRING>(mAllData.testString)));
mCfgMapString.insert(std::make_pair(IpcConfigKey::TEST_STRING, innerMapString));
} }
const StatusCode IpcConfig::Init(void) const StatusCode IpcConfig::Init(void)
{ {
@ -52,10 +54,10 @@ const StatusCode IpcConfig::ConfigFileSave(void) { return ConfigSaveFile(mCfg);
const int IpcConfig::GetInt(const IpcConfigKey &key) const int IpcConfig::GetInt(const IpcConfigKey &key)
{ {
std::map<IpcConfigKey, std::reference_wrapper<int>>::iterator iter; std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<int>>>::iterator iter;
iter = mCfgMapInt.find(key); iter = mCfgMapInt.find(key);
if (iter != mCfgMapInt.end()) { if (iter != mCfgMapInt.end() && CHECK_MAP(iter->second)) {
return iter->second; return iter->second.begin()->second;
} }
LogError("Can't find the key.\n"); LogError("Can't find the key.\n");
constexpr int UNKNOWN_CONFIG = -1; constexpr int UNKNOWN_CONFIG = -1;
@ -63,10 +65,12 @@ const int IpcConfig::GetInt(const IpcConfigKey &key)
} }
void IpcConfig::SetInt(const IpcConfigKey &key, const int &value) void IpcConfig::SetInt(const IpcConfigKey &key, const int &value)
{ {
std::map<IpcConfigKey, std::reference_wrapper<int>>::iterator iter; std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<int>>>::iterator iter;
iter = mCfgMapInt.find(key); iter = mCfgMapInt.find(key);
if (iter != mCfgMapInt.end()) { if (iter != mCfgMapInt.end() && CHECK_MAP(iter->second)) {
iter->second.get() = value; iter->second.begin()->second.get() = value;
const char *name = iter->second.begin()->first.c_str(); // const std::strinbg --> const char *
ConfigSetInt(mCfg, name, iter->second.begin()->second);
mCfgChanged = CONFIG_HAS_CHANGED; mCfgChanged = CONFIG_HAS_CHANGED;
} }
else { else {

View File

@ -70,7 +70,7 @@ private:
bool mCfgChanged; bool mCfgChanged;
VConfig *mCfg; VConfig *mCfg;
Config_s mAllData; Config_s mAllData;
std::map<IpcConfigKey, std::reference_wrapper<int>> mCfgMapInt; std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<int>>> mCfgMapInt;
std::map<IpcConfigKey, std::reference_wrapper<short>> mCfgMapShort; std::map<IpcConfigKey, std::reference_wrapper<short>> mCfgMapShort;
std::map<IpcConfigKey, std::reference_wrapper<long>> mCfgMapLong; std::map<IpcConfigKey, std::reference_wrapper<long>> mCfgMapLong;
std::map<IpcConfigKey, std::reference_wrapper<long long>> mCfgMapLongLong; std::map<IpcConfigKey, std::reference_wrapper<long long>> mCfgMapLongLong;