diff --git a/src/sled/config.cc b/src/sled/config.cc index 74a98c3..12c43f3 100644 --- a/src/sled/config.cc +++ b/src/sled/config.cc @@ -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) { @@ -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 { diff --git a/src/sled/config.h b/src/sled/config.h index 853912e..5322665 100644 --- a/src/sled/config.h +++ b/src/sled/config.h @@ -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 @@ -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;