Loading src/sled/config.cc +15 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,13 @@ Config::Config(sled::string_view name, sled::string_view path) : config_name_(na config_paths_.emplace_back(sled::to_string(path)); } std::string Config::ToString() const { toml::value root = toml_; return toml::format(root); } void Config::AddConfigFullPath(sled::string_view path) { Loading Loading @@ -75,6 +82,14 @@ Config::IsSet(sled::string_view key) const return GetNode(key, value); } bool Config::IsArray(sled::string_view key) const { toml::value value; if (!GetNode(key, value)) { return false; } return value.is_array(); } bool Config::GetBoolOr(sled::string_view key, const bool &def) const { Loading src/sled/config.h +4 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ public: Config &operator=(const Config &lhs) = delete; Config &operator=(Config &&rhs) noexcept = delete; sled::string ToString() const; /** * case 1 * - fullpath = /path/to/config.toml Loading @@ -36,6 +38,8 @@ public: bool ReadInConfig(); bool IsSet(sled::string_view key) const; bool IsArray(sled::string_view key) const; bool GetBoolOr(sled::string_view key, const bool &def = false) const; int GetIntOr(sled::string_view key, const int &def = 0) const; double GetDoubleOr(sled::string_view key, const double &def = 0.0) const; Loading Loading
src/sled/config.cc +15 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,13 @@ Config::Config(sled::string_view name, sled::string_view path) : config_name_(na config_paths_.emplace_back(sled::to_string(path)); } std::string Config::ToString() const { toml::value root = toml_; return toml::format(root); } void Config::AddConfigFullPath(sled::string_view path) { Loading Loading @@ -75,6 +82,14 @@ Config::IsSet(sled::string_view key) const return GetNode(key, value); } bool Config::IsArray(sled::string_view key) const { toml::value value; if (!GetNode(key, value)) { return false; } return value.is_array(); } bool Config::GetBoolOr(sled::string_view key, const bool &def) const { Loading
src/sled/config.h +4 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ public: Config &operator=(const Config &lhs) = delete; Config &operator=(Config &&rhs) noexcept = delete; sled::string ToString() const; /** * case 1 * - fullpath = /path/to/config.toml Loading @@ -36,6 +38,8 @@ public: bool ReadInConfig(); bool IsSet(sled::string_view key) const; bool IsArray(sled::string_view key) const; bool GetBoolOr(sled::string_view key, const bool &def = false) const; int GetIntOr(sled::string_view key, const int &def = 0) const; double GetDoubleOr(sled::string_view key, const double &def = 0.0) const; Loading