tagval 0.2.0
Modern C++23 header-only library of tagged values (open/closed enumerations with metadata)
Loading...
Searching...
No Matches
openended_registry.hpp
Go to the documentation of this file.
1#pragma once
2
14
15#include <tagval/entry.hpp>
16
17#include <algorithm>
18#include <span>
19#include <string_view>
20#include <vector>
21
22namespace tagval {
23
26template <typename Owner>
28public:
31 static void add(const TagValMetadata* m) {
32 if (m == nullptr) {
33 return;
34 }
35 auto& v = storage();
36 if (std::ranges::any_of(v, [&](const auto* x) { return x->code == m->code; })) {
37 return;
38 }
39 v.push_back(m);
40 }
41
42 [[nodiscard]] static std::span<const TagValMetadata* const> all() noexcept {
43 return std::span<const TagValMetadata* const>{storage()};
44 }
45
46 [[nodiscard]] static const TagValMetadata* find(std::string_view code) noexcept {
47 const auto& v = storage();
48 const auto it = std::ranges::find_if(v, [&](const auto* m) { return m->code == code; });
49 return it == v.end() ? nullptr : *it;
50 }
51
52private:
53 [[nodiscard]] static std::vector<const TagValMetadata*>& storage() {
54 static std::vector<const TagValMetadata*> v;
55 return v;
56 }
57};
58
59} // namespace tagval
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
Compile-time Entry NTTP and the runtime-view TagValMetadata struct.
Definition base.hpp:26
Runtime view of an entry's metadata.
Definition entry.hpp:46
std::string_view code
Definition entry.hpp:47