JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
jsonv::function_adapter< T, FDeserialize, FSerialize > Class Template Reference

An adapter which calls one function to deserialize and another to serialize. More...

#include <jsonv/serialization/function_adapter.hpp>

+ Inheritance diagram for jsonv::function_adapter< T, FDeserialize, FSerialize >:
+ Collaboration diagram for jsonv::function_adapter< T, FDeserialize, FSerialize >:

Public Member Functions

template<typename FUDeserialize , typename FUSerialize >
 function_adapter (FUDeserialize &&deserialize_, FUSerialize &&serialize_)
 Create an adapter which deserializes by calling deserialize_ and serializes by calling serialize_.
 
- 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
 

Protected Member Functions

virtual std::expected< T, ast_node_type > create (deserialization_context &context, reader &from) const override
 Create an instance of T by reading from.
 
virtual void serialize (const serialization_context &context, const T &from, writer &to) const override
 Write from into to.
 

Detailed Description

template<typename T, typename FDeserialize, typename FSerialize>
class jsonv::function_adapter< T, FDeserialize, FSerialize >

An adapter which calls one function to deserialize and another to serialize.

The functions may take any of the shapes detail::invoke_deserialize and detail::invoke_serialize accept.

Definition at line 31 of file function_adapter.hpp.

Constructor & Destructor Documentation

◆ function_adapter()

template<typename T , typename FDeserialize , typename FSerialize >
template<typename FUDeserialize , typename FUSerialize >
jsonv::function_adapter< T, FDeserialize, FSerialize >::function_adapter ( FUDeserialize &&  deserialize_,
FUSerialize &&  serialize_ 
)
inlineexplicit

Create an adapter which deserializes by calling deserialize_ and serializes by calling serialize_.

Definition at line 37 of file function_adapter.hpp.

Member Function Documentation

◆ create()

template<typename T , typename FDeserialize , typename FSerialize >
virtual std::expected< T, ast_node_type > jsonv::function_adapter< T, FDeserialize, FSerialize >::create ( deserialization_context &  context,
reader &  from 
) const
inlineoverrideprotectedvirtual

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 44 of file function_adapter.hpp.

◆ serialize()

template<typename T , typename FDeserialize , typename FSerialize >
virtual void jsonv::function_adapter< T, FDeserialize, FSerialize >::serialize ( const serialization_context &  context,
const T &  from,
writer &  to 
) const
inlineoverrideprotectedvirtual

Write from into to.

See also
serializer::serialize

Implements jsonv::adapter_for< T >.

Definition at line 49 of file function_adapter.hpp.


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