0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd::conf: Add allocated string get() overloads.

This commit is contained in:
Jason Volk 2019-03-11 11:13:14 -07:00
parent 8353d0a7e9
commit 1fa5ebc415
2 changed files with 28 additions and 0 deletions

View file

@ -61,6 +61,7 @@ namespace ircd::conf
bool exists(const string_view &key);
bool persists(const string_view &key);
string_view get(const string_view &key, const mutable_buffer &out);
std::string get(const string_view &key);
bool set(const string_view &key, const string_view &value);
bool set(std::nothrow_t, const string_view &key, const string_view &value);
bool reset(std::nothrow_t, const string_view &key);
@ -88,6 +89,7 @@ struct ircd::conf::item<void>
public:
virtual size_t size() const = 0;
string_view get(const mutable_buffer &) const;
std::string get() const;
bool set(const string_view &);
item(const json::members &, conf::set_cb);

View file

@ -109,6 +109,21 @@ catch(const std::out_of_range &e)
};
}
std::string
ircd::conf::get(const string_view &key)
try
{
const auto &item(*items.at(key));
return item.get();
}
catch(const std::out_of_range &e)
{
throw not_found
{
"Conf item '%s' is not available", key
};
}
ircd::string_view
ircd::conf::get(const string_view &key,
const mutable_buffer &out)
@ -226,6 +241,17 @@ ircd::conf::item<void>::set(const string_view &val)
return ret;
}
std::string
ircd::conf::item<void>::get()
const
{
return ircd::string(size(), [this]
(const mutable_buffer &buf)
{
return get(buf);
});
}
ircd::string_view
ircd::conf::item<void>::get(const mutable_buffer &buf)
const