JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
jsonv::value_adapter_for< T > Class Template Referenceabstract

A base for adapters written against the older value -based interface, in both directions. More...

#include <jsonv/serialization/adapter_for.hpp>

+ Inheritance diagram for jsonv::value_adapter_for< T >:
+ Collaboration diagram for jsonv::value_adapter_for< T >:

Protected Member Functions

virtual std::expected< T, ast_node_type > create (deserialization_context &context, reader &from) const final override
 Create an instance of T by reading from.
 
virtual void serialize (const serialization_context &context, const T &from, writer &to) const final override
 Write from into to.
 
virtual T create (deserialization_context &context, const value &from) const =0
 Create an instance of T from the materialised from.
 
virtual value to_json (const serialization_context &context, const T &from) const =0
 Convert from into a value.
 

Additional Inherited Members

- Public Member Functions inherited from jsonv::adapter_for< T >
virtual const std::type_info & get_type () const noexcept override
 
virtual std::expected< void, ast_node_type > deserialize (deserialization_context &context, reader &from, void *into) const override
 
virtual void serialize (const serialization_context &context, const void *from, writer &to) const override
 

Detailed Description

template<typename T>
class jsonv::value_adapter_for< T >

A base for adapters written against the older value -based interface, in both directions.

Reading, the subtree under the reader is materialised with read_value and handed to the subclass, whose create runs unchanged. Writing, the value the subclass's to_json builds is written whole into the writer with writer::write. Both cost the tree the reader and the writer exist to avoid – so it is a stepping stone for ports, not a destination. New adapters should derive from adapter_for, walk the reader and write into the writer.

Definition at line 107 of file adapter_for.hpp.

Member Function Documentation

◆ create() [1/2]

template<typename T >
virtual T jsonv::value_adapter_for< T >::create ( deserialization_context &  context,
const value &  from 
) const
protectedpure virtual

Create an instance of T from the materialised from.

Exceptions
deserialization_errorif from cannot be converted to a T.

◆ create() [2/2]

template<typename T >
virtual std::expected< T, ast_node_type > jsonv::value_adapter_for< T >::create ( deserialization_context &  context,
reader &  from 
) const
inlinefinaloverrideprotectedvirtual

Create an instance of T by reading from.

Parameters
contextExtra information to help you decode sub-objects, such as looking up other deserializer implementations via formats. Record any problem you encounter with deserialization_context::problem.
fromThe JSON reader to deserialize from. On a successful return it should sit one position past the value which was read, as reader::next_value would have left it.
Returns
The created instance; otherwise a std::unexpected carrying the ast_node_type actually found when the failure was a type mismatch, or ast_node_type::error otherwise.

Implements jsonv::adapter_for< T >.

Definition at line 113 of file adapter_for.hpp.

+ Here is the call graph for this function:

◆ serialize()

template<typename T >
virtual void jsonv::value_adapter_for< T >::serialize ( const serialization_context &  context,
const T &  from,
writer &  to 
) const
inlinefinaloverrideprotectedvirtual

Write from into to.

See also
serializer::serialize

Implements jsonv::adapter_for< T >.

Definition at line 139 of file adapter_for.hpp.

+ Here is the call graph for this function:

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