From 422206794f3e2d60c848f8b75b517555e1c8bd9e Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 25 May 2018 20:45:30 -0700 Subject: [PATCH] ircd::conf: Add conf::exists(key); minor cleanup. --- include/ircd/conf.h | 1 + ircd/conf.cc | 38 ++++++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/include/ircd/conf.h b/include/ircd/conf.h index 68c07a267..3a227704e 100644 --- a/include/ircd/conf.h +++ b/include/ircd/conf.h @@ -36,6 +36,7 @@ namespace ircd::conf extern const std::string &config; //TODO: X extern std::map *> 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); diff --git a/ircd/conf.cc b/ircd/conf.cc index 53e9e2f29..15100f4fa 100644 --- a/ircd/conf.cc +++ b/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 //