JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
function_serializer.hpp
Go to the documentation of this file.
1
/// \file jsonv/serialization/function_serializer.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
>
13
#include <
jsonv/serialization.hpp
>
14
15
#include "
serializer_for.hpp
"
16
17
namespace
jsonv
18
{
19
20
/// \addtogroup Serialization
21
/// \{
22
23
template
<
typename
T,
typename
FToJson>
24
class
function_serializer
:
25
public
serializer_for
<T>
26
{
27
public
:
28
template
<
typename
FUToJson>
29
explicit
function_serializer
(
FUToJson
&&
to_json_
) :
30
_to_json(std::forward<FUToJson>(
to_json_
))
31
{ }
32
33
protected
:
34
35
virtual
value
to_json(
const
serialization_context
&
context
,
const
T&
from
)
const override
36
{
37
return
to_json_impl(_to_json,
context
,
from
);
38
}
39
40
private
:
41
template
<
typename
FUToJson>
42
static
auto
to_json_impl(
const
FUToJson
&
func
,
const
serialization_context
&
context
,
const
T&
from
)
43
->
decltype
(
func
(
context
,
from
))
44
{
45
return
func
(
context
,
from
);
46
}
47
48
template
<
typename
FUToJson,
typename
=
void
>
49
static
auto
to_json_impl(
const
FUToJson
&
func
,
const
serialization_context
&,
const
T&
from
)
50
->
decltype
(
func
(
from
))
51
{
52
return
func
(
from
);
53
}
54
55
private
:
56
FToJson
_to_json;
57
};
58
59
template
<
typename
T,
typename
FToJson>
60
function_serializer<T, FToJson>
make_serializer(
FToJson
to_json_
)
61
{
62
return
function_serializer<T, FToJson>
(std::move(
to_json_
));
63
}
64
65
/// \}
66
67
}
jsonv::enum_adapter
An adapter for enumeration types.
Definition
enum_adapter.hpp:41
jsonv::function_serializer
Definition
function_serializer.hpp:26
jsonv::serialization_context
Definition
serialization.hpp:697
jsonv::serializer_for
Definition
serializer_for.hpp:24
jsonv::value
Represents a single JSON value, which can be any one of a potential kind, each behaving slightly diff...
Definition
value.hpp:107
config.hpp
Copyright (c) 2014-2020 by Travis Gockel.
serialization.hpp
Conversion between C++ types and JSON values.
serializer_for.hpp
Copyright (c) 2015-2020 by Travis Gockel.
jsonv
serialization
function_serializer.hpp
Generated by
1.9.8