parcel 0.2.2
Wrappable, wire-transferable C++23 value system with JSON serialization
Loading...
Searching...
No Matches
parcel::InheritedFieldDescriptor< DerivedPayload, ParentPayload > Class Template Referencefinal

Adapter that lets a parent struct's payload field descriptor be reused by a derived struct. More...

#include <struct.h>

Inheritance diagram for parcel::InheritedFieldDescriptor< DerivedPayload, ParentPayload >:
Collaboration diagram for parcel::InheritedFieldDescriptor< DerivedPayload, ParentPayload >:

Public Member Functions

 InheritedFieldDescriptor (std::shared_ptr< IPayloadFieldDescriptor< ParentPayload > > inner)
 Wrap a parent payload field descriptor.
 
std::string_view key () const override
 JSON key under which this field appears in "v".
 
std::string_view kind () const override
 Cell kind id for the field's value type.
 
DisplayInfo display_info () const override
 Display info for this field.
 
bool is_required () const override
 Whether the field must be present on deserialization.
 
json_t to_json () const override
 Serialize the field descriptor itself.
 
DisplayInfomutable_display_info () override
 Mutable access to this field's display info — used by FieldsBuilder.
 
void set_required (const bool r) override
 Override the field's required flag.
 
void to_json_into (json_t &v_obj, DerivedPayload const &p) const override
 Serialize this field from p into the value object v_obj.
 
void from_json_into (json_t const &field_json, DerivedPayload &p, ParcelRegistry const &reg) const override
 Deserialize this field from field_json into p.
 
void to_string_into (std::string &out, DerivedPayload const &p) const override
 Append key: value for this field to the rendered string.
 
std::partial_ordering compare (DerivedPayload const &a, DerivedPayload const &b) const override
 Three-way compare this field across two payload instances.
 

Detailed Description

template<typename DerivedPayload, typename ParentPayload>
class parcel::InheritedFieldDescriptor< DerivedPayload, ParentPayload >

Adapter that lets a parent struct's payload field descriptor be reused by a derived struct.

Holds a shared_ptr<IPayloadFieldDescriptor<ParentPayload>> and forwards every call after static_cast-ing the derived payload reference to the parent payload reference. The cast is sound because extend<> constrains DerivedPayload to derive from ParentPayload.

Template Parameters
DerivedPayloadThe struct type using the inherited field.
ParentPayloadThe struct type that originally declared the field.

Constructor & Destructor Documentation

◆ InheritedFieldDescriptor()

template<typename DerivedPayload , typename ParentPayload >
parcel::InheritedFieldDescriptor< DerivedPayload, ParentPayload >::InheritedFieldDescriptor ( std::shared_ptr< IPayloadFieldDescriptor< ParentPayload > >  inner)
inlineexplicit

Wrap a parent payload field descriptor.

Parameters
innerParent descriptor to forward to.

Member Function Documentation

◆ compare()

template<typename DerivedPayload , typename ParentPayload >
std::partial_ordering parcel::InheritedFieldDescriptor< DerivedPayload, ParentPayload >::compare ( DerivedPayload const &  a,
DerivedPayload const &  b 
) const
inlineoverridevirtual

Three-way compare this field across two payload instances.

StructCell::compare walks fields in declaration order and short- circuits on the first non-equal result; ignores display info. Optional fields follow std::optional's <=>: absent < present, both absent is equal.

Implements parcel::IPayloadFieldDescriptor< DerivedPayload >.

◆ from_json_into()

template<typename DerivedPayload , typename ParentPayload >
void parcel::InheritedFieldDescriptor< DerivedPayload, ParentPayload >::from_json_into ( json_t const &  field_json,
DerivedPayload &  p,
ParcelRegistry const &  reg 
) const
inlineoverridevirtual

Deserialize this field from field_json into p.

Parameters
field_jsonJSON value for this field (already a wrapped cell).
pPayload instance to write into.
regRegistry forwarded to nested cell deserializers.

Implements parcel::IPayloadFieldDescriptor< DerivedPayload >.

◆ to_json()

template<typename DerivedPayload , typename ParentPayload >
json_t parcel::InheritedFieldDescriptor< DerivedPayload, ParentPayload >::to_json ( ) const
inlineoverridevirtual

Serialize the field descriptor itself.

Returns
JSON object with key, kind, display_info, required.

Implements parcel::IFieldDescriptor.

◆ to_json_into()

template<typename DerivedPayload , typename ParentPayload >
void parcel::InheritedFieldDescriptor< DerivedPayload, ParentPayload >::to_json_into ( json_t v_obj,
DerivedPayload const &  p 
) const
inlineoverridevirtual

Serialize this field from p into the value object v_obj.

Parameters
v_objTarget JSON object (the "v" block of the cell).
pPayload instance to read from.

Implements parcel::IPayloadFieldDescriptor< DerivedPayload >.

◆ to_string_into()

template<typename DerivedPayload , typename ParentPayload >
void parcel::InheritedFieldDescriptor< DerivedPayload, ParentPayload >::to_string_into ( std::string &  out,
DerivedPayload const &  p 
) const
inlineoverridevirtual

Append key: value for this field to the rendered string.

Parameters
outString buffer to append to.
pPayload instance to read from.

Implements parcel::IPayloadFieldDescriptor< DerivedPayload >.


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