tagval 0.2.0
Modern C++23 header-only library of tagged values (open/closed enumerations with metadata)
Loading...
Searching...
No Matches
tagval Namespace Reference

Namespaces

namespace  detail
 

Classes

class  ClosedEnded
 CRTP base for tag-value kinds whose values are fixed at compile time. More...
 
struct  Entry
 Compile-time entry. More...
 
struct  KindEntryView
 Flattened, copy-friendly view of a single entry. More...
 
class  KindRegistry
 Program-wide index of every kind that opted in via TAGVAL_REGISTER_KIND. More...
 
class  KindView
 Type-erased handle to one registered kind. More...
 
class  OpenEnded
 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...
 
class  OpenEndedRegistry
 Runtime list of metadata pointers for a single OpenEnded kind. More...
 
struct  ParseError
 Returned via std::expected from try_of() when a code is not present. More...
 
class  TagValCell
 
struct  TagValDescriptor
 Runtime metadata describing a tag-value kind (e.g. More...
 
class  TagValError
 Common base exception. Catch this to handle any tagval-thrown error. More...
 
struct  TagValMetadata
 Runtime view of an entry's metadata. More...
 
class  UnknownCodeError
 Thrown by of() when a code is not present. More...
 
struct  Values
 Compile-time tuple of Entry types belonging to a single Owner. More...
 

Enumerations

enum class  KindCategory { Closed , Open }
 Which CRTP base a kind derives from. More...
 

Functions

template<typename E >
constexpr std::string_view label_or_code () noexcept
 If the user declared an empty label, fall back to the code so that label() never returns an empty string for a valid entry.
 
template<typename E >
constexpr TagValMetadata metadata_of () noexcept
 
template<typename T >
requires std::derived_from<T, detail::TagValBaseTag>
void to_json (::nlohmann::json &j, const T &v)
 
template<typename T >
requires std::derived_from<T, detail::TagValBaseTag>
void from_json (const ::nlohmann::json &j, T &v)
 
template<typename T >
requires std::derived_from<T, detail::TagValBaseTag>
std::ostream & operator<< (std::ostream &os, const T &v)
 
template<typename V >
constexpr auto values_metadata_array ()
 Materialize the metadata array for a Values<...> list.
 
template<typename V >
constexpr auto values_metadata_pointers ()
 Materialize an array of pointers to the pinned metadata_v<E> constants for a Values<...> list.
 

Variables

template<typename E >
constexpr TagValMetadata metadata_v = metadata_of<E>()
 Pinned, per-entry TagValMetadata constant.
 

Enumeration Type Documentation

◆ KindCategory

enum class tagval::KindCategory
strong

Which CRTP base a kind derives from.

Enumerator
Closed 
Open 

Function Documentation

◆ label_or_code()

template<typename E >
constexpr std::string_view tagval::label_or_code ( )
constexprnoexcept

If the user declared an empty label, fall back to the code so that label() never returns an empty string for a valid entry.

◆ metadata_of()

template<typename E >
constexpr TagValMetadata tagval::metadata_of ( )
constexprnoexcept

◆ to_json()

template<typename T >
requires std::derived_from<T, detail::TagValBaseTag>
void tagval::to_json ( ::nlohmann::json &  j,
const T &  v 
)
inline

◆ from_json()

template<typename T >
requires std::derived_from<T, detail::TagValBaseTag>
void tagval::from_json ( const ::nlohmann::json &  j,
T &  v 
)
inline

◆ operator<<()

template<typename T >
requires std::derived_from<T, detail::TagValBaseTag>
std::ostream & tagval::operator<< ( std::ostream &  os,
const T &  v 
)
inline

◆ values_metadata_array()

template<typename V >
constexpr auto tagval::values_metadata_array ( )
constexpr

Materialize the metadata array for a Values<...> list.

Used by ClosedEnded::all_values() to expose a constexpr metadata snapshot.

◆ values_metadata_pointers()

template<typename V >
constexpr auto tagval::values_metadata_pointers ( )
constexpr

Materialize an array of pointers to the pinned metadata_v<E> constants for a Values<...> list.

Used by OpenEnded to seed Registry with stable addresses identical to those used by extern entries.

Variable Documentation

◆ metadata_v

template<typename E >
constexpr TagValMetadata tagval::metadata_v = metadata_of<E>()
inlineconstexpr

Pinned, per-entry TagValMetadata constant.

Inline-variable templates are ODR-merged across translation units, so every TU sees the same address for metadata_v<E>. Registry stores pointers into this storage instead of copies, which keeps handle identity stable even when extern entries register after main() begins.