JSON Voorhees
Killer JSON for C++
Main Page
Related Pages
Modules
Classes
Files
Examples
File List
File Members
serialization_optional.hpp
Go to the documentation of this file.
1
/** \file jsonv/serialization_optional.hpp
2
* Template specialization to support optional<T> serialization.
3
* These are usually not needed unless you are writing your own
4
* \c extractor or \c serializer.
5
*
6
* Copyright (c) 2015 by Travis Gockel. All rights reserved.
7
*
8
* This program is free software: you can redistribute it and/or modify it under the terms of the Apache License
9
* as published by the Apache Software Foundation, either version 2 of the License, or (at your option) any later
10
* version.
11
*
12
* \author Vladimir Venediktov (vvenedict@gmail.com)
13
**/
14
15
#ifndef __JSONV_SERIALIZATION_OPTIONAL_HPP_INCLUDED__
16
#define __JSONV_SERIALIZATION_OPTIONAL_HPP_INCLUDED__
17
18
#include <
jsonv/serialization_util.hpp
>
19
#include <
jsonv/optional.hpp
>
20
21
22
namespace
jsonv
23
{
24
25
//specialization for optional<T>
26
template
<
typename
T>
27
class
container_adapter
<
optional
<T>> :
28
public
adapter_for
<optional<T>>
29
{
30
using
element_type =
optional<T>
;
31
32
protected
:
33
virtual
optional<T>
create(
const
extraction_context
& context,
const
value
& from)
const override
34
{
35
optional<T>
out;
36
if
(from.
is_null
()) {
37
return
out;
38
}
39
out = context.
extract
<T>(from);
40
return
out;
41
}
42
43
virtual
value
to_json(
const
serialization_context
& context,
const
optional<T>
& from)
const override
44
{
45
value
out;
46
if
(from) {
47
out = context.
to_json
(*from);
48
}
49
return
out;
50
}
51
};
52
53
}
54
55
#endif
56
jsonv::container_adapter
An adapter for container types.
Definition:
serialization_util.hpp:372
jsonv::serialization_context
Definition:
serialization.hpp:636
optional.hpp
Pulls in an implementation of optional.
jsonv::value::is_null
bool is_null() const
Tests if this kind is kind::null.
serialization_util.hpp
Helper types and functions for serialization.
jsonv::extraction_context
Definition:
serialization.hpp:541
jsonv::adapter_for
Definition:
serialization_util.hpp:218
jsonv
Definition:
algorithm.hpp:23
jsonv::optional
JSONV_OPTIONAL_TYPE< T > optional
Represents a value that may or may not be present.
Definition:
optional.hpp:87
jsonv::serialization_context::to_json
value to_json(const T &from) const
Convenience function for converting a C++ object into a JSON value.
Definition:
serialization.hpp:656
jsonv::extraction_context::extract
T extract(const value &from) const
Attempt to extract a T from from using the formats associated with this context.
Definition:
serialization.hpp:572
jsonv::value
Represents a single JSON value, which can be any one of a potential kind, each behaving slightly diff...
Definition:
value.hpp:131
jsonv
serialization_optional.hpp
Generated by
1.8.11