tagval 0.2.0
Modern C++23 header-only library of tagged values (open/closed enumerations with metadata)
Loading...
Searching...
No Matches
tagval::OpenEnded< Id, Derived > Class Template Reference

CRTP base for tag-value kinds whose values are partly compile-time (Derived::values_t) and partly contributed by plugins via TAGVAL_EXTERN_ENTRY. More...

#include <open_ended.hpp>

+ Inheritance diagram for tagval::OpenEnded< Id, Derived >:
+ Collaboration diagram for tagval::OpenEnded< Id, Derived >:

Static Public Member Functions

template<typename E >
static const Derived & value () noexcept
 Canonical handle for an entry.
 
static auto all_values () noexcept
 Range of TagValMetadata covering compile-time values_t entries (seeded lazily on first call) plus extern entries currently registered in OpenEndedRegistry<Derived>.
 
static Derived of (std::string_view code)
 Look up a value by code. Throws UnknownCodeError on miss.
 
static std::expected< Derived, ParseErrortry_of (std::string_view code) noexcept
 Look up a value by code. Returns ParseError on miss.
 
- Static Public Member Functions inherited from tagval::detail::HandleBase< Id, Derived >
static constexpr std::string_view kind_id () noexcept
 
static constexpr TagValDescriptor descriptor () noexcept
 

Additional Inherited Members

- Public Member Functions inherited from tagval::detail::HandleBase< Id, Derived >
constexpr HandleBase () noexcept=default
 Default-constructed handle: empty(), bool() == false.
 
std::string_view code () const noexcept
 
std::string_view label () const noexcept
 
std::optional< comms::Icon > icon () const noexcept
 
std::optional< comms::Color > color () const noexcept
 
bool empty () const noexcept
 
 operator bool () const noexcept
 
- Protected Member Functions inherited from tagval::detail::HandleBase< Id, Derived >
constexpr HandleBase (const TagValMetadata *m) noexcept
 
- Static Protected Member Functions inherited from tagval::detail::HandleBase< Id, Derived >
static Derived make_handle (const TagValMetadata *m) noexcept
 Build a Derived handle from a stable metadata pointer.
 
static const TagValMetadatafind_in (const std::span< const TagValMetadata > values, const std::string_view code) noexcept
 Linear search a metadata range by code.
 
static Derived of_impl (const std::span< const TagValMetadata > values, const std::string_view code)
 
static std::expected< Derived, ParseErrortry_of_impl (const std::span< const TagValMetadata > values, const std::string_view code) noexcept
 
- Protected Attributes inherited from tagval::detail::HandleBase< Id, Derived >
const TagValMetadatameta_ = nullptr
 

Detailed Description

template<comms::FixedString Id, typename Derived>
class tagval::OpenEnded< Id, Derived >

CRTP base for tag-value kinds whose values are partly compile-time (Derived::values_t) and partly contributed by plugins via TAGVAL_EXTERN_ENTRY.

class Kind : public tagval::OpenEnded<"kind", Kind> {
public:
    using base_t = tagval::OpenEnded<"kind", Kind>;
    using base_t::base_t;
    TAGVAL_ENTRY(Kind, Phone,  phone,  "Phone")
    TAGVAL_ENTRY(Kind, Tablet, tablet, "Tablet")
    using values_t = tagval::Values<Phone, Tablet>;
};

namespace vendor {
TAGVAL_EXTERN_ENTRY(::Kind, SmartWatch, smart_watch, "Smart Watch");
} 

Member Function Documentation

◆ value()

template<comms::FixedString Id, typename Derived >
template<typename E >
static const Derived & tagval::OpenEnded< Id, Derived >::value ( )
inlinestaticnoexcept

Canonical handle for an entry.

Looked up via OpenEndedRegistry, so the handle's address agrees with of(E::code) whether E came from values_t or from a TAGVAL_EXTERN_ENTRY in another translation unit.

◆ all_values()

template<comms::FixedString Id, typename Derived >
static auto tagval::OpenEnded< Id, Derived >::all_values ( )
inlinestaticnoexcept

Range of TagValMetadata covering compile-time values_t entries (seeded lazily on first call) plus extern entries currently registered in OpenEndedRegistry<Derived>.

Each element is a reference to the pinned metadata storage and remains valid for the program's lifetime.

◆ of()

template<comms::FixedString Id, typename Derived >
static Derived tagval::OpenEnded< Id, Derived >::of ( std::string_view  code)
inlinestatic

Look up a value by code. Throws UnknownCodeError on miss.

◆ try_of()

template<comms::FixedString Id, typename Derived >
static std::expected< Derived, ParseError > tagval::OpenEnded< Id, Derived >::try_of ( std::string_view  code)
inlinestaticnoexcept

Look up a value by code. Returns ParseError on miss.


The documentation for this class was generated from the following file: