Commit 4f8b6241 authored by tqcq's avatar tqcq
Browse files

feat update

parent 8d76becf
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -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
{
+4 −0
Original line number Diff line number Diff line
@@ -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;