29#include <commons/fixed_string.hpp>
62template <comms::FixedString Id,
typename Derived>
70 template <
typename Self = Derived>
72 inline static const bool values_t_seeded_ = [] {
74 for (
constexpr auto ptrs = values_metadata_pointers<typename Self::values_t>();
75 const auto* p : ptrs) {
89 [[nodiscard]]
static const Derived&
value() noexcept {
90 static_assert(std::same_as<typename E::owner_t, Derived>,
91 "Entry type's owner must match this kind");
92 (void)values_t_seeded_<Derived>;
102 (void)values_t_seeded_<Derived>;
104 std::views::transform(
109 [[nodiscard]]
static Derived
of(std::string_view
code) {
110 (void)values_t_seeded_<Derived>;
113 std::string msg =
"tagval: unknown code '";
115 msg +=
"' for kind '";
116 msg.append(Id.view());
124 [[nodiscard]]
static std::expected<Derived, ParseError>
try_of(std::string_view
code)
noexcept {
125 (void)values_t_seeded_<Derived>;
CRTP HandleBase used by ClosedEnded and OpenEnded.
Runtime list of metadata pointers for a single OpenEnded kind.
Definition openended_registry.hpp:27
static void add(const TagValMetadata *m)
Register a pinned metadata pointer.
Definition openended_registry.hpp:31
static std::span< const TagValMetadata *const > all() noexcept
Definition openended_registry.hpp:42
static const TagValMetadata * find(std::string_view code) noexcept
Definition openended_registry.hpp:46
CRTP base for tag-value kinds whose values are partly compile-time (Derived::values_t) and partly con...
Definition open_ended.hpp:63
static std::expected< Derived, ParseError > try_of(std::string_view code) noexcept
Look up a value by code. Returns ParseError on miss.
Definition open_ended.hpp:124
static auto all_values() noexcept
Range of TagValMetadata covering compile-time values_t entries (seeded lazily on first call) plus ext...
Definition open_ended.hpp:101
static Derived of(std::string_view code)
Look up a value by code. Throws UnknownCodeError on miss.
Definition open_ended.hpp:109
static const Derived & value() noexcept
Canonical handle for an entry.
Definition open_ended.hpp:89
Thrown by of() when a code is not present.
Definition error.hpp:19
CRTP handle.
Definition base.hpp:49
static Derived make_handle(const TagValMetadata *m) noexcept
Build a Derived handle from a stable metadata pointer.
Definition base.hpp:109
std::string_view code() const noexcept
Definition base.hpp:55
Definition open_ended.hpp:42
Compile-time Entry NTTP and the runtime-view TagValMetadata struct.
tagval exception types and ParseError record used by try_of().
Per-Owner runtime registry used by OpenEnded kinds.
Returned via std::expected from try_of() when a code is not present.
Definition error.hpp:25
std::string code
The attempted code.
Definition error.hpp:26
Compile-time list of Entry types for ClosedEnded kinds.