parcel 0.2.2
Wrappable, wire-transferable C++23 value system with JSON serialization
Loading...
Searching...
No Matches
parcel::TypedListCell< T > Class Template Reference

Homogeneous list of element cells of type T. More...

#include <list.h>

Inheritance diagram for parcel::TypedListCell< T >:
Collaboration diagram for parcel::TypedListCell< T >:

Public Member Functions

 TypedListCell (std::initializer_list< element_storage_t > elems)
 Construct from a brace-enclosed list of element values.
 
template<std::ranges::input_range R>
requires std::convertible_to<std::ranges::range_value_t<R>, element_storage_t>
 TypedListCell (std::from_range_t, R &&r)
 Construct from any input range whose elements convert to element_storage_t.
 
 TypedListCell (std::span< const element_storage_t > sp)
 Construct by copying the contents of sp into the list.
 
std::span< const element_storage_t > as_span () const noexcept
 Read-only span view over the list's elements.
 
std::span< element_storage_t > as_span () noexcept
 Mutable span view over the list's elements.
 
std::string to_string () const override
 Render the list as [a, b, c] using each element's to_string.
 
json_t to_json () const override
 Default JSON serialization for cells with JSON-convertible storage.
 
std::partial_ordering compare (ICell const &other) const override
 Element-wise three-way comparison; ignores display info.
 
template<typename U >
requires std::assignable_from<Storage&, U&&>
Derived & operator= (U &&v)
 Assign to the storage from v.
 
- Public Member Functions inherited from parcel::BaseCell< TypedListCell< T >, std::vector< T::storage_t > >
 explicit (false) BaseCell(U &&v)
 Construct by forwarding into the storage (v becomes Storage::value).
 
TypedListCell< T > & operator= (U &&v)
 Assign to the storage from v.
 
std::vector< T::storage_t > & get ()
 Mutable access to the held storage.
 
std::vector< T::storage_t > const & get () const
 Read-only access to the held storage.
 
void inject_display_info (json_t &j) const
 Copy this cell's display info (if any) into the JSON object under "d".
 
- Public Member Functions inherited from parcel::ICell
virtual std::string to_formatted_string () const
 Render the cell as a multi-line, indented string.
 
virtual std::size_t hash_value () const noexcept
 Equality-consistent hash that mirrors compare's display-info-insensitivity.
 
cell_t with_display_info (DisplayInfo m) const
 Return a deep copy with the entire display info block replaced.
 
cell_t with_name (std::string v) const
 Return a deep copy with name set to v.
 
cell_t with_description (std::string v) const
 Return a deep copy with description set to v.
 
cell_t with_icon (comms::Icon icon) const
 Return a deep copy with icon set to the typed icon.
 
cell_t with_icon (std::string const &v) const
 Return a deep copy with icon parsed from an Iconify set:name string (e.g.
 
cell_t with_color (comms::Color color) const
 Return a deep copy with color set to the typed color.
 
cell_t with_color (std::string const &v) const
 Return a deep copy with color parsed from a color string (hex like "#ffcc00", a CSS-functional form, or a CSS color name).
 

Static Public Member Functions

static cell_t from_json (json_t const &j, ParcelRegistry const &reg)
 Deserialize a TypedListCell<T> from JSON.
 
static cell_type_descriptor_t descriptor ()
 Cached descriptor for this typed list.
 
- Static Public Member Functions inherited from parcel::BaseCell< TypedListCell< T >, std::vector< T::storage_t > >
static std::shared_ptr< TypedListCell< T > > of (Args &&... args)
 Construct a shared_ptr<Derived> forwarding the arguments.
 
static std::unique_ptr< TypedListCell< T > > unique (Args &&... args)
 Construct a unique_ptr<Derived> forwarding the arguments.
 
static void absorb_display_info (json_t const &j, Out &out)
 Read "d" (if present) from a JSON object and assign it onto a cell.
 
static cell_t from_json_strict (json_t const &j)
 Strict shorthand for the recurring cell_from_json + make_shared.
 

Static Public Attributes

static constexpr std::string_view kind_id = prefixed_id_v<"l:", T::kind_id>
 Wire kind id of this typed list ("l:" + T::kind_id).
 
- Static Public Attributes inherited from parcel::ICell
static constexpr std::string_view KEY_KIND = "k"
 JSON key for the kind id ("k").
 
static constexpr std::string_view KEY_VALUE = "v"
 JSON key for the value payload ("v").
 
static constexpr std::string_view KEY_DESCRIPTION = "d"
 JSON key for the optional display info block ("d").
 

Additional Inherited Members

- Public Attributes inherited from parcel::BaseCell< TypedListCell< T >, std::vector< T::storage_t > >
std::vector< T::storage_t > value
 Held value of the cell.
 
- Static Protected Member Functions inherited from parcel::BaseCell< TypedListCell< T >, std::vector< T::storage_t > >
static T cell_from_json (const json_t &j, const std::string_view expected_kind)
 Validate a wrapped {"k","v"} JSON object and extract its "v" as T.
 
- Protected Attributes inherited from parcel::BaseCell< TypedListCell< T >, std::vector< T::storage_t > >
std::optional< DisplayInfodisplay_info_
 Optional display info; omitted from JSON when empty.
 

Detailed Description

template<CellLike T>
class parcel::TypedListCell< T >

Homogeneous list of element cells of type T.

Wire shape (example for TypedListCell<I32Cell>):

{"k": "l:i32", "v": [1, 2, 3]}

The element kind is part of "k" so the registry can dispatch each typed list distinctly. Storage is std::vector<typename T::storage_t>, which means raw element values (not wrapper cells) are held — the kind discipline lives on the type tag, and a curated subset of std::vector's API is forwarded for ergonomic use.

Template Parameters
TElement cell type (must satisfy CellLike).
See also
TypedListCellTypeDescriptor

Constructor & Destructor Documentation

◆ TypedListCell() [1/2]

template<CellLike T>
parcel::TypedListCell< T >::TypedListCell ( std::initializer_list< element_storage_t >  elems)
inline

Construct from a brace-enclosed list of element values.

Parameters
elemsInitializer list of raw element values.

◆ TypedListCell() [2/2]

template<CellLike T>
template<std::ranges::input_range R>
requires std::convertible_to<std::ranges::range_value_t<R>, element_storage_t>
parcel::TypedListCell< T >::TypedListCell ( std::from_range_t  ,
R &&  r 
)
inline

Construct from any input range whose elements convert to element_storage_t.

Disambiguated by std::from_range_t so it does not collide with the inherited BaseCell(U&&).

Member Function Documentation

◆ compare()

template<CellLike T>
std::partial_ordering parcel::TypedListCell< T >::compare ( ICell const &  other) const
inlineoverridevirtual

Element-wise three-way comparison; ignores display info.

Each element pair is wrapped in T and routed through T::compare so element types whose raw storage lacks == (e.g. struct payloads) still compare correctly via the cell wrapper.

Reimplemented from parcel::BaseCell< TypedListCell< T >, std::vector< T::storage_t > >.

◆ descriptor()

template<CellLike T>
static cell_type_descriptor_t parcel::TypedListCell< T >::descriptor ( )
inlinestatic

Cached descriptor for this typed list.

Returns
Shared TypedListCellTypeDescriptor<T> instance.

◆ from_json()

template<CellLike T>
static cell_t parcel::TypedListCell< T >::from_json ( json_t const &  j,
ParcelRegistry const &  reg 
)
inlinestatic

Deserialize a TypedListCell<T> from JSON.

Parameters
jInput JSON object — must match {"k": kind_id, "v": [...] }.
regRegistry (passed through to per-element from_json).
Returns
Newly built cell handle.
Exceptions
std::runtime_erroron shape or kind mismatch, or if any element fails to deserialize as T.

◆ operator=()

template<CellLike T>
template<typename U >
requires std::assignable_from<Storage&, U&&>
Derived & parcel::BaseCell< Derived, Storage >::operator= ( U &&  v)
inline

Assign to the storage from v.

Template Parameters
UAny type assignable to the storage.
Parameters
vReplacement value.
Returns
Reference to the derived cell for chaining.

◆ to_json()

template<CellLike T>
json_t parcel::TypedListCell< T >::to_json ( ) const
inlineoverridevirtual

Default JSON serialization for cells with JSON-convertible storage.

If Storage has a JSON adapter, emits {"k": kind_id, "v": value, optional "d": display info}. Otherwise the call throws — the derived cell must override to_json itself (ListCell, MapCell, etc.).

Returns
JSON object representation.
Exceptions
std::runtime_errorif Storage is not JSON-convertible.

Reimplemented from parcel::BaseCell< TypedListCell< T >, std::vector< T::storage_t > >.

◆ to_string()

template<CellLike T>
std::string parcel::TypedListCell< T >::to_string ( ) const
inlineoverridevirtual

Render the list as [a, b, c] using each element's to_string.

Returns
Bracketed comma-separated form.

Implements parcel::ICell.

Member Data Documentation

◆ kind_id

template<CellLike T>
constexpr std::string_view parcel::TypedListCell< T >::kind_id = prefixed_id_v<"l:", T::kind_id>
staticconstexpr

Wire kind id of this typed list ("l:" + T::kind_id).

Encoded in the type so each instantiation registers under a distinct kind:

Homogeneous list of element cells of type T.
Definition list.h:106

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