nomlib
Toggle main menu visibility
Loading...
Searching...
No Matches
include
nomlib
serializers
JsonCppSerializer.hpp
1
/******************************************************************************
2
3
nomlib - C++11 cross-platform game engine
4
5
Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6
All rights reserved.
7
8
Redistribution and use in source and binary forms, with or without
9
modification, are permitted provided that the following conditions are met:
10
11
1. Redistributions of source code must retain the above copyright notice, this
12
list of conditions and the following disclaimer.
13
2. Redistributions in binary form must reproduce the above copyright notice,
14
this list of conditions and the following disclaimer in the documentation
15
and/or other materials provided with the distribution.
16
17
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28
******************************************************************************/
29
#ifndef NOMLIB_SERIALIZERS_JSONCPP_SERIALIZER_HPP
30
#define NOMLIB_SERIALIZERS_JSONCPP_SERIALIZER_HPP
31
32
#include <sstream>
33
#include <fstream>
34
35
#include "export.hpp"
36
#include "nomlib/config.hpp"
37
#include "nomlib/serializers/serializers_config.hpp"
38
#include "nomlib/serializers/IValueSerializer.hpp"
39
#include "nomlib/ptree.hpp"
40
41
// Enable dumping output of each key, value pair, sizes, etc. as we
42
// traverse the object.
43
// #define NOM_DEBUG_JSONCPP_SERIALIZER_VALUES
44
45
// Forward declarations for third-party libraries used; these allow us to not
46
// worry about including third-party header files in outside-project builds,
47
// such as is the case with TTcards.
48
namespace
Json {
49
50
class
Value;
51
52
}
// namespace Json
53
54
namespace
nom {
55
59
NOM_NO_EXPORT
const
std::string JSONCPP_INDENTION_LEVEL =
" "
;
60
63
class
NOM_EXPORT
JsonCppSerializer
:
public
IValueSerializer
64
{
65
public
:
66
typedef
JsonCppSerializer
SelfType;
67
72
JsonCppSerializer
(
void
);
73
75
~JsonCppSerializer
(
void
);
76
78
JsonCppSerializer
(
enum
SerializerOptions options );
79
88
std::string
serialize
(
const
Value
& source );
89
100
bool
save
(
const
Value
& source,
const
std::string& filename );
101
102
private
:
103
enum
SerializerOptions options_;
104
105
bool
write(
const
Value
& source, Json::Value& dest )
const
;
106
108
bool
write_value
(
const
Value
&
object
, Json::Value& dest )
const
;
109
111
bool
write_array_value
(
const
Value
&
object
, Json::Value& dest )
const
;
112
116
bool
write_array
(
const
Value
&
object
, Json::Value& dest )
const
;
117
121
bool
write_object
(
const
Value
&
object
, Json::Value& dest )
const
;
122
};
123
124
NOM_EXPORT std::unique_ptr<IValueSerializer> make_unique_json_serializer();
125
126
}
// namespace nom
127
128
#endif
// include guard defined
129
nom::JsonCppSerializer::write_object
bool write_object(const Value &object, Json::Value &dest) const
Internal helper method for serialization of object nodes.
nom::JsonCppSerializer::save
bool save(const Value &source, const std::string &filename)
Convenience method provided to output JSON-formatted data to a file.
nom::JsonCppSerializer::serialize
std::string serialize(const Value &source)
Output a nom::Value object to a string.
nom::JsonCppSerializer::write_value
bool write_value(const Value &object, Json::Value &dest) const
nom::JsonCppSerializer::JsonCppSerializer
JsonCppSerializer(enum SerializerOptions options)
Construct a parser with a feature set enumeration.
nom::JsonCppSerializer::write_array_value
bool write_array_value(const Value &object, Json::Value &dest) const
nom::JsonCppSerializer::JsonCppSerializer
JsonCppSerializer(void)
Default constructor; initialize the writer with human friendly output.
nom::JsonCppSerializer::write_array
bool write_array(const Value &object, Json::Value &dest) const
Internal helper method for serialization of array nodes.
nom::JsonCppSerializer::~JsonCppSerializer
~JsonCppSerializer(void)
Destructor.
nom::Value
Generic interface for opaque data containers.
Definition
Value.hpp:44
Generated on
for nomlib by
1.18.0