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