|
parcel 0.2.2
Wrappable, wire-transferable C++23 value system with JSON serialization
|
The default_cell_for<T> trait that drives FieldsBuilder field-type inference.
More...
#include <parcel/list.h>#include <parcel/map.h>#include <parcel/primitive.h>#include <parcel/union.h>#include <array>#include <cstddef>#include <deque>#include <list>#include <map>#include <memory>#include <optional>#include <set>#include <string>#include <type_traits>#include <unordered_map>#include <utility>#include <variant>#include <vector>

Go to the source code of this file.
Classes | |
| struct | parcel::default_cell_for< T, typename > |
Maps a raw field type to its default ICell wrapper. More... | |
| struct | parcel::default_cell_for< T > |
Any PrimitiveStorage type → PrimitiveCell<T>. More... | |
| struct | parcel::default_cell_for< std::vector< T > > |
std::vector<T> (with a default-wrappable T) → TypedListCell<wrapper>. More... | |
| struct | parcel::default_cell_for< std::map< std::string, T > > |
std::map<std::string, T> (with a default-wrappable T) → TypedMapCell<wrapper>. More... | |
| struct | parcel::default_cell_for< std::unordered_map< std::string, T > > |
std::unordered_map<std::string, T> → TypedMapCell<wrapper> (sorted on the wire). More... | |
| struct | parcel::default_cell_for< std::array< T, N > > |
std::array<T, N> → TypedListCell<wrapper> (size erased on the wire). More... | |
| struct | parcel::default_cell_for< std::deque< T > > |
std::deque<T> → TypedListCell<wrapper>. More... | |
| struct | parcel::default_cell_for< std::list< T > > |
std::list<T> → TypedListCell<wrapper>. More... | |
| struct | parcel::default_cell_for< std::set< T > > |
std::set<T> → TypedListCell<wrapper> (the wire form is a list — sort/unique is the user's responsibility). More... | |
| struct | parcel::default_cell_for< std::variant< Ts... > > |
std::variant<Ts...> (with default-wrappable Ts) → UnionCell<wrappers...>. More... | |
| struct | parcel::default_cell_for< std::optional< T > > |
std::optional<T> (with a default-wrappable T) → the inner wrapper itself. More... | |
Concepts | |
| concept | parcel::HasDefaultCellWrapper |
Concept matching types for which a default_cell_for mapping exists. | |
Macros | |
| #define | PARCEL_DEFAULT_CELL(CellT) |
| Register a cell type as the default wrapper for its payload type. | |
Typedefs | |
| template<typename T > | |
| using | parcel::default_cell_for_t = default_cell_for< T >::type |
Convenience alias for default_cell_for<T>::type. | |
Functions | |
| template<typename T > requires HasDefaultCellWrapper<detail::cell_arg_t<T>> | |
| auto | parcel::cell (T &&v) |
Wrap a raw value into its default cell, returning a shared_ptr to the cell. | |
| template<typename... Ts> requires (HasDefaultCellWrapper<detail::cell_arg_t<Ts>> && ...) | |
| std::shared_ptr< ListCell > | parcel::make_list (Ts &&... xs) |
Build a heterogeneous ListCell from raw values, wrapping each via parcel::cell(...). | |
| std::shared_ptr< MapCell > | parcel::make_map (const std::initializer_list< std::pair< const std::string, cell_t > > entries) |
Build a heterogeneous MapCell from a brace list of {key, cell} pairs. | |
The default_cell_for<T> trait that drives FieldsBuilder field-type inference.
default_cell_for<T> maps a raw field type to the cell wrapper used for it on the wire. Out of the box every PrimitiveStorage type maps to PrimitiveCell<T>, std::vector<T> to TypedListCell, std::map<std::string, T> to TypedMapCell, std::variant<Ts...> to UnionCell, and std::optional<T> to the inner wrapper. User code can specialize the trait for custom field types so the parameter-less FieldsBuilder::field<MemberPtr>(key) works. See the README "Default cell wrappers" section.
| #define PARCEL_DEFAULT_CELL | ( | CellT | ) |
Register a cell type as the default wrapper for its payload type.
Expands to a parcel::default_cell_for specialization mapping CellT::storage_t to CellT, so FieldsBuilder::field<MemberPtr>(key) can infer the wrapper from the field type alone (and the free parcel::cell(value) factory picks it up too).
Use once per user-defined cell, at namespace scope (typically just below the class definition, outside any namespace):
Equivalent hand-rolled form:
The cell type must be complete and expose a storage_t typedef — every cell derived from parcel::BaseCell (including StructCell) does.
| CellT | Fully-qualified cell type (e.g. demo::AddressCell). |
| auto parcel::cell | ( | T && | v | ) |
Wrap a raw value into its default cell, returning a shared_ptr to the cell.
Picks the wrapper via default_cell_for_t, with a small normalization layer so cell("hi") resolves to StringCell rather than tripping over const char*.
| T | Argument type — its decayed form must satisfy HasDefaultCellWrapper. |
| v | Raw value. |
std::shared_ptr<Cell> owning the new cell. | std::shared_ptr< ListCell > parcel::make_list | ( | Ts &&... | xs | ) |
Build a heterogeneous ListCell from raw values, wrapping each via parcel::cell(...).
| Ts | Argument types — each must satisfy HasDefaultCellWrapper after cell_arg normalization. |
std::shared_ptr<ListCell> owning the new list.
|
inline |
Build a heterogeneous MapCell from a brace list of {key, cell} pairs.
For homogeneous maps prefer TypedMapCell<T> directly. This helper is for the heterogeneous case where each value is already a cell_t (typically built via parcel::cell(value)).