parcel 0.2.2
Wrappable, wire-transferable C++23 value system with JSON serialization
Loading...
Searching...
No Matches
parcel::ParcelRegistry Class Reference

Runtime catalog of cell-type descriptors, keyed by wire kind id. More...

#include <registry.h>

Public Member Functions

 ParcelRegistry (BuiltinsOptions opts={})
 Construct, optionally tuning which builtins are pre-registered.
 
void register_kind (cell_type_descriptor_t d)
 Register or replace a descriptor by its kind id.
 
template<typename... Ds>
ParcelRegistryregister_kinds (Ds &&... ds)
 Variadic shorthand: register many descriptors in one call.
 
template<typename... Cs>
ParcelRegistryregister_cells ()
 Variadic shorthand: register one descriptor per cell type.
 
cell_type_descriptor_t find (std::string_view kind) const
 Look up a descriptor by kind id.
 
cell_t cell_from_json (json_t const &j) const
 Deserialize any registered cell from JSON, dispatching by "k".
 
std::vector< cell_type_descriptor_tall () const
 Every registered descriptor.
 
std::vector< std::string_view > kinds () const
 Every registered kind id.
 
std::size_t count () const noexcept
 Number of registered kinds.
 
bool contains (std::string_view kind) const
 Whether kind is registered.
 
std::vector< cell_type_descriptor_tfind_by_category (descriptor::CellCategory c) const
 Every descriptor whose category() matches c.
 
std::vector< cell_type_descriptor_tfind_by_storage (std::type_index ti) const
 Every descriptor whose storage_type() matches ti.
 
template<typename T >
std::vector< cell_type_descriptor_tfind_by_storage () const
 Every descriptor whose storage type is T.
 
Definition define (std::string_view kind) const
 Build a Definition rooted at kind plus everything it references.
 

Detailed Description

Runtime catalog of cell-type descriptors, keyed by wire kind id.

Heterogeneous containers and any code deserializing from an arbitrary "k" go through the registry. The default-constructed registry calls register_builtins so the standard kinds are immediately available.

See also
BuiltinsOptions — toggles for what gets pre-registered.

Constructor & Destructor Documentation

◆ ParcelRegistry()

parcel::ParcelRegistry::ParcelRegistry ( BuiltinsOptions  opts = {})
inlineexplicit

Construct, optionally tuning which builtins are pre-registered.

Parameters
optsToggles forwarded to register_builtins.

Member Function Documentation

◆ cell_from_json()

cell_t parcel::ParcelRegistry::cell_from_json ( json_t const &  j) const
inline

Deserialize any registered cell from JSON, dispatching by "k".

Parameters
jInput JSON object — must contain a "k" matching a registered kind.
Returns
Newly built cell handle.
Exceptions
std::runtime_erroron shape mismatch or unknown kind.

◆ contains()

bool parcel::ParcelRegistry::contains ( std::string_view  kind) const
inline

Whether kind is registered.

Parameters
kindWire kind id.

◆ define()

Definition parcel::ParcelRegistry::define ( std::string_view  kind) const
inline

Build a Definition rooted at kind plus everything it references.

Parameters
kindWire kind id of the root.
Returns
Definition containing the root descriptor and every transitively referenced kind.
Exceptions
std::runtime_errorif kind is not registered, or if a referenced kind is missing from the registry.

◆ find()

cell_type_descriptor_t parcel::ParcelRegistry::find ( std::string_view  kind) const
inline

Look up a descriptor by kind id.

Parameters
kindWire kind id.
Returns
Descriptor handle, or nullptr if not registered.

◆ find_by_category()

std::vector< cell_type_descriptor_t > parcel::ParcelRegistry::find_by_category ( descriptor::CellCategory  c) const
inline

Every descriptor whose category() matches c.

Parameters
cCategory filter.

◆ find_by_storage() [1/2]

template<typename T >
std::vector< cell_type_descriptor_t > parcel::ParcelRegistry::find_by_storage ( ) const
inline

Every descriptor whose storage type is T.

Template Parameters
TStorage type to match.

◆ find_by_storage() [2/2]

std::vector< cell_type_descriptor_t > parcel::ParcelRegistry::find_by_storage ( std::type_index  ti) const
inline

Every descriptor whose storage_type() matches ti.

Parameters
tiStorage std::type_index filter.

◆ register_cells()

template<typename... Cs>
ParcelRegistry & parcel::ParcelRegistry::register_cells ( )
inline

Variadic shorthand: register one descriptor per cell type.

registry.register_cells<PersonCell, AddressCell>();
Template Parameters
CsPack of CellLike types whose descriptor() is registered.
Returns
*this for chaining.

◆ register_kind()

void parcel::ParcelRegistry::register_kind ( cell_type_descriptor_t  d)
inline

Register or replace a descriptor by its kind id.

Parameters
dDescriptor to register; must be non-null.
Exceptions
std::runtime_errorif d is null.

◆ register_kinds()

template<typename... Ds>
ParcelRegistry & parcel::ParcelRegistry::register_kinds ( Ds &&...  ds)
inline

Variadic shorthand: register many descriptors in one call.

registry.register_kinds(MyCellA::descriptor(), MyCellB::descriptor());
Template Parameters
DsPack of descriptor types convertible to cell_type_descriptor_t.
Parameters
dsDescriptors to register.
Returns
*this for chaining.

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