|
parcel 0.2.2
Wrappable, wire-transferable C++23 value system with JSON serialization
|
CRTP base for struct cells that are their own payload. More...
#include <struct.h>


Public Types | |
| using | storage_t = Derived |
Storage-type alias used by descriptors that probe T::storage_t. | |
Public Member Functions | |
| std::string_view | kind () const override |
| Wire-stable kind identifier for this cell. | |
| std::string | to_string () const override |
| Render the cell's value as a compact human-readable string. | |
| json_t | to_json () const override |
| Serialize this cell to its canonical JSON representation. | |
| cell_t | clone () const override |
| Deep-copy this cell. | |
| std::partial_ordering | compare (ICell const &other) const override |
Three-way comparison over field values (and cell_extras_ when allow_extra_fields is true); ignores display info. | |
| std::optional< DisplayInfo > const & | overridden_display_info () const override |
| Read-only access to this cell's optional display info. | |
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 ®) |
| Deserialize the self-payload struct cell from JSON. | |
| static cell_type_descriptor_t | descriptor () |
| Cached descriptor for this self-payload struct cell. | |
Static Public Attributes | |
| static constexpr bool | allow_extra_fields = false |
| Whether unknown JSON keys are tolerated. | |
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"). | |
Protected Member Functions | |
| void | inject_display_info (json_t &j) const |
Copy this cell's display info (if any) into the JSON object under "d". | |
| void | set_display_info (std::optional< DisplayInfo > m) override |
| Replace this cell's display info in place. | |
Protected Attributes | |
| std::optional< DisplayInfo > | display_info_ |
| Optional display info; omitted from JSON when empty. | |
| std::map< std::string, cell_t > | cell_extras_ |
Unknown keys retained when Derived::allow_extra_fields is true. | |
CRTP base for struct cells that are their own payload.
Where StructCell<Derived, Payload, StructId> composes a separate payload struct held in BaseCell::value, SelfStructCell<Derived> inherits ICell directly and treats Derived itself as the payload. Field descriptors are IPayloadFieldDescriptor<Derived> and address members on the cell instance itself — there is no nested value.
Library authors typically introduce a CRTP intermediate (e.g. BaseEvent<Self, EventId>) on top of SelfStructCell to carry common fields and to choose their own wire-namespace prefix:
Unlike StructCell, SelfStructCell has no StructId template parameter and does not synthesize a kind_id; the deriving class (or a CRTP intermediate) declares static constexpr std::string_view kind_id directly, which gives library authors freedom to carve out their own sub-namespace (e.g. "s:event:something").
Derived must additionally provide:
static constexpr std::string_view kind_id — wire kind id.static auto field_descriptors() — built via FieldsBuilder<Derived>.static DisplayInfo display_info() — cell-level display info; defaults to an empty DisplayInfo{} when not declared.static constexpr bool allow_extra_fields — defaults to false.Derived must also be default-constructible with access from parcel-internal code — from_json calls std::make_shared<Derived>(). Keeping the default constructor public while making data members protected/private is the standard pattern.
| Derived | The concrete struct cell, which is also its own payload. |
| using parcel::SelfStructCell< Derived >::storage_t = Derived |
Storage-type alias used by descriptors that probe T::storage_t.
SelfStructCell does not own a separate payload — the cell is its own payload — so storage_t resolves to Derived itself. Lets the existing BaseCellTypeDescriptor<Derived>::storage_type() keep working unchanged.
|
inlineoverridevirtual |
Deep-copy this cell.
cell_t whose state is independent of the original. Implements parcel::ICell.
|
inlineoverridevirtual |
Three-way comparison over field values (and cell_extras_ when allow_extra_fields is true); ignores display info.
Walks declared fields in the order returned by field_descriptors() and short-circuits on the first non-equal result. Optional fields follow std::optional's <=>. When allow_extra_fields is true, after declared fields agree the cell_extras_ maps are compared lexicographically by key, with ICell <=> resolving each value pair.
Implements parcel::ICell.
|
inlinestatic |
Cached descriptor for this self-payload struct cell.
StructCellTypeDescriptor<Derived, Derived> instance.
|
inlinestatic |
Deserialize the self-payload struct cell from JSON.
Mirrors StructCell::from_json, but field descriptors target Derived itself rather than a separate payload type.
| j | Input JSON object — must match {"k": kind_id, "v": {…}}. |
| reg | Registry used to dispatch nested cells. |
| std::runtime_error | on shape or kind mismatch, missing required field, or unknown key when extras are not allowed. |
|
inlineprotected |
Copy this cell's display info (if any) into the JSON object under "d".
Mirrors BaseCell::inject_display_info — re-declared here because SelfStructCell inherits ICell directly, not BaseCell.
| j | JSON object to mutate. |
|
inlineoverridevirtual |
Wire-stable kind identifier for this cell.
kind_id on the concrete type. Implements parcel::ICell.
|
inlineoverridevirtual |
Read-only access to this cell's optional display info.
Implements parcel::ICell.
|
inlineoverrideprotectedvirtual |
Replace this cell's display info in place.
Used by with_* builders on freshly cloned receivers and by JSON deserializers; no other public path mutates display info.
| m | New display info value (may be empty to clear). |
Implements parcel::ICell.
|
inlineoverridevirtual |
Serialize this cell to its canonical JSON representation.
{"k", "v", optional "d"}. Implements parcel::ICell.
|
inlineoverridevirtual |
Render the cell's value as a compact human-readable string.
Implements parcel::ICell.
|
staticconstexpr |
Whether unknown JSON keys are tolerated.
Concrete Derived types may shadow this with true to opt into lenient deserialization; the default is strict (false).