JSON Voorhees
Killer JSON for C++
|
An adapter which can create polymorphic types. More...
#include <jsonv/serialization_util.hpp>
Public Types | |
using | match_predicate = std::function< bool(const extraction_context &, const value &)> |
Public Member Functions | |
template<typename T > | |
void | add_subtype (match_predicate pred) |
Add a subtype which can be transformed into TPointer which will be called if the discriminator pred is matched. More... | |
template<typename T > | |
void | add_subtype_keyed (std::string key, value expected_value, keyed_subtype_action action=keyed_subtype_action::none) |
Add a subtype which can be transformed into TPointer which will be called if given a JSON value with kind::object which has a member with key and the provided expected_value. More... | |
void | check_null_input (bool on) |
When extracting a C++ value, should kind::null in JSON automatically become a default-constructed TPointer (which is usually the null representation)? | |
bool | check_null_input () const |
void | check_null_output (bool on) |
When converting with to_json , should a null input translate into a kind::null ? | |
bool | check_null_output () const |
Public Member Functions inherited from jsonv::adapter_for< TPointer > | |
virtual const std::type_info & | get_type () const override |
Get the run-time type this extractor knows how to extract. More... | |
virtual void | extract (const extraction_context &context, const value &from, void *into) const override |
Extract a the type from a value into a region of memory. More... | |
virtual value | to_json (const serialization_context &context, const void *from) const override |
Create a value from the value in the given region of memory. More... | |
Protected Member Functions | |
virtual TPointer | create (const extraction_context &context, const value &from) const override |
virtual value | to_json (const serialization_context &context, const TPointer &from) const override |
An adapter which can create polymorphic types.
This allows you to parse JSON directly into a type heirarchy without some middle layer.
TPointer | Some pointer-like type (likely unique_ptr or shared_ptr ) you wish to extract values into. It must support operator* , an explicit conversion to bool , construction with a pointer to a subtype of what it contains and default construction. |
Definition at line 559 of file serialization_util.hpp.
|
inline |
Add a subtype which can be transformed into TPointer
which will be called if the discriminator pred is matched.
Definition at line 574 of file serialization_util.hpp.
|
inline |
Add a subtype which can be transformed into TPointer
which will be called if given a JSON value
with kind::object
which has a member with key and the provided expected_value.
Definition at line 590 of file serialization_util.hpp.