34class SIMO_PUBLIC ParameterTrie {
35 static constexpr std::pair<std::string_view, std::string_view>
36 split_string_view(
const std::string_view name) {
37 const auto next_dot_pos = name.find(PARAMETER_NODE_SEPARATOR);
38 if (next_dot_pos == std::string_view::npos) {
39 return std::make_pair(name, std::string_view{});
41 return std::make_pair(name.substr(0, next_dot_pos),
42 name.substr(next_dot_pos + 1));
46 ParameterTrie() =
default;
48 ParameterTrie(
const ParameterTrie& other) { *
this = other; }
50 ParameterTrie& operator=(
const ParameterTrie& other) {
52 value = std::unique_ptr(other.value->clone());
54 for (
const auto& [fst, snd] : other.children) {
60 template <
typename T,
typename... Args>
63 return add_generic<T>(name,
true, std::forward<Args>(args)...);
69 return add_generic<T>(name,
false);
73 Parameter* find(
const std::string_view name)
const {
77 const auto [child_name, rest_of_name] = split_string_view(name);
78 if (!children.contains(std::string(child_name))) {
81 return children.at(std::string(child_name)).find(rest_of_name);
86 auto*
const res = find(name);
89 : boost::typeindex::runtime_cast<ParameterTyped<T>*>(res);
92 [[nodiscard]]
const ParameterTrie* get_subtrie(
93 const std::string_view name)
const {
97 const auto [child_name, rest_of_name] = split_string_view(name);
98 if (!children.contains(std::string(child_name))) {
101 return children.at(std::string(child_name)).get_subtrie(rest_of_name);
106 template <
typename Function>
108 bool all(Function f)
const {
109 if (value !=
nullptr && value->has_value() && !f(*value)) {
112 for (
const auto& snd : children | std::views::values) {
120 std::unique_ptr<Parameter> value;
123 template <
typename T,
typename... Args>
129 value = std::unique_ptr<Parameter>(ptr);
130 value->has_value(has_value);
133 const auto [child_name, rest_of_name] = split_string_view(name);
134 return children[std::string(child_name)].add_generic<T>(
135 rest_of_name, has_value, std::forward<Args>(args)...);
139 std::unordered_map<std::string, ParameterTrie> children;