0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 08:12:37 +01:00

ircd::conf: Add conf::exists(key); minor cleanup.

This commit is contained in:
Jason Volk 2018-05-25 20:45:30 -07:00
parent 42af033421
commit 422206794f
2 changed files with 23 additions and 16 deletions

View file

@ -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);

View file

@ -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
//