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>
14
15#include "serializer_for.hpp"
16
17namespace jsonv
18{
19
20/// \addtogroup Serialization
21/// \{
22
23template <typename T, typename FToJson>
25 public serializer_for<T>
26{
27public:
28 template <typename FUToJson>
30 _to_json(std::forward<FUToJson>(to_json_))
31 { }
32
33protected:
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
40private:
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
55private:
56 FToJson _to_json;
57};
58
59template <typename T, typename FToJson>
61{
63}
64
65/// \}
66
67}
An adapter for enumeration types.
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.
Copyright (c) 2015-2020 by Travis Gockel.