#ifndef __UT_JSON_CONFIG_HPP__ #define __UT_JSON_CONFIG_HPP__ #include #define UT_JSON_CONF_KEY_PARAMETER "Parameter" namespace unitree { namespace common { class JsonConfig { public: JsonConfig(); virtual ~JsonConfig(); JsonConfig(const std::string& configFileName); virtual void Parse(const std::string& configFileName); //top-level field bool Has(const std::string& name) const; //top-level field const Any& Get(const std::string& name) const; //top-level field template const T& Get(const std::string& name) const { return AnyCast(Get(name)); } //top-level field template T GetNumber(const std::string& name) const { return AnyNumberCast(Get(name)); } //top-level field template T Get(const std::string& name, const T& defValue) const { const Any& a = Get(name); if (a.Empty()) { return defValue; } else { return AnyCast(a); } } //top-level field template T GetNumber(const std::string& name, const T& defValue) const { const Any& a = Get(name); if (a.Empty()) { return defValue; } else { return AnyNumberCast(a); } } //JsonMap field bool Has(const JsonMap& jsonMap, const std::string& name) const; //JsonMap field const Any& Get(const JsonMap& jsonMap, const std::string& name) const; //JsonMap field template const T& Get(const JsonMap& jsonMap, const std::string& name) const { return AnyCast(Get(jsonMap, name)); } //JsonMap field template T GetNumber(const JsonMap& jsonMap, const std::string& name) const { return AnyNumberCast(Get(jsonMap, name)); } //JsonMap field template T Get(const JsonMap& jsonMap, const std::string& name, const T& defValue) const { const Any& a = Get(jsonMap, name); if (a.Empty()) { return defValue; } else { return AnyCast(a); } } //JsonMap field template T GetNumber(const JsonMap& jsonMap, const std::string& name, const T& defValue) const { const Any& a = Get(jsonMap, name); if (a.Empty()) { return defValue; } else { return AnyNumberCast(a); } } //top-level field const Any& GetGlobalParameter(const std::string& name) const; //top-level field: Parameter bool HasParameter(const std::string& name) const; //top-level field: Parameter const JsonMap& GetParameter() const; //get field/value from top-level field: Parameter const Any& GetParameter(const std::string& name) const; //get field/value from top-level field: Parameter template const T& GetParameter(const std::string& name) const { return AnyCast(GetParameter(name)); } //get field/value from top-level field: Parameter template T GetNumberParameter(const std::string& name) const { return AnyNumberCast(GetParameter(name)); } //get field/value from top-level field: Parameter template T GetParameter(const std::string& name, const T& defValue) const { const Any& a = GetParameter(name); if (a.Empty()) { return defValue; } else { return AnyCast(a); } } template T GetNumberParameter(const std::string& name, const T& defValue) const { const Any& a = GetParameter(name); if (a.Empty()) { return defValue; } else { return AnyNumberCast(a); } } protected: JsonMap mParameter; Any mContent; }; typedef std::shared_ptr JsonConfigPtr; } } #endif//__UT_JSON_CONFIG_HPP__