[zhoulongyu]增加常见的数据类型接口
This commit is contained in:
parent
9e78b4e163
commit
91ae7dbc67
|
@ -16,6 +16,9 @@
|
||||||
#define IIPCCONFIG_H
|
#define IIPCCONFIG_H
|
||||||
#include "StatusCode.h"
|
#include "StatusCode.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string_view>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
enum class IpcConfigKey
|
enum class IpcConfigKey
|
||||||
{
|
{
|
||||||
TEST_NUM = 0,
|
TEST_NUM = 0,
|
||||||
|
@ -31,6 +34,27 @@ public:
|
||||||
virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
||||||
virtual const int GetInt(const IpcConfigKey &key) { return -1; }
|
virtual const int GetInt(const IpcConfigKey &key) { return -1; }
|
||||||
virtual void SetInt(const IpcConfigKey &key, const int &value) {}
|
virtual void SetInt(const IpcConfigKey &key, const int &value) {}
|
||||||
|
virtual const short GetShort(const IpcConfigKey &key) { return -1; }
|
||||||
|
virtual void SetShort(const IpcConfigKey &key, const short &value) {}
|
||||||
|
virtual const long GetLong(const IpcConfigKey &key) { return -1; }
|
||||||
|
virtual void SetLong(const IpcConfigKey &key, const long &value) {}
|
||||||
|
virtual const long long GetLongLong(const IpcConfigKey &key) { return -1; }
|
||||||
|
virtual void SetLongLong(const IpcConfigKey &key, const long long &value) {}
|
||||||
|
virtual const char GetChar(const IpcConfigKey &key) { return '\0'; }
|
||||||
|
virtual void SetChar(const IpcConfigKey &key, const char &value) {}
|
||||||
|
virtual const float GetFloat(const IpcConfigKey &key) { return -1.0; }
|
||||||
|
virtual void SetFloat(const IpcConfigKey &key, const float &value) {}
|
||||||
|
virtual const double GetDouble(const IpcConfigKey &key) { return -1.0; }
|
||||||
|
virtual void SetDouble(const IpcConfigKey &key, const double &value) {}
|
||||||
|
virtual const long double GetLongDouble(const IpcConfigKey &key) { return -1.0; }
|
||||||
|
virtual void SetLongDouble(const IpcConfigKey &key, const long double &value) {}
|
||||||
|
virtual const bool GetBool(const IpcConfigKey &key) { return true; }
|
||||||
|
virtual void SetBool(const IpcConfigKey &key, const bool &value) {}
|
||||||
|
virtual const std::string_view GetString(const IpcConfigKey &key) { return "undefine"; }
|
||||||
|
virtual void SetString(const IpcConfigKey &key, const std::string string) {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
bool CreateIpcConfig(void);
|
bool CreateIpcConfig(void);
|
||||||
#endif
|
#endif
|
|
@ -15,6 +15,7 @@
|
||||||
#include "IpcConfig.h"
|
#include "IpcConfig.h"
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
IpcConfig::IpcConfig()
|
IpcConfig::IpcConfig()
|
||||||
{
|
{
|
||||||
mCfgChanged = CONFIG_HAS_NOT_CHANGED;
|
mCfgChanged = CONFIG_HAS_NOT_CHANGED;
|
||||||
|
@ -73,6 +74,246 @@ void IpcConfig::SetInt(const IpcConfigKey &key, const int &value)
|
||||||
LogError("Can't find the key.\n");
|
LogError("Can't find the key.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const short IpcConfig::GetShort(const IpcConfigKey &key)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<short>>::iterator iter;
|
||||||
|
iter = mCfgMapShort.find(key);
|
||||||
|
if (iter != mCfgMapShort.end())
|
||||||
|
{
|
||||||
|
return iter->second;
|
||||||
|
}
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
constexpr short UNKNOWN_CONFIG = -1;
|
||||||
|
return UNKNOWN_CONFIG;
|
||||||
|
}
|
||||||
|
void IpcConfig::SetShort(const IpcConfigKey &key, const short &value)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<short>>::iterator iter;
|
||||||
|
iter = mCfgMapShort.find(key);
|
||||||
|
if (iter != mCfgMapShort.end())
|
||||||
|
{
|
||||||
|
iter->second.get() = value;
|
||||||
|
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const long IpcConfig::GetLong(const IpcConfigKey &key)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<long>>::iterator iter;
|
||||||
|
iter = mCfgMapLong.find(key);
|
||||||
|
if (iter != mCfgMaplong.end())
|
||||||
|
{
|
||||||
|
return iter->second;
|
||||||
|
}
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
constexpr long UNKNOWN_CONFIG = -1;
|
||||||
|
return UNKNOWN_CONFIG;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IpcConfig::SetLong(const IpcConfigKey &key, const long &value)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<long>>::iterator iter;
|
||||||
|
iter = mCfgMaLlong.find(key);
|
||||||
|
if (iter != mCfgMapLong.end())
|
||||||
|
{
|
||||||
|
iter->second.get() = value;
|
||||||
|
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const long long IpcConfig::GetLongLong(const IpcConfigKey &key)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<long long>>::iterator iter;
|
||||||
|
iter = mCfgMapLongLong.find(key);
|
||||||
|
if (iter != mCfgMapLongLong.end())
|
||||||
|
{
|
||||||
|
return iter->second;
|
||||||
|
}
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
constexpr long long UNKNOWN_CONFIG = -1;
|
||||||
|
return UNKNOWN_CONFIG;
|
||||||
|
}
|
||||||
|
void IpcConfig::SetLongLong(const IpcConfigKey &key, const long long &value)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<long long>>::iterator iter;
|
||||||
|
iter = mCfgMapLongLong.find(key);
|
||||||
|
if (iter != mCfgMapLongLong.end())
|
||||||
|
{
|
||||||
|
iter->second.get() = value;
|
||||||
|
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const char IpcConfig::GetChar(const IpcConfigKey &key)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<char>>::iterator iter;
|
||||||
|
iter = mCfgMapChar.find(key);
|
||||||
|
if (iter != mCfgMapChar.end())
|
||||||
|
{
|
||||||
|
return iter->second;
|
||||||
|
}
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
constexpr char UNKNOWN_CONFIG = '\0';
|
||||||
|
return UNKNOWN_CONFIG;
|
||||||
|
}
|
||||||
|
void IpcConfig::SetChar(const IpcConfigKey &key, const char &character)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<char>>::iterator iter;
|
||||||
|
iter = mCfgMapChar.find(key);
|
||||||
|
if (iter != mCfgMapChar.end())
|
||||||
|
{
|
||||||
|
iter->second.get() = character;
|
||||||
|
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const float IpcConfig::GetFloat(const IpcConfigKey &key)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<float>>::iterator iter;
|
||||||
|
iter = mCfgMapFloat.find(key);
|
||||||
|
if (iter != mCfgMapFloat.end())
|
||||||
|
{
|
||||||
|
return iter->second;
|
||||||
|
}
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
constexpr float UNKNOWN_CONFIG = -1.0;
|
||||||
|
return UNKNOWN_CONFIG;
|
||||||
|
}
|
||||||
|
void IpcConfig::SetFloat(const IpcConfigKey &key, const float &value)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<float>>::iterator iter;
|
||||||
|
iter = mCfgMapFloat.find(key);
|
||||||
|
if (iter != mCfgMapFloat.end())
|
||||||
|
{
|
||||||
|
iter->second.get() = value;
|
||||||
|
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const double IpcConfig::GetDouble(const IpcConfigKey &key)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<double>>::iterator iter;
|
||||||
|
iter = mCfgMapDouble.find(key);
|
||||||
|
if (iter != mCfgMapDouble.end())
|
||||||
|
{
|
||||||
|
return iter->second;
|
||||||
|
}
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
constexpr double UNKNOWN_CONFIG = -1.0;
|
||||||
|
return UNKNOWN_CONFIG;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IpcConfig::SetDouble(const IpcConfigKey &key, const double &value)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<double>>::iterator iter;
|
||||||
|
iter = mCfgMapDouble.find(key);
|
||||||
|
if (iter != mCfgMapDouble.end())
|
||||||
|
{
|
||||||
|
iter->second.get() = value;
|
||||||
|
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const long double IpcConfig::GetLongDouble(const IpcConfigKey &key)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<long double>>::iterator iter;
|
||||||
|
iter = mCfgMapLongDouble.find(key);
|
||||||
|
if (iter != mCfgMapLongDouble.end())
|
||||||
|
{
|
||||||
|
return iter->second;
|
||||||
|
}
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
constexpr long double UNKNOWN_CONFIG = -1.0;
|
||||||
|
return UNKNOWN_CONFIG;
|
||||||
|
}
|
||||||
|
void IpcConfig::SetLongDouble(const IpcConfigKey &key, const long double &value)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<long double>>::iterator iter;
|
||||||
|
iter = mCfgMapLongDouble.find(key);
|
||||||
|
if (iter != mCfgMapLongDouble.end())
|
||||||
|
{
|
||||||
|
iter->second.get() = value;
|
||||||
|
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const bool IpcConfig::GetBool(const IpcConfigKey &key)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<bool>>::iterator iter;
|
||||||
|
iter = mCfgMapBool.find(key);
|
||||||
|
if (iter != mCfgMapBool.end())
|
||||||
|
{
|
||||||
|
return iter->second;
|
||||||
|
}
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
constexpr bool UNKNOWN_CONFIG = false;
|
||||||
|
return UNKNOWN_CONFIG;
|
||||||
|
}
|
||||||
|
void IpcConfig::SetBool(const IpcConfigKey &key, const bool &value)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<bool>>::iterator iter;
|
||||||
|
iter = mCfgMapBool.find(key);
|
||||||
|
if (iter != mCfgMapBool.end())
|
||||||
|
{
|
||||||
|
iter->second.get() = value;
|
||||||
|
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const std::string_view IpcConfig::GetString(const IpcConfigKey &key)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<std::string>>::iterator iter;
|
||||||
|
iter = mCfgMapString.find(key);
|
||||||
|
if (iter != mCfgMapString.end())
|
||||||
|
{
|
||||||
|
std::string s = iter->second;
|
||||||
|
std::string_view sv(s);
|
||||||
|
return sv;
|
||||||
|
}
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
constexpr std::string_view UNKNOWN_CONFIG = "undefine";
|
||||||
|
return UNKNOWN_CONFIG;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IpcConfig::SetString(const IpcConfigKey &key, const std::string string)
|
||||||
|
{
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<std::string>>::iterator iter;
|
||||||
|
iter = mCfgMapString.find(key);
|
||||||
|
if (iter != mCfgMapString.end())
|
||||||
|
{
|
||||||
|
iter->second.get() = string;
|
||||||
|
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogError("Can't find the key.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void IpcConfig::ReadAllConfigParameters(void)
|
void IpcConfig::ReadAllConfigParameters(void)
|
||||||
{
|
{
|
||||||
StatusCode code = ConfigGetInt(mCfg, "test_num", &(mAllData.testNum));
|
StatusCode code = ConfigGetInt(mCfg, "test_num", &(mAllData.testNum));
|
||||||
|
|
|
@ -40,6 +40,25 @@ public:
|
||||||
const StatusCode UnInit(void) override;
|
const StatusCode UnInit(void) override;
|
||||||
const int GetInt(const IpcConfigKey &key) override;
|
const int GetInt(const IpcConfigKey &key) override;
|
||||||
void SetInt(const IpcConfigKey &key, const int &value) override;
|
void SetInt(const IpcConfigKey &key, const int &value) override;
|
||||||
|
const short GetShort(const IpcConfigKey &key) override;
|
||||||
|
void SetShort(const IpcConfigKey &key, const short &value) override;
|
||||||
|
const long GetLong(const IpcConfigKey &key) override;
|
||||||
|
void SetLong(const IpcConfigKey &key, const long &value) override;
|
||||||
|
const long long GetLongLong(const IpcConfigKey &key) override;
|
||||||
|
void SetLongLong(const IpcConfigKey &key, const long long &value) override;
|
||||||
|
const char GetChar(const IpcConfigKey &key) override;
|
||||||
|
void SetChar(const IpcConfigKey &key, const char &character) override;
|
||||||
|
const float GetFloat(const IpcConfigKey &key) override;
|
||||||
|
void SetFloat(const IpcConfigKey &key, const float &value) override;
|
||||||
|
const double GetDouble(const IpcConfigKey &key) override;
|
||||||
|
void SetDouble(const IpcConfigKey &key, const double &value) override;
|
||||||
|
const long double GetLongDouble(const IpcConfigKey &key) override;
|
||||||
|
void SetLongDouble(const IpcConfigKey &key, const long double &value) override;
|
||||||
|
const bool GetBool(const IpcConfigKey &key) override;
|
||||||
|
void SetBool(const IpcConfigKey &key, const bool &value) override;
|
||||||
|
const std::string_view GetString(const IpcConfigKey &key) override;
|
||||||
|
void SetString(const IpcConfigKey &key, const std::string string) override;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ReadAllConfigParameters(void);
|
void ReadAllConfigParameters(void);
|
||||||
|
@ -49,7 +68,14 @@ private:
|
||||||
VConfig *mCfg;
|
VConfig *mCfg;
|
||||||
Config_s mAllData;
|
Config_s mAllData;
|
||||||
std::map<IpcConfigKey, std::reference_wrapper<int>> mCfgMapInt;
|
std::map<IpcConfigKey, std::reference_wrapper<int>> mCfgMapInt;
|
||||||
std::map<IpcConfigKey, std::reference_wrapper<long int>> mCfgMapUInt;
|
std::map<IpcConfigKey, std::reference_wrapper<short>> mCfgMapShort;
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<long>> mCfgMapLong;
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<long long>> mCfgMapLongLong;
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<char>> mCfgMapChar;
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<float>> mCfgMapFloat;
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<double>> mCfgMapDouble;
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<long double>> mCfgMapLongDouble;
|
||||||
|
std::map<IpcConfigKey, std::reference_wrapper<bool>> mCfgMapBool;
|
||||||
std::map<IpcConfigKey, std::reference_wrapper<std::string>> mCfgMapString;
|
std::map<IpcConfigKey, std::reference_wrapper<std::string>> mCfgMapString;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue
Block a user