mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd::conf: Add conf::exists(key); minor cleanup.
This commit is contained in:
parent
42af033421
commit
422206794f
2 changed files with 23 additions and 16 deletions
|
@ -36,6 +36,7 @@ namespace ircd::conf
|
|||
extern const std::string &config; //TODO: X
|
||||
extern std::map<string_view, item<> *> items;
|
||||
|
||||
bool exists(const string_view &key);
|
||||
string_view get(const string_view &key, const mutable_buffer &out);
|
||||
bool set(const string_view &key, const string_view &value);
|
||||
bool set(std::nothrow_t, const string_view &key, const string_view &value);
|
||||
|
|
38
ircd/conf.cc
38
ircd/conf.cc
|
@ -27,22 +27,6 @@ ircd::conf::init(const string_view &filename)
|
|||
_config = read_json_file(filename);
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::conf::get(const string_view &key,
|
||||
const mutable_buffer &out)
|
||||
try
|
||||
{
|
||||
const auto &item(*items.at(key));
|
||||
return item.get(out);
|
||||
}
|
||||
catch(const std::out_of_range &e)
|
||||
{
|
||||
throw not_found
|
||||
{
|
||||
"Conf item '%s' is not available", key
|
||||
};
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::conf::set(std::nothrow_t,
|
||||
const string_view &key,
|
||||
|
@ -84,6 +68,28 @@ catch(const std::out_of_range &e)
|
|||
};
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::conf::get(const string_view &key,
|
||||
const mutable_buffer &out)
|
||||
try
|
||||
{
|
||||
const auto &item(*items.at(key));
|
||||
return item.get(out);
|
||||
}
|
||||
catch(const std::out_of_range &e)
|
||||
{
|
||||
throw not_found
|
||||
{
|
||||
"Conf item '%s' is not available", key
|
||||
};
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::conf::exists(const string_view &key)
|
||||
{
|
||||
return items.count(key);
|
||||
}
|
||||
|
||||
//
|
||||
// item
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue