JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
extractor_construction.hpp
Go to the documentation of this file.
1/// \file jsonv/serialization/extractor_construction.hpp
2///
3/// Copyright (c) 2015-2020 by Travis Gockel. All rights reserved.
4///
5/// This program is free software: you can redistribute it and/or modify it under the terms of the Apache License
6/// as published by the Apache Software Foundation, either version 2 of the License, or (at your option) any later
7/// version.
8///
9/// \author Travis Gockel (travis@gockelhut.com)
10#pragma once
11
12#include <jsonv/config.hpp>
14
15namespace jsonv
16{
17
18/// \addtogroup Serialization
19/// \{
20
21/// An \c extractor for type \c T that has a constructor that accepts either a \c jsonv::value or a \c jsonv::value and
22/// \c extraction_context.
23template <typename T>
25 public extractor
26{
27public:
28 virtual const std::type_info& get_type() const override
29 {
30 return typeid(T);
31 }
32
33 virtual void extract(const extraction_context& context,
34 const value& from,
35 void* into
36 ) const override
37 {
39 }
40
41protected:
42 template <typename U>
43 auto extract_impl(const extraction_context& context,
44 const value& from,
45 void* into
46 ) const
47 -> decltype(U(from, context), void())
48 {
49 new(into) U(from, context);
50 }
51
52 template <typename U, typename = void>
53 auto extract_impl(const extraction_context&,
54 const value& from,
55 void* into
56 ) const
57 -> decltype(U(from), void())
58 {
59 new(into) U(from);
60 }
61};
62
63/// \}
64
65}
An adapter for enumeration types.
An extractor for type T that has a constructor that accepts either a jsonv::value or a jsonv::value a...
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.
An extractor holds the method for converting JSON source into an arbitrary C++ type.
Represents a single JSON value, which can be any one of a potential kind, each behaving slightly diff...
Definition value.hpp:107
Copyright (c) 2014-2020 by Travis Gockel.
Conversion between C++ types and JSON values.