|
JSON Voorhees
Killer JSON for C++
|
An adapter which can create polymorphic types. More...
#include <jsonv/serialization/polymorphic_adapter.hpp>
Inheritance diagram for jsonv::polymorphic_adapter< TPointer >:
Collaboration diagram for jsonv::polymorphic_adapter< TPointer >: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. | |
| 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. | |
| void | check_null_input (bool on) |
| bool | check_null_input () const |
| void | check_null_output (bool on) |
| } | |
| 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. | |
| 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. | |
| 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. | |
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 56 of file polymorphic_adapter.hpp.
| using jsonv::polymorphic_adapter< TPointer >::match_predicate = std::function<bool (const extraction_context&, const value&)> |
Definition at line 60 of file polymorphic_adapter.hpp.
|
inline |
Add a subtype which can be transformed into TPointer which will be called if the discriminator pred is matched.
Definition at line 70 of file polymorphic_adapter.hpp.
Here is the call graph for this function:
|
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 85 of file polymorphic_adapter.hpp.
Here is the call graph for this function:
|
inline |
Definition at line 112 of file polymorphic_adapter.hpp.
|
inline |
When extracting a C++ value, should kind::null in JSON automatically become a default-constructed TPointer (which is usually the null representation)?
Definition at line 107 of file polymorphic_adapter.hpp.
|
inline |
Definition at line 125 of file polymorphic_adapter.hpp.
|
inline |
}
When converting with to_json, should a null input translate into a kind::null?
Definition at line 120 of file polymorphic_adapter.hpp.
|
inlineoverrideprotectedvirtual |
Implements jsonv::adapter_for< TPointer >.
Definition at line 132 of file polymorphic_adapter.hpp.
|
inlineoverrideprotectedvirtual |
Implements jsonv::adapter_for< TPointer >.
Definition at line 154 of file polymorphic_adapter.hpp.