nomlib
Loading...
Searching...
No Matches
JsonCppDeserializer.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. 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
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON 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
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_SERIALIZERS_JSONCPP_DESERIALIZER_HPP
30#define NOMLIB_SERIALIZERS_JSONCPP_DESERIALIZER_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/IValueDeserializer.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_DESERIALIZER_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.
48namespace Json {
49
50class Value;
51
52} // namespace Json
53
54namespace nom {
55
58class NOM_EXPORT JsonCppDeserializer: public IValueDeserializer
59{
60 public:
66
69
73 JsonCppDeserializer( uint32 options );
74
83 Value deserialize( const std::string& source );
84
92 bool load( const std::string& filename, Value& output );
93
94 private:
95 uint32 options_;
96
97 bool read( const Json::Value& source, Value& dest ) const;
98
100 bool read_value( const Json::Value& object, Value& dest ) const;
101
105 bool read_array( const Json::Value& object, Value& dest ) const;
106
110 bool read_object( const Json::Value& object, Value& dest ) const;
111};
112
113NOM_EXPORT
114std::unique_ptr<IValueDeserializer> make_unique_json_deserializer();
115
116} // namespace nom
117
118#endif // include guard defined
119
bool read_array(const Json::Value &object, Value &dest) const
Internal helper method for un-serialization of array nodes.
bool load(const std::string &filename, Value &output)
Convenience method provided to store JSON-formatted data from a file.
~JsonCppDeserializer(void)
Destructor.
bool read_object(const Json::Value &object, Value &dest) const
Internal helper method for un-serialization of object nodes.
JsonCppDeserializer(uint32 options)
Construct a parser with a feature set enumeration.
Value deserialize(const std::string &source)
Parse JSON data as a nom::Value object.
bool read_value(const Json::Value &object, Value &dest) const
JsonCppDeserializer(void)
Default constructor; initialize the parser to strict mode compliance.
Generic interface for opaque data containers.
Definition Value.hpp:44