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

Heterogeneous string-keyed unordered_map of cell_t. More...

#include <unordered_map.h>

Inheritance diagram for parcel::HashMapCell:
Collaboration diagram for parcel::HashMapCell:

Public Member Functions

std::string to_string () const override
 Render the cell's value as a compact human-readable string.
 
json_t to_json () const override
 Default JSON serialization for cells with JSON-convertible storage.
 
cell_t clone () const override
 Deep-copy this cell.
 
std::size_t hash_value () const noexcept override
 Equality-consistent hash that mirrors compare's display-info-insensitivity.
 
std::partial_ordering compare (ICell const &other) const override
 Default three-way comparison: kind first, then storage value.
 
- Public Member Functions inherited from parcel::BaseCell< HashMapCell, std::unordered_map< std::string, cell_t > >
 explicit (false) BaseCell(U &&v)
 Construct by forwarding into the storage (v becomes Storage::value).
 
HashMapCelloperator= (U &&v)
 Assign to the storage from v.
 
std::unordered_map< std::string, cell_t > & get ()
 Mutable access to the held storage.
 
std::unordered_map< std::string, cell_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.
 
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).
 

Additional Inherited Members

- Static Public Member Functions inherited from parcel::BaseCell< HashMapCell, std::unordered_map< std::string, cell_t > >
static std::shared_ptr< HashMapCellof (Args &&... args)
 Construct a shared_ptr<Derived> forwarding the arguments.
 
static std::unique_ptr< HashMapCellunique (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.
 
- Public Attributes inherited from parcel::BaseCell< HashMapCell, std::unordered_map< std::string, cell_t > >
std::unordered_map< std::string, cell_tvalue
 Held value of the cell.
 
- 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").
 
- Static Protected Member Functions inherited from parcel::BaseCell< HashMapCell, std::unordered_map< std::string, cell_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< HashMapCell, std::unordered_map< std::string, cell_t > >
std::optional< DisplayInfodisplay_info_
 Optional display info; omitted from JSON when empty.
 

Detailed Description

Heterogeneous string-keyed unordered_map of cell_t.

Wire kind: "hm". Same canonicalization rule as TypedHashMapCell — sorted on the wire, unsorted in memory.

Member Function Documentation

◆ clone()

cell_t parcel::HashMapCell::clone ( ) const
inlineoverridevirtual

Deep-copy this cell.

Returns
A new cell_t whose state is independent of the original.

Reimplemented from parcel::BaseCell< HashMapCell, std::unordered_map< std::string, cell_t > >.

◆ compare()

std::partial_ordering parcel::HashMapCell::compare ( ICell const &  other) const
inlineoverridevirtual

Default three-way comparison: kind first, then storage value.

If Storage supports <=>, that comparison is forwarded directly (which yields partial_ordering for floating-point storage). If only == is available, equal values map to equivalent and unequal values to unordered. Storage types lacking either, or std::variant storage (which UnionCell overrides), return unordered.

Parameters
otherCell to compare with.
Returns
Three-way comparison result; ignores display info.

Reimplemented from parcel::BaseCell< HashMapCell, std::unordered_map< std::string, cell_t > >.

◆ hash_value()

std::size_t parcel::HashMapCell::hash_value ( ) const
inlineoverridevirtualnoexcept

Equality-consistent hash that mirrors compare's display-info-insensitivity.

Default implementation hashes the kind id and the JSON dump of "v", which works for every cell whose to_json() payload omits nested DisplayInfo. Heterogeneous container cells (ListCell, MapCell, HashMapCell) override this to recurse through hash_value() on their children — that is what keeps the hash display-info-insensitive when children carry display info of their own.

Reimplemented from parcel::ICell.

◆ to_json()

json_t parcel::HashMapCell::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< HashMapCell, std::unordered_map< std::string, cell_t > >.

◆ to_string()

std::string parcel::HashMapCell::to_string ( ) const
inlineoverridevirtual

Render the cell's value as a compact human-readable string.

Returns
String form — implementation-defined per cell type.

Implements parcel::ICell.


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