Skip to content

Commit

Permalink
Merge pull request #238 from 107-systems/fix-no-string-support
Browse files Browse the repository at this point in the history
Fix: overload 'get' in order to enable std::string as supported parameters.
  • Loading branch information
aentinger authored Jul 6, 2023
2 parents 4d4e4bf + d69d9a6 commit 53095a0
Showing 1 changed file with 19 additions and 0 deletions.
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

0 comments on commit 53095a0

Please sign in to comment.