17#include <jsonv/version.hpp>
37class extraction_context;
38class serialization_context;
55 public std::invalid_argument
62 const std::type_index& type_index()
const {
return _type_index; }
65 std::type_index _type_index;
70 public std::runtime_error
111 std::string _message;
112 std::exception_ptr _cause;
115 using problem_list = std::vector<problem>;
147 template <
typename...
TArgs>
151 problem_list _problems;
156 public std::runtime_error
174 std::type_index _type_index;
175 std::
string _type_name;
196 std::type_index _type_index;
197 std::
string _type_name;
204 using size_type = extraction_error::problem_list::size_type;
265 on_error _failure_mode = on_error::fail_immediately;
266 size_type _max_failures = 10U;
267 duplicate_key_action _on_duplicate_key = duplicate_key_action::replace;
278 virtual const std::type_info&
get_type()
const = 0;
304 virtual const std::type_info&
get_type()
const = 0;
384 using list = std::vector<formats>;
598 const void* _user_data;
630 template <
typename T>
633 alignas(T)
unsigned char place[
sizeof(T)];
635 T* ptr = std::launder(
reinterpret_cast<T*
>(
place));
636 auto destroy = detail::on_scope_exit([ptr] { std::destroy_at(ptr); });
637 return std::move(*ptr);
640 void extract(
const std::type_info& type,
651 template <
typename T>
654 alignas(T)
unsigned char place[
sizeof(T)];
655 extract_sub(
typeid(T),
from, std::move(
subpath),
static_cast<void*
>(
place));
656 T* ptr = std::launder(
reinterpret_cast<T*
>(
place));
657 auto destroy = detail::on_scope_exit([ptr] { std::destroy_at(ptr); });
658 return std::move(*ptr);
669 template <
typename T>
716 return to_json(
typeid(T),
static_cast<const void*
>(&
from));
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.
An adapter is both an extractor and a serializer.
Provides extra information to routines used for extraction.
context_base()
Create a new instance using the default formats (formats::global).
const jsonv::version version() const
Get the version this extraction_context was created with.
context_base(jsonv::formats fmt, const jsonv::version &ver=jsonv::version(1), const void *userdata=nullptr)
Create a new instance using the given fmt, ver and p.
const void * user_data() const
Get a pointer to arbitrary user data.
Exception thrown if an insertion of an extractor or serializer into a formats is attempted,...
An adapter for enumeration types.
Thrown when formats::to_json does not have a serializer for the provided type.
no_serializer(const std::type_info &type)
Create a new exception.
Represents an exact path in some JSON structure.
value to_json(const std::type_info &type, const void *from) const
Dynamically convert a type into a JSON value.
serialization_context()
Create a new instance using the default formats (formats::global).
serialization_context(jsonv::formats fmt, const jsonv::version &ver=jsonv::version(), const void *userdata=nullptr)
Create a new instance using the given fmt and ver.
A serializer holds the method for converting an arbitrary C++ type into a value.
virtual value to_json(const serialization_context &context, const void *from) const =0
Create a value from the value in the given region of memory.
virtual const std::type_info & get_type() const =0
Get the run-time type this serialize knows how to encode.
Represents a single JSON value, which can be any one of a potential kind, each behaving slightly diff...
Copyright (c) 2014-2020 by Travis Gockel.
#define JSONV_PUBLIC
This function or class is part of the public API for JSON Voorhees.
duplicate_type_action
The action to take when an insertion of an extractor or serializer into a formats is attempted,...
T extract(const value &from, const formats &fmts)
Extract a C++ value from from using the provided fmts.
value to_json(const T &from, const formats &fmts)
Encode a JSON value from from using the provided fmts.
@ exception
A duplicate_type_error should be thrown.
@ ignore
The existing extractor or serializer should be kept, but no exception should be thrown.
@ replace
The new extractor or serializer should be inserted, and no exception should be thrown.
Definition of the on_scope_exit utility.
std::string_view string_view
A non-owning reference to a string.
Represents a version used to extract and encode JSON objects from C++ classes.
Copyright (c) 2012-2020 by Travis Gockel.