Commit 1d99dc5e authored by Dominik Charousset's avatar Dominik Charousset

Use string_view for lookups in config_option_set

parent f1681080
......@@ -105,7 +105,7 @@ public:
/// Sets a config by using its INI name `config_name` to `config_value`.
template <class T>
actor_system_config& set(const char* name, T&& value) {
actor_system_config& set(string_view name, T&& value) {
return set_impl(name, config_value{std::forward<T>(value)});
}
......@@ -403,7 +403,7 @@ private:
&make_type_erased_value<T>);
}
actor_system_config& set_impl(const char* name, config_value value);
actor_system_config& set_impl(string_view name, config_value value);
static std::string render_sec(uint8_t, atom_value, const message&);
......
......@@ -28,6 +28,7 @@
#include "caf/fwd.hpp"
#include "caf/make_config_option.hpp"
#include "caf/pec.hpp"
#include "caf/string_view.hpp"
namespace caf {
......@@ -69,18 +70,18 @@ public:
/// `<prefix>#<category>.<long-name>`. Users can omit `<prefix>`
/// for options that have an empty prefix and `<category>`
/// if the category is "global".
option_pointer cli_long_name_lookup(const std::string& name) const;
option_pointer cli_long_name_lookup(string_view name) const;
/// Returns the first `config_option` that matches the CLI short option name.
option_pointer cli_short_name_lookup(char short_name) const;
/// Returns the first `config_option` that matches category and long name.
option_pointer qualified_name_lookup(const std::string& category,
const std::string& long_name) const;
option_pointer qualified_name_lookup(string_view category,
string_view long_name) const;
/// Returns the first `config_option` that matches the qualified name.
/// @param name Config option name formatted as `<category>.<long-name>`.
option_pointer qualified_name_lookup(const std::string& name) const;
option_pointer qualified_name_lookup(string_view name) const;
/// Returns the number of stored config options.
inline size_t size() const noexcept {
......
......@@ -387,7 +387,7 @@ actor_system_config::add_error_category(atom_value x, error_renderer y) {
return *this;
}
actor_system_config& actor_system_config::set_impl(const char* name,
actor_system_config& actor_system_config::set_impl(string_view name,
config_value value) {
auto opt = custom_options_.qualified_name_lookup(name);
if (opt != nullptr && opt->check(value) == none) {
......
......@@ -224,12 +224,12 @@ config_option_set::parse(config_map& config,
}
config_option_set::option_pointer
config_option_set::cli_long_name_lookup(const string& name) const {
config_option_set::cli_long_name_lookup(string_view name) const {
// We accept "caf#" prefixes for backward compatibility, but ignore them.
size_t offset = name.compare(0, 4, "caf#") != 0 ? 0u : 4u;
// Extract category and long name.
string category;
string long_name;
string_view category;
string_view long_name;
auto sep = name.find('.', offset);
if (sep == string::npos) {
category = "global";
......@@ -255,15 +255,15 @@ config_option_set::cli_short_name_lookup(char short_name) const {
}
config_option_set::option_pointer
config_option_set::qualified_name_lookup(const std::string& category,
const std::string& long_name) const {
config_option_set::qualified_name_lookup(string_view category,
string_view long_name) const {
return detail::ptr_find_if(opts_, [&](const config_option& opt) {
return opt.category() == category && opt.long_name() == long_name;
});
}
config_option_set::option_pointer
config_option_set::qualified_name_lookup(const std::string& name) const {
config_option_set::qualified_name_lookup(string_view name) const {
auto sep = name.find('.');
if (sep == string::npos)
return nullptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment