33#include <commons/color.hpp>
34#include <commons/display_info.hpp>
35#include <commons/flag.hpp>
36#include <commons/icon.hpp>
37#include <commons/json.hpp>
38#include <commons/origin.hpp>
39#include <commons/semver.hpp>
40#include <commons/version_constraint.hpp>
58 using base_t::operator=;
60 static constexpr std::string_view kind_id =
"color";
62 [[nodiscard]] std::string
to_string()
const override {
63 return this->
value.to_hex_string();
67 auto v = base_t::cell_from_json<comms::Color>(j, kind_id);
68 auto cell = std::make_shared<ColorCell>(v);
73 static cell_type_descriptor_t descriptor() {
74 static const auto d = std::make_shared<SimpleCellTypeDescriptor<ColorCell>>(
75 DisplayInfo{.name =
"Color", .description =
"RGBA color (hex string on the wire)"});
88 using base_t::operator=;
90 static constexpr std::string_view kind_id =
"icon";
92 [[nodiscard]] std::string
to_string()
const override {
93 return this->
value.to_string();
97 auto v = base_t::cell_from_json<comms::Icon>(j, kind_id);
98 auto cell = std::make_shared<IconCell>(v);
103 static cell_type_descriptor_t descriptor() {
104 static const auto d = std::make_shared<SimpleCellTypeDescriptor<IconCell>>(DisplayInfo{
105 .name =
"Icon", .description =
"Iconify icon identifier (set:name string)"});
117 using base_t::base_t;
118 using base_t::operator=;
120 static constexpr std::string_view kind_id =
"display_info";
127 auto v = base_t::cell_from_json<comms::DisplayInfo>(j, kind_id);
128 auto cell = std::make_shared<DisplayInfoCell>(std::move(v));
133 static cell_type_descriptor_t descriptor() {
134 static const auto d = std::make_shared<SimpleCellTypeDescriptor<DisplayInfoCell>>(
135 DisplayInfo{.name =
"DisplayInfo",
136 .description =
"Presentation display info (name/description/icon/color)"});
151 using base_t::base_t;
152 using base_t::operator=;
154 static constexpr std::string_view kind_id =
"flag";
157 return std::string{this->
value.name};
161 auto v = base_t::cell_from_json<comms::FlagRef>(j, kind_id);
162 auto cell = std::make_shared<FlagCell>(v);
167 static cell_type_descriptor_t descriptor() {
168 static const auto d = std::make_shared<SimpleCellTypeDescriptor<FlagCell>>(DisplayInfo{
169 .name =
"Flag", .description =
"Reference to a registered flag (name on the wire)"});
184 using base_t::base_t;
185 using base_t::operator=;
187 static constexpr std::string_view kind_id =
"flag_set";
190 std::string out =
"[";
192 for (
auto const& f : this->
value) {
196 out += std::string{f.name};
204 auto v = base_t::cell_from_json<comms::FlagSet>(j, kind_id);
205 auto cell = std::make_shared<FlagSetCell>(std::move(v));
210 static cell_type_descriptor_t descriptor() {
211 static const auto d = std::make_shared<SimpleCellTypeDescriptor<FlagSetCell>>(
212 DisplayInfo{.name =
"FlagSet",
213 .description =
"Insertion-ordered set of flags (names on the wire)"});
226 using base_t::base_t;
227 using base_t::operator=;
229 static constexpr std::string_view kind_id =
"semver";
232 return this->
value.to_string();
236 auto v = base_t::cell_from_json<comms::SemVer>(j, kind_id);
237 auto cell = std::make_shared<SemVerCell>(v);
242 static cell_type_descriptor_t descriptor() {
243 static const auto d = std::make_shared<SimpleCellTypeDescriptor<SemVerCell>>(DisplayInfo{
244 .name =
"SemVer", .description =
"Semantic version (canonical string on the wire)"});
260 using base_t::base_t;
261 using base_t::operator=;
263 static constexpr std::string_view kind_id =
"version_constraint";
266 return this->
value.to_string();
270 auto v = base_t::cell_from_json<comms::VersionConstraint>(j, kind_id);
271 auto cell = std::make_shared<VersionConstraintCell>(std::move(v));
276 static cell_type_descriptor_t descriptor() {
277 static const auto d = std::make_shared<SimpleCellTypeDescriptor<VersionConstraintCell>>(
278 DisplayInfo{.name =
"VersionConstraint",
279 .description =
"Semver range constraint (range string on the wire)"});
296 using storage_t = comms::OriginPtr;
298 static constexpr std::string_view kind_id =
"origin";
308 return std::make_shared<OriginCell>(std::move(v));
311 [[nodiscard]] std::string_view
kind()
const override {
316 return display_info_;
320 return value ? std::string{
value->kind()} : std::string{
"null"};
332 auto c = std::make_shared<OriginCell>(
value ?
value->clone() : comms::OriginPtr{});
333 c->display_info_ = display_info_;
337 [[nodiscard]] std::partial_ordering
compare(
ICell const& other)
const override {
338 if (
const auto k_cmp = this->
kind() <=> other.
kind(); k_cmp != 0) {
341 const auto* o =
dynamic_cast<OriginCell const*
>(&other);
343 return std::partial_ordering::unordered;
346 : std::partial_ordering::unordered;
352 if (!j.is_object()) {
355 const auto it_kind = j.find(
KEY_KIND);
356 if (it_kind == j.end() || !it_kind->is_string()) {
357 throw InvalidJsonException(
"Missing or invalid 'k' field in ICell JSON",
358 std::string(kind_id));
360 if (
const auto k = it_kind->get<std::string_view>(); k != kind_id) {
361 throw KindMismatchException(
"Unexpected kind in ICell JSON: expected '" +
362 std::string(kind_id) +
"', got '" + std::string(k) +
364 std::string(kind_id));
367 if (it_value == j.end()) {
368 throw InvalidJsonException(
"Missing 'v' field in ICell JSON", std::string(kind_id));
371 auto cell = std::make_shared<OriginCell>(it_value->get<comms::OriginPtr>());
373 cell->set_display_info(it_d->get<DisplayInfo>());
379 static const auto d = std::make_shared<SimpleCellTypeDescriptor<OriginCell>>(
DisplayInfo{
381 .description =
"Polymorphic provenance envelope ({\"kind\", …fields} on the wire)"});
387 display_info_ = std::move(m);
391 std::optional<DisplayInfo> display_info_;
Core ICell interface, cell_t handle, BaseCell CRTP base, and CellLike concept.
std::shared_ptr< ICellTypeDescriptor > cell_type_descriptor_t
Shared handle to a runtime cell-type descriptor.
Definition cell.h:63
std::shared_ptr< ICell > cell_t
Shared handle to any ICell-derived value — the canonical cell pointer.
Definition cell.h:68
Cell wrapping comms::Color.
Definition commons.h:53
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition commons.h:62
Cell wrapping comms::DisplayInfo.
Definition commons.h:113
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition commons.h:122
Cell wrapping comms::FlagRef.
Definition commons.h:147
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition commons.h:156
Cell wrapping comms::FlagSet.
Definition commons.h:180
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition commons.h:189
Cell wrapping comms::Icon.
Definition commons.h:83
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition commons.h:92
JSON shape was wrong (missing/non-string k, missing v, etc.).
Definition error.h:158
Cell wrapping comms::OriginPtr (a std::unique_ptr<comms::IOrigin>).
Definition commons.h:294
static cell_t of(comms::OriginPtr v)
Construct a shared_ptr<OriginCell> owning v.
Definition commons.h:307
std::optional< DisplayInfo > const & overridden_display_info() const override
Read-only access to this cell's optional display info.
Definition commons.h:315
json_t to_json() const override
Serialize this cell to its canonical JSON representation.
Definition commons.h:323
comms::OriginPtr value
Held origin (may be null).
Definition commons.h:301
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition commons.h:319
void set_display_info(std::optional< DisplayInfo > m) override
Replace this cell's display info in place.
Definition commons.h:386
std::string_view kind() const override
Wire-stable kind identifier for this cell.
Definition commons.h:311
std::partial_ordering compare(ICell const &other) const override
Three-way compare against another cell.
Definition commons.h:337
cell_t clone() const override
Deep-copy this cell.
Definition commons.h:331
Runtime catalog of cell-type descriptors, keyed by wire kind id.
Definition registry.h:115
Cell wrapping comms::SemVer.
Definition commons.h:222
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition commons.h:231
Cell wrapping comms::VersionConstraint.
Definition commons.h:256
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition commons.h:265
comms::DisplayInfo DisplayInfo
Display info attached to a cell or descriptor — re-exported from comms::DisplayInfo.
Definition common.h:75
The default_cell_for<T> trait that drives FieldsBuilder field-type inference.
#define PARCEL_DEFAULT_CELL(CellT)
Register a cell type as the default wrapper for its payload type.
Definition defaults.h:269
auto cell(T &&v)
Wrap a raw value into its default cell, returning a shared_ptr to the cell.
Definition defaults.h:192
Runtime cell-type descriptors and the schema-graph mix-ins (IHasFields, ISubTypes).
nlohmann::json typedef shared across cell types.
nlohmann::json json_t
Project-wide alias for nlohmann::json.
Definition json.h:19
CRTP base providing default to_json / clone / kind plumbing on top of a storage type.
Definition cell.h:343
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.
Definition cell.h:499
comms::Color value
Held value of the cell.
Definition cell.h:348
Polymorphic root of every parcel cell.
Definition cell.h:84
static constexpr std::string_view KEY_DESCRIPTION
JSON key for the optional display info block ("d").
Definition cell.h:90
static constexpr std::string_view KEY_VALUE
JSON key for the value payload ("v").
Definition cell.h:88
virtual std::string_view kind() const =0
Wire-stable kind identifier for this cell.
static constexpr std::string_view KEY_KIND
JSON key for the kind id ("k").
Definition cell.h:86