JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
jsonv::optional_adapter< TOptional > Class Template Reference

An adapter for optional-like types. More...

#include <jsonv/serialization/optional_adapter.hpp>

+ Inheritance diagram for jsonv::optional_adapter< TOptional >:
+ Collaboration diagram for jsonv::optional_adapter< TOptional >:

Protected Member Functions

virtual std::expected< TOptional, 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 TOptional &from, writer &to) const override
 Write from into to.
 

Additional Inherited Members

- Public Member Functions inherited from jsonv::adapter_for< TOptional >
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 TOptional>
class jsonv::optional_adapter< TOptional >

An adapter for optional-like types.

This is for convenience of creating an adapter for things like std::optional or boost::optional.

Template Parameters
TOptionalThe optional container type. It must have a member type named value_type which holds the actual type. It must default-construct to the "none" type and have a single-argument constructor which takes a TOptional::value_type. It must support a boolean conversion operator for checking if the value is none and a unary operator* for getting the underlying value. Both std::optional and boost::optional possess all of these properties.

Definition at line 39 of file optional_adapter.hpp.

Member Function Documentation

◆ create()

template<typename TOptional >
virtual std::expected< TOptional, ast_node_type > jsonv::optional_adapter< TOptional >::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< TOptional >.

Definition at line 47 of file optional_adapter.hpp.

+ Here is the call graph for this function:

◆ serialize()

template<typename TOptional >
virtual void jsonv::optional_adapter< TOptional >::serialize ( const serialization_context &  context,
const TOptional &  from,
writer &  to 
) const
inlineoverrideprotectedvirtual

Write from into to.

See also
serializer::serialize

Implements jsonv::adapter_for< TOptional >.

Definition at line 82 of file optional_adapter.hpp.

+ Here is the call graph for this function:

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