Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: overload 'get' in order to enable std::string as supported parameters. #238

Merged
merged 3 commits into from
Jul 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/util/registry/registry_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
}
return false;
}
[[nodiscard]] inline bool get(const Value& src, std::string& dst)
{
if (const auto* const str = src.get_string_if())
{
dst = std::string{reinterpret_cast<const char*>(str->value.data()), str->value.size()};
return true;
}
return false;
}
} // namespace detail

/// Convert the value stored in source to the same type and dimensionality as destination; update destination in-place.
Expand Down Expand Up @@ -197,6 +206,16 @@ inline void set(Value& dst, const std::string_view string)
str.value.push_back(static_cast<std::uint8_t>(string[i]));
}
}
/// Assigns string to the value, truncating if necessary.
inline void set(Value& dst, const std::string& string)
{
set(dst, std::string_view(string));
}
/// Assigns string to the value, truncating if necessary.
inline void set(Value& dst, const char* const string)
{
set(dst, std::string_view(string));
}
/// Assigns numerical arrays/vectors of various arithmetic types to the value.
/// E.g., passing an std::array<float, 7> here will switch the value to real32[7].
/// The existing contents of the value is discarded.
Expand Down
Loading