RavEngine
Loading...
Searching...
No Matches
json.h
1
3
4// //////////////////////////////////////////////////////////////////////
5// Beginning of content of file: LICENSE
6// //////////////////////////////////////////////////////////////////////
7
8/*
9The JsonCpp library's source code, including accompanying documentation,
10tests and demonstration applications, are licensed under the following
11conditions...
12
13The author (Baptiste Lepilleur) explicitly disclaims copyright in all
14jurisdictions which recognize such a disclaimer. In such jurisdictions,
15this software is released into the Public Domain.
16
17In jurisdictions which do not recognize Public Domain property (e.g. Germany as of
182010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is
19released under the terms of the MIT License (see below).
20
21In jurisdictions which recognize Public Domain property, the user of this
22software may choose to accept it either as 1) Public Domain, 2) under the
23conditions of the MIT License (see below), or 3) under the terms of dual
24Public Domain/MIT License conditions described here, as they choose.
25
26The MIT License is about as close to Public Domain as a license can get, and is
27described in clear, concise terms at:
28
29 http://en.wikipedia.org/wiki/MIT_License
30
31The full text of the MIT License follows:
32
33========================================================================
34Copyright (c) 2007-2010 Baptiste Lepilleur
35
36Permission is hereby granted, free of charge, to any person
37obtaining a copy of this software and associated documentation
38files (the "Software"), to deal in the Software without
39restriction, including without limitation the rights to use, copy,
40modify, merge, publish, distribute, sublicense, and/or sell copies
41of the Software, and to permit persons to whom the Software is
42furnished to do so, subject to the following conditions:
43
44The above copyright notice and this permission notice shall be
45included in all copies or substantial portions of the Software.
46
47THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
51BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
52ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
53CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
54SOFTWARE.
55========================================================================
56(END LICENSE TEXT)
57
58The MIT license is compatible with both the GPL and commercial
59software, affording one all of the rights of Public Domain with the
60minor nuisance of being required to keep the above copyright notice
61and license text in the source code. Note also that by accepting the
62Public Domain "license" you can re-license your copy using whatever
63license you like.
64
65*/
66
67// //////////////////////////////////////////////////////////////////////
68// End of content of file: LICENSE
69// //////////////////////////////////////////////////////////////////////
70
71
72
73
74
75#ifndef JSON_AMALGATED_H_INCLUDED
76# define JSON_AMALGATED_H_INCLUDED
79#define JSON_IS_AMALGAMATION
80
81// //////////////////////////////////////////////////////////////////////
82// Beginning of content of file: include/json/version.h
83// //////////////////////////////////////////////////////////////////////
84
85// DO NOT EDIT. This file (and "version") is generated by CMake.
86// Run CMake configure step to update it.
87#ifndef JSON_VERSION_H_INCLUDED
88# define JSON_VERSION_H_INCLUDED
89
90# define JSONCPP_VERSION_STRING "0.10.6"
91# define JSONCPP_VERSION_MAJOR 0
92# define JSONCPP_VERSION_MINOR 10
93# define JSONCPP_VERSION_PATCH 6
94# define JSONCPP_VERSION_QUALIFIER
95# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))
96
97#endif // JSON_VERSION_H_INCLUDED
98
99// //////////////////////////////////////////////////////////////////////
100// End of content of file: include/json/version.h
101// //////////////////////////////////////////////////////////////////////
102
103
104
105
106
107
108// //////////////////////////////////////////////////////////////////////
109// Beginning of content of file: include/json/config.h
110// //////////////////////////////////////////////////////////////////////
111
112// Copyright 2007-2010 Baptiste Lepilleur
113// Distributed under MIT license, or public domain if desired and
114// recognized in your jurisdiction.
115// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
116
117#ifndef JSON_CONFIG_H_INCLUDED
118#define JSON_CONFIG_H_INCLUDED
119
121//# define JSON_IN_CPPTL 1
122
124//# define JSON_USE_CPPTL 1
128//# define JSON_USE_CPPTL_SMALLMAP 1
129
130// If non-zero, the library uses exceptions to report bad input instead of C
131// assertion macros. The default is to use exceptions.
132#ifndef JSON_USE_EXCEPTION
133#define JSON_USE_EXCEPTION 1
134#endif
135
139// #define JSON_IS_AMALGAMATION
140
141#ifdef JSON_IN_CPPTL
142#include <cpptl/config.h>
143#ifndef JSON_USE_CPPTL
144#define JSON_USE_CPPTL 1
145#endif
146#endif
147
148#ifdef JSON_IN_CPPTL
149#define JSON_API CPPTL_API
150#elif defined(JSON_DLL_BUILD)
151#if defined(_MSC_VER)
152#define JSON_API __declspec(dllexport)
153#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
154#endif // if defined(_MSC_VER)
155#elif defined(JSON_DLL)
156#if defined(_MSC_VER)
157#define JSON_API __declspec(dllimport)
158#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
159#endif // if defined(_MSC_VER)
160#endif // ifdef JSON_IN_CPPTL
161#if !defined(JSON_API)
162#define JSON_API
163#endif
164
165#if !defined(JSON_HAS_UNIQUE_PTR)
166#if __cplusplus >= 201103L
167#define JSON_HAS_UNIQUE_PTR (1)
168#elif _MSC_VER >= 1600
169#define JSON_HAS_UNIQUE_PTR (1)
170#else
171#define JSON_HAS_UNIQUE_PTR (0)
172#endif
173#endif
174
175// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for
176// integer
177// Storages, and 64 bits integer support is disabled.
178// #define JSON_NO_INT64 1
179
180#if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC 6
181// Microsoft Visual Studio 6 only support conversion from __int64 to double
182// (no conversion from unsigned __int64).
183#define JSON_USE_INT64_DOUBLE_CONVERSION 1
184// Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255'
185// characters in the debug information)
186// All projects I've ever seen with VS6 were using this globally (not bothering
187// with pragma push/pop).
188#pragma warning(disable : 4786)
189#endif // if defined(_MSC_VER) && _MSC_VER < 1200 // MSVC 6
190
191#if defined(_MSC_VER) && _MSC_VER >= 1500 // MSVC 2008
193#define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
194#elif defined(__clang__) && defined(__has_feature)
195#if __has_feature(attribute_deprecated_with_message)
196#define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))
197#endif
198#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
199#define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))
200#elif defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
201#define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
202#endif
203
204#if !defined(JSONCPP_DEPRECATED)
205#define JSONCPP_DEPRECATED(message)
206#endif // if !defined(JSONCPP_DEPRECATED)
207
208namespace Json {
209typedef int Int;
210typedef unsigned int UInt;
211#if defined(JSON_NO_INT64)
212typedef int LargestInt;
213typedef unsigned int LargestUInt;
214#undef JSON_HAS_INT64
215#else // if defined(JSON_NO_INT64)
216// For Microsoft Visual use specific types as long long is not supported
217#if defined(_MSC_VER) // Microsoft Visual Studio
218typedef __int64 Int64;
219typedef unsigned __int64 UInt64;
220#else // if defined(_MSC_VER) // Other platforms, use long long
221typedef long long int Int64;
222typedef unsigned long long int UInt64;
223#endif // if defined(_MSC_VER)
224typedef Int64 LargestInt;
225typedef UInt64 LargestUInt;
226#define JSON_HAS_INT64
227#endif // if defined(JSON_NO_INT64)
228} // end namespace Json
229
230#endif // JSON_CONFIG_H_INCLUDED
231
232// //////////////////////////////////////////////////////////////////////
233// End of content of file: include/json/config.h
234// //////////////////////////////////////////////////////////////////////
235
236
237
238
239
240
241// //////////////////////////////////////////////////////////////////////
242// Beginning of content of file: include/json/forwards.h
243// //////////////////////////////////////////////////////////////////////
244
245// Copyright 2007-2010 Baptiste Lepilleur
246// Distributed under MIT license, or public domain if desired and
247// recognized in your jurisdiction.
248// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
249
250#ifndef JSON_FORWARDS_H_INCLUDED
251#define JSON_FORWARDS_H_INCLUDED
252
253#if !defined(JSON_IS_AMALGAMATION)
254#include "config.h"
255#endif // if !defined(JSON_IS_AMALGAMATION)
256
257namespace Json {
258
259// writer.h
260class FastWriter;
261class StyledWriter;
262
263// reader.h
264class Reader;
265
266// features.h
267class Features;
268
269// value.h
270typedef unsigned int ArrayIndex;
271class StaticString;
272class Path;
273class PathArgument;
274class Value;
275class ValueIteratorBase;
276class ValueIterator;
277class ValueConstIterator;
278
279} // namespace Json
280
281#endif // JSON_FORWARDS_H_INCLUDED
282
283// //////////////////////////////////////////////////////////////////////
284// End of content of file: include/json/forwards.h
285// //////////////////////////////////////////////////////////////////////
286
287
288
289
290
291
292// //////////////////////////////////////////////////////////////////////
293// Beginning of content of file: include/json/features.h
294// //////////////////////////////////////////////////////////////////////
295
296// Copyright 2007-2010 Baptiste Lepilleur
297// Distributed under MIT license, or public domain if desired and
298// recognized in your jurisdiction.
299// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
300
301#ifndef CPPTL_JSON_FEATURES_H_INCLUDED
302#define CPPTL_JSON_FEATURES_H_INCLUDED
303
304#if !defined(JSON_IS_AMALGAMATION)
305#include "forwards.h"
306#endif // if !defined(JSON_IS_AMALGAMATION)
307
308namespace Json {
309
314class JSON_API Features {
315public:
322 static Features all();
323
330 static Features strictMode();
331
334 Features();
335
338
342};
343
344} // namespace Json
345
346#endif // CPPTL_JSON_FEATURES_H_INCLUDED
347
348// //////////////////////////////////////////////////////////////////////
349// End of content of file: include/json/features.h
350// //////////////////////////////////////////////////////////////////////
351
352
353
354
355
356
357// //////////////////////////////////////////////////////////////////////
358// Beginning of content of file: include/json/value.h
359// //////////////////////////////////////////////////////////////////////
360
361// Copyright 2007-2010 Baptiste Lepilleur
362// Distributed under MIT license, or public domain if desired and
363// recognized in your jurisdiction.
364// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
365
366#ifndef CPPTL_JSON_H_INCLUDED
367#define CPPTL_JSON_H_INCLUDED
368
369#if !defined(JSON_IS_AMALGAMATION)
370#include "forwards.h"
371#endif // if !defined(JSON_IS_AMALGAMATION)
372#include <string>
373#include <vector>
374#include <exception>
375
376#ifndef JSON_USE_CPPTL_SMALLMAP
377#include <map>
378#else
379#include <cpptl/smallmap.h>
380#endif
381#ifdef JSON_USE_CPPTL
382#include <cpptl/forwards.h>
383#endif
384
385// Disable warning C4251: <data member>: <type> needs to have dll-interface to
386// be used by...
387#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
388#pragma warning(push)
389#pragma warning(disable : 4251)
390#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
391
392//Conditional NORETURN attribute on the throw functions would:
393// a) suppress false positives from static code analysis
394// b) possibly improve optimization opportunities.
395#if !defined(JSONCPP_NORETURN)
396# if defined(_MSC_VER)
397# define JSONCPP_NORETURN __declspec(noreturn)
398# elif defined(__GNUC__)
399# define JSONCPP_NORETURN __attribute__ ((__noreturn__))
400# else
401# define JSONCPP_NORETURN
402# endif
403#endif
404
407namespace Json {
408
413class JSON_API Exception : public std::exception {
414public:
415 Exception(std::string const& msg);
416 virtual ~Exception() throw();
417 virtual char const* what() const throw();
418protected:
419 void operator = (const Exception&) = delete;
420 std::string const msg_;
421};
422
429class JSON_API RuntimeError : public Exception {
430public:
431 RuntimeError(std::string const& msg);
432};
433
440class JSON_API LogicError : public Exception {
441public:
442 LogicError(std::string const& msg);
443};
444
446JSONCPP_NORETURN void throwRuntimeError(std::string const& msg);
448JSONCPP_NORETURN void throwLogicError(std::string const& msg);
449
462
470
471//# ifdef JSON_USE_CPPTL
472// typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
473// typedef CppTL::AnyEnumerator<const Value &> EnumValues;
474//# endif
475
490class JSON_API StaticString {
491public:
492 explicit StaticString(const char* czstring) : c_str_(czstring) {}
493
494 operator const char*() const { return c_str_; }
495
496 const char* c_str() const { return c_str_; }
497
498private:
499 const char* c_str_;
500};
501
536class JSON_API Value {
537 friend class ValueIteratorBase;
538public:
539 typedef std::vector<std::string> Members;
540 typedef ValueIterator iterator;
542 typedef Json::UInt UInt;
543 typedef Json::Int Int;
544#if defined(JSON_HAS_INT64)
545 typedef Json::UInt64 UInt64;
546 typedef Json::Int64 Int64;
547#endif // defined(JSON_HAS_INT64)
548 typedef Json::LargestInt LargestInt;
549 typedef Json::LargestUInt LargestUInt;
550 typedef Json::ArrayIndex ArrayIndex;
551
552 static const Value& nullRef;
553#if !defined(__ARMEL__)
555 static const Value null;
556#endif
558 static const LargestInt minLargestInt;
560 static const LargestInt maxLargestInt;
562 static const LargestUInt maxLargestUInt;
563
565 static const Int minInt;
567 static const Int maxInt;
569 static const UInt maxUInt;
570
571#if defined(JSON_HAS_INT64)
573 static const Int64 minInt64;
575 static const Int64 maxInt64;
577 static const UInt64 maxUInt64;
578#endif // defined(JSON_HAS_INT64)
579
580//MW: workaround for bug in NVIDIAs CUDA 7.5 nvcc compiler
581#ifdef __NVCC__
582public:
583#else
584private:
585#endif //__NVCC__
586#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
587 class CZString {
588 public:
589 enum DuplicationPolicy {
590 noDuplication = 0,
591 duplicate,
592 duplicateOnCopy
593 };
594 CZString(ArrayIndex index);
595 CZString(char const* str, unsigned length, DuplicationPolicy allocate);
596 CZString(CZString const& other);
597 ~CZString();
598 CZString& operator=(CZString other);
599 bool operator<(CZString const& other) const;
600 bool operator==(CZString const& other) const;
601 ArrayIndex index() const;
602 //const char* c_str() const; ///< \deprecated
603 char const* data() const;
604 unsigned length() const;
605 bool isStaticString() const;
606
607 private:
608 void swap(CZString& other);
609
610 struct StringStorage {
611 unsigned policy_: 2;
612 unsigned length_: 30; // 1GB max
613 };
614
615 char const* cstr_; // actually, a prefixed string, unless policy is noDup
616 union {
617 ArrayIndex index_;
618 StringStorage storage_;
619 };
620 };
621
622public:
623#ifndef JSON_USE_CPPTL_SMALLMAP
624 typedef std::map<CZString, Value> ObjectValues;
625#else
626 typedef CppTL::SmallMap<CZString, Value> ObjectValues;
627#endif // ifndef JSON_USE_CPPTL_SMALLMAP
628#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
629
630public:
646 Value(ValueType type = nullValue);
647 Value(Int value);
648 Value(UInt value);
649#if defined(JSON_HAS_INT64)
650 Value(Int64 value);
651 Value(UInt64 value);
652#endif // if defined(JSON_HAS_INT64)
653 Value(double value);
654 Value(const char* value);
655 Value(const char* begin, const char* end);
671 Value(const StaticString& value);
672 Value(const std::string& value);
673#ifdef JSON_USE_CPPTL
674 Value(const CppTL::ConstString& value);
675#endif
676 Value(bool value);
678 Value(const Value& other);
679 ~Value();
680
683 Value &operator=(const Value &other);
685 void swap(Value& other);
687 void swapPayload(Value& other);
688
689 ValueType type() const;
690
692 bool operator<(const Value& other) const;
693 bool operator<=(const Value& other) const;
694 bool operator>=(const Value& other) const;
695 bool operator>(const Value& other) const;
696 bool operator==(const Value& other) const;
697 bool operator!=(const Value& other) const;
698 int compare(const Value& other) const;
699
700 const char* asCString() const;
701 std::string asString() const;
705 bool getString(
706 char const** begin, char const** end) const;
707#ifdef JSON_USE_CPPTL
708 CppTL::ConstString asConstString() const;
709#endif
710 Int asInt() const;
711 UInt asUInt() const;
712#if defined(JSON_HAS_INT64)
713 Int64 asInt64() const;
714 UInt64 asUInt64() const;
715#endif // if defined(JSON_HAS_INT64)
716 LargestInt asLargestInt() const;
717 LargestUInt asLargestUInt() const;
718 float asFloat() const;
719 double asDouble() const;
720 bool asBool() const;
721
722 bool isNull() const;
723 bool isBool() const;
724 bool isInt() const;
725 bool isInt64() const;
726 bool isUInt() const;
727 bool isUInt64() const;
728 bool isIntegral() const;
729 bool isDouble() const;
730 bool isNumeric() const;
731 bool isString() const;
732 bool isArray() const;
733 bool isObject() const;
734
735 bool isConvertibleTo(ValueType other) const;
736
738 ArrayIndex size() const;
739
742 bool empty() const;
743
745 bool operator!() const;
746
750 void clear();
751
757 void resize(ArrayIndex size);
758
765 Value& operator[](ArrayIndex index);
766
773 Value& operator[](int index);
774
778 const Value& operator[](ArrayIndex index) const;
779
783 const Value& operator[](int index) const;
784
788 Value get(ArrayIndex index, const Value& defaultValue) const;
790 bool isValidIndex(ArrayIndex index) const;
794 Value& append(const Value& value);
795
799 Value& operator[](const char* key);
802 const Value& operator[](const char* key) const;
805 Value& operator[](const std::string& key);
809 const Value& operator[](const std::string& key) const;
822 Value& operator[](const StaticString& key);
823#ifdef JSON_USE_CPPTL
825 Value& operator[](const CppTL::ConstString& key);
828 const Value& operator[](const CppTL::ConstString& key) const;
829#endif
832 Value get(const char* key, const Value& defaultValue) const;
836 Value get(const char* begin, const char* end, const Value& defaultValue) const;
840 Value get(const std::string& key, const Value& defaultValue) const;
841#ifdef JSON_USE_CPPTL
844 Value get(const CppTL::ConstString& key, const Value& defaultValue) const;
845#endif
849 Value const* find(char const* begin, char const* end) const;
853 Value const* demand(char const* begin, char const* end);
861 Value removeMember(const char* key);
865 Value removeMember(const std::string& key);
868 bool removeMember(const char* key, Value* removed);
875 bool removeMember(std::string const& key, Value* removed);
877 bool removeMember(const char* begin, const char* end, Value* removed);
884 bool removeIndex(ArrayIndex i, Value* removed);
885
888 bool isMember(const char* key) const;
891 bool isMember(const std::string& key) const;
893 bool isMember(const char* begin, const char* end) const;
894#ifdef JSON_USE_CPPTL
896 bool isMember(const CppTL::ConstString& key) const;
897#endif
898
904 Members getMemberNames() const;
905
906 //# ifdef JSON_USE_CPPTL
907 // EnumMemberNames enumMemberNames() const;
908 // EnumValues enumValues() const;
909 //# endif
910
912 JSONCPP_DEPRECATED("Use setComment(std::string const&) instead.")
913 void setComment(const char* comment, CommentPlacement placement);
915 void setComment(const char* comment, size_t len, CommentPlacement placement);
917 void setComment(const std::string& comment, CommentPlacement placement);
918 bool hasComment(CommentPlacement placement) const;
920 std::string getComment(CommentPlacement placement) const;
921
922 std::string toStyledString() const;
923
924 const_iterator begin() const;
925 const_iterator end() const;
926
927 iterator begin();
928 iterator end();
929
930 // ozz
931 size_t order() const { return order_; }
932
933private:
934 void initBasic(ValueType type, bool allocated = false);
935
936 Value& resolveReference(const char* key);
937 Value& resolveReference(const char* key, const char* end);
938
939 struct CommentInfo {
940 CommentInfo();
941 ~CommentInfo();
942
943 void setComment(const char* text, size_t len);
944
945 char* comment_;
946 };
947
948 // struct MemberNamesTransform
949 //{
950 // typedef const char *result_type;
951 // const char *operator()( const CZString &name ) const
952 // {
953 // return name.c_str();
954 // }
955 //};
956
957 union ValueHolder {
958 LargestInt int_;
959 LargestUInt uint_;
960 double real_;
961 bool bool_;
962 char* string_; // actually ptr to unsigned, followed by str, unless !allocated_
963 ObjectValues* map_;
964 } value_;
965 ValueType type_ : 8;
966 unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
967 // If not allocated_, string_ must be null-terminated.
968 CommentInfo* comments_;
969
970 // ozz: stores order of insertion.
971 size_t order_;
972};
973
977class JSON_API PathArgument {
978public:
979 friend class Path;
980
981 PathArgument();
982 PathArgument(ArrayIndex index);
983 PathArgument(const char* key);
984 PathArgument(const std::string& key);
985
986private:
987 enum Kind {
988 kindNone = 0,
989 kindIndex,
990 kindKey
991 };
992 std::string key_;
993 ArrayIndex index_;
994 Kind kind_;
995};
996
1008class JSON_API Path {
1009public:
1010 Path(const std::string& path,
1011 const PathArgument& a1 = PathArgument(),
1012 const PathArgument& a2 = PathArgument(),
1013 const PathArgument& a3 = PathArgument(),
1014 const PathArgument& a4 = PathArgument(),
1015 const PathArgument& a5 = PathArgument());
1016
1017 const Value& resolve(const Value& root) const;
1018 Value resolve(const Value& root, const Value& defaultValue) const;
1021 Value& make(Value& root) const;
1022
1023private:
1024 typedef std::vector<const PathArgument*> InArgs;
1025 typedef std::vector<PathArgument> Args;
1026
1027 void makePath(const std::string& path, const InArgs& in);
1028 void addPathInArg(const std::string& path,
1029 const InArgs& in,
1030 InArgs::const_iterator& itInArg,
1031 PathArgument::Kind kind);
1032 void invalidPath(const std::string& path, int location);
1033
1034 Args args_;
1035};
1036
1040class JSON_API ValueIteratorBase {
1041public:
1042 typedef std::bidirectional_iterator_tag iterator_category;
1043 typedef unsigned int size_t;
1044 typedef int difference_type;
1046
1047 bool operator==(const SelfType& other) const { return isEqual(other); }
1048
1049 bool operator!=(const SelfType& other) const { return !isEqual(other); }
1050
1051 difference_type operator-(const SelfType& other) const {
1052 return other.computeDistance(*this);
1053 }
1054
1057 Value key() const;
1058
1060 UInt index() const;
1061
1065 std::string name() const;
1066
1070 JSONCPP_DEPRECATED("Use `key = name();` instead.")
1071 char const* memberName() const;
1075 char const* memberName(char const** end) const;
1076
1077protected:
1078 Value& deref() const;
1079
1080 void increment();
1081
1082 void decrement();
1083
1084 difference_type computeDistance(const SelfType& other) const;
1085
1086 bool isEqual(const SelfType& other) const;
1087
1088 void copy(const SelfType& other);
1089
1090private:
1091 Value::ObjectValues::iterator current_;
1092 // Indicates that iterator is for a null value.
1093 bool isNull_;
1094
1095public:
1096 // For some reason, BORLAND needs these at the end, rather
1097 // than earlier. No idea why.
1099 explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
1100};
1101
1105class JSON_API ValueConstIterator : public ValueIteratorBase {
1106 friend class Value;
1107
1108public:
1109 typedef const Value value_type;
1110 //typedef unsigned int size_t;
1111 //typedef int difference_type;
1112 typedef const Value& reference;
1113 typedef const Value* pointer;
1115
1117
1118private:
1121 explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
1122public:
1123 SelfType& operator=(const ValueIteratorBase& other);
1124
1125 SelfType operator++(int) {
1126 SelfType temp(*this);
1127 ++*this;
1128 return temp;
1129 }
1130
1131 SelfType operator--(int) {
1132 SelfType temp(*this);
1133 --*this;
1134 return temp;
1135 }
1136
1137 SelfType& operator--() {
1138 decrement();
1139 return *this;
1140 }
1141
1142 SelfType& operator++() {
1143 increment();
1144 return *this;
1145 }
1146
1147 reference operator*() const { return deref(); }
1148
1149 pointer operator->() const { return &deref(); }
1150};
1151
1154class JSON_API ValueIterator : public ValueIteratorBase {
1155 friend class Value;
1156
1157public:
1158 typedef Value value_type;
1159 typedef unsigned int size_t;
1160 typedef int difference_type;
1161 typedef Value& reference;
1162 typedef Value* pointer;
1163 typedef ValueIterator SelfType;
1164
1165 ValueIterator();
1166 ValueIterator(const ValueConstIterator& other);
1167 ValueIterator(const ValueIterator& other);
1168
1169private:
1172 explicit ValueIterator(const Value::ObjectValues::iterator& current);
1173public:
1174 SelfType& operator=(const SelfType& other);
1175
1176 SelfType operator++(int) {
1177 SelfType temp(*this);
1178 ++*this;
1179 return temp;
1180 }
1181
1182 SelfType operator--(int) {
1183 SelfType temp(*this);
1184 --*this;
1185 return temp;
1186 }
1187
1188 SelfType& operator--() {
1189 decrement();
1190 return *this;
1191 }
1192
1193 SelfType& operator++() {
1194 increment();
1195 return *this;
1196 }
1197
1198 reference operator*() const { return deref(); }
1199
1200 pointer operator->() const { return &deref(); }
1201};
1202
1203} // namespace Json
1204
1205
1206namespace std {
1208template<>
1209inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); }
1210}
1211
1212
1213#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1214#pragma warning(pop)
1215#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1216
1217#endif // CPPTL_JSON_H_INCLUDED
1218
1219// //////////////////////////////////////////////////////////////////////
1220// End of content of file: include/json/value.h
1221// //////////////////////////////////////////////////////////////////////
1222
1223
1224
1225
1226
1227
1228// //////////////////////////////////////////////////////////////////////
1229// Beginning of content of file: include/json/reader.h
1230// //////////////////////////////////////////////////////////////////////
1231
1232// Copyright 2007-2010 Baptiste Lepilleur
1233// Distributed under MIT license, or public domain if desired and
1234// recognized in your jurisdiction.
1235// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
1236
1237#ifndef CPPTL_JSON_READER_H_INCLUDED
1238#define CPPTL_JSON_READER_H_INCLUDED
1239
1240#if !defined(JSON_IS_AMALGAMATION)
1241#include "features.h"
1242#include "value.h"
1243#endif // if !defined(JSON_IS_AMALGAMATION)
1244#include <deque>
1245#include <iosfwd>
1246#include <stack>
1247#include <string>
1248#include <istream>
1249
1250// Disable warning C4251: <data member>: <type> needs to have dll-interface to
1251// be used by...
1252#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1253#pragma warning(push)
1254#pragma warning(disable : 4251)
1255#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1256
1257namespace Json {
1258
1264class JSON_API Reader {
1265public:
1266 typedef char Char;
1267 typedef const Char* Location;
1268
1272 Reader();
1273
1277 Reader(const Features& features);
1278
1293 bool
1294 parse(const std::string& document, Value& root, bool collectComments = true);
1295
1314 bool parse(const char* beginDoc,
1315 const char* endDoc,
1316 Value& root,
1317 bool collectComments = true);
1318
1321 bool parse(std::istream& is, Value& root, bool collectComments = true);
1322
1332 JSONCPP_DEPRECATED("Use getFormattedErrorMessages() instead.")
1333 std::string getFormatedErrorMessages() const;
1334
1343 std::string getFormattedErrorMessages() const;
1344
1345private:
1346 enum TokenType {
1347 tokenEndOfStream = 0,
1348 tokenObjectBegin,
1349 tokenObjectEnd,
1350 tokenArrayBegin,
1351 tokenArrayEnd,
1352 tokenString,
1353 tokenNumber,
1354 tokenTrue,
1355 tokenFalse,
1356 tokenNull,
1357 tokenArraySeparator,
1358 tokenMemberSeparator,
1359 tokenComment,
1360 tokenError
1361 };
1362
1363 class Token {
1364 public:
1365 TokenType type_;
1366 Location start_;
1367 Location end_;
1368 };
1369
1370 class ErrorInfo {
1371 public:
1372 Token token_;
1373 std::string message_;
1374 Location extra_;
1375 };
1376
1377 typedef std::deque<ErrorInfo> Errors;
1378
1379 bool readToken(Token& token);
1380 void skipSpaces();
1381 bool match(Location pattern, int patternLength);
1382 bool readComment();
1383 bool readCStyleComment();
1384 bool readCppStyleComment();
1385 bool readString();
1386 void readNumber();
1387 bool readValue();
1388 bool readObject(Token& token);
1389 bool readArray(Token& token);
1390 bool decodeNumber(Token& token);
1391 bool decodeNumber(Token& token, Value& decoded);
1392 bool decodeString(Token& token);
1393 bool decodeString(Token& token, std::string& decoded);
1394 bool decodeDouble(Token& token);
1395 bool decodeDouble(Token& token, Value& decoded);
1396 bool decodeUnicodeCodePoint(Token& token,
1397 Location& current,
1398 Location end,
1399 unsigned int& unicode);
1400 bool decodeUnicodeEscapeSequence(Token& token,
1401 Location& current,
1402 Location end,
1403 unsigned int& unicode);
1404 bool addError(const std::string& message, Token& token, Location extra = 0);
1405 bool recoverFromError(TokenType skipUntilToken);
1406 bool addErrorAndRecover(const std::string& message,
1407 Token& token,
1408 TokenType skipUntilToken);
1409 void skipUntilSpace();
1410 Value& currentValue();
1411 Char getNextChar();
1412 void
1413 getLocationLineAndColumn(Location location, int& line, int& column) const;
1414 std::string getLocationLineAndColumn(Location location) const;
1415 void addComment(Location begin, Location end, CommentPlacement placement);
1416 void skipCommentTokens(Token& token);
1417
1418 typedef std::stack<Value*> Nodes;
1419 Nodes nodes_;
1420 Errors errors_;
1421 std::string document_;
1422 Location begin_;
1423 Location end_;
1424 Location current_;
1425 Location lastValueEnd_;
1426 Value* lastValue_;
1427 std::string commentsBefore_;
1428 Features features_;
1429 bool collectComments_;
1430}; // Reader
1431
1434class JSON_API CharReader {
1435public:
1436 virtual ~CharReader() {}
1454 virtual bool parse(
1455 char const* beginDoc, char const* endDoc,
1456 Value* root, std::string* errs) = 0;
1457
1458 class Factory {
1459 public:
1460 virtual ~Factory() {}
1464 virtual CharReader* newCharReader() const = 0;
1465 }; // Factory
1466}; // CharReader
1467
1481public:
1482 // Note: We use a Json::Value so that we can add data-members to this class
1483 // without a major version bump.
1521
1523 virtual ~CharReaderBuilder();
1524
1525 virtual CharReader* newCharReader() const;
1526
1530 bool validate(Json::Value* invalid) const;
1531
1534 Value& operator[](std::string key);
1535
1541 static void setDefaults(Json::Value* settings);
1547 static void strictMode(Json::Value* settings);
1548};
1549
1554bool JSON_API parseFromStream(
1555 CharReader::Factory const&,
1556 std::istream&,
1557 Value* root, std::string* errs);
1558
1583JSON_API std::istream& operator>>(std::istream&, Value&);
1584
1585} // namespace Json
1586
1587#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1588#pragma warning(pop)
1589#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1590
1591#endif // CPPTL_JSON_READER_H_INCLUDED
1592
1593// //////////////////////////////////////////////////////////////////////
1594// End of content of file: include/json/reader.h
1595// //////////////////////////////////////////////////////////////////////
1596
1597
1598
1599
1600
1601
1602// //////////////////////////////////////////////////////////////////////
1603// Beginning of content of file: include/json/writer.h
1604// //////////////////////////////////////////////////////////////////////
1605
1606// Copyright 2007-2010 Baptiste Lepilleur
1607// Distributed under MIT license, or public domain if desired and
1608// recognized in your jurisdiction.
1609// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
1610
1611#ifndef JSON_WRITER_H_INCLUDED
1612#define JSON_WRITER_H_INCLUDED
1613
1614#if !defined(JSON_IS_AMALGAMATION)
1615#include "value.h"
1616#endif // if !defined(JSON_IS_AMALGAMATION)
1617#include <vector>
1618#include <string>
1619#include <ostream>
1620
1621// Disable warning C4251: <data member>: <type> needs to have dll-interface to
1622// be used by...
1623#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1624#pragma warning(push)
1625#pragma warning(disable : 4251)
1626#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1627
1628namespace Json {
1629
1630class Value;
1631
1645class JSON_API StreamWriter {
1646protected:
1647 std::ostream* sout_; // not owned; will not delete
1648public:
1649 StreamWriter();
1650 virtual ~StreamWriter();
1657 virtual int write(Value const& root, std::ostream* sout) = 0;
1658
1661 class JSON_API Factory {
1662 public:
1663 virtual ~Factory();
1667 virtual StreamWriter* newStreamWriter() const = 0;
1668 }; // Factory
1669}; // StreamWriter
1670
1674std::string JSON_API writeString(StreamWriter::Factory const& factory, Value const& root);
1675
1676
1693public:
1694 // Note: We use a Json::Value so that we can add data-members to this class
1695 // without a major version bump.
1718
1720 virtual ~StreamWriterBuilder();
1721
1725 virtual StreamWriter* newStreamWriter() const;
1726
1730 bool validate(Json::Value* invalid) const;
1733 Value& operator[](std::string key);
1734
1740 static void setDefaults(Json::Value* settings);
1741};
1742
1746class JSON_API Writer {
1747public:
1748 virtual ~Writer();
1749
1750 virtual std::string write(const Value& root) = 0;
1751};
1752
1762class JSON_API FastWriter : public Writer {
1763
1764public:
1765 FastWriter();
1766 virtual ~FastWriter() {}
1767
1768 void enableYAMLCompatibility();
1769
1770public: // overridden from Writer
1771 virtual std::string write(const Value& root);
1772
1773private:
1774 void writeValue(const Value& value);
1775
1776 std::string document_;
1777 bool yamlCompatiblityEnabled_;
1778};
1779
1804class JSON_API StyledWriter : public Writer {
1805public:
1806 StyledWriter();
1807 virtual ~StyledWriter() {}
1808
1809public: // overridden from Writer
1814 virtual std::string write(const Value& root);
1815
1816private:
1817 void writeValue(const Value& value);
1818 void writeArrayValue(const Value& value);
1819 bool isMultineArray(const Value& value);
1820 void pushValue(const std::string& value);
1821 void writeIndent();
1822 void writeWithIndent(const std::string& value);
1823 void indent();
1824 void unindent();
1825 void writeCommentBeforeValue(const Value& root);
1826 void writeCommentAfterValueOnSameLine(const Value& root);
1827 bool hasCommentForValue(const Value& value);
1828 static std::string normalizeEOL(const std::string& text);
1829
1830 typedef std::vector<std::string> ChildValues;
1831
1832 ChildValues childValues_;
1833 std::string document_;
1834 std::string indentString_;
1835 int rightMargin_;
1836 int indentSize_;
1837 bool addChildValues_;
1838};
1839
1866class JSON_API StyledStreamWriter {
1867public:
1868 StyledStreamWriter(std::string indentation = "\t");
1870
1871public:
1878 void write(std::ostream& out, const Value& root);
1879
1880private:
1881 void writeValue(const Value& value);
1882 void writeArrayValue(const Value& value);
1883 bool isMultineArray(const Value& value);
1884 void pushValue(const std::string& value);
1885 void writeIndent();
1886 void writeWithIndent(const std::string& value);
1887 void indent();
1888 void unindent();
1889 void writeCommentBeforeValue(const Value& root);
1890 void writeCommentAfterValueOnSameLine(const Value& root);
1891 bool hasCommentForValue(const Value& value);
1892 static std::string normalizeEOL(const std::string& text);
1893
1894 typedef std::vector<std::string> ChildValues;
1895
1896 ChildValues childValues_;
1897 std::ostream* document_;
1898 std::string indentString_;
1899 int rightMargin_;
1900 std::string indentation_;
1901 bool addChildValues_ : 1;
1902 bool indented_ : 1;
1903};
1904
1905#if defined(JSON_HAS_INT64)
1906std::string JSON_API valueToString(Int value);
1907std::string JSON_API valueToString(UInt value);
1908#endif // if defined(JSON_HAS_INT64)
1909std::string JSON_API valueToString(LargestInt value);
1910std::string JSON_API valueToString(LargestUInt value);
1911std::string JSON_API valueToString(double value);
1912std::string JSON_API valueToString(bool value);
1913std::string JSON_API valueToQuotedString(const char* value);
1914
1917JSON_API std::ostream& operator<<(std::ostream&, const Value& root);
1918
1919} // namespace Json
1920
1921#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1922#pragma warning(pop)
1923#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1924
1925#endif // JSON_WRITER_H_INCLUDED
1926
1927// //////////////////////////////////////////////////////////////////////
1928// End of content of file: include/json/writer.h
1929// //////////////////////////////////////////////////////////////////////
1930
1931
1932
1933
1934
1935
1936// //////////////////////////////////////////////////////////////////////
1937// Beginning of content of file: include/json/assertions.h
1938// //////////////////////////////////////////////////////////////////////
1939
1940// Copyright 2007-2010 Baptiste Lepilleur
1941// Distributed under MIT license, or public domain if desired and
1942// recognized in your jurisdiction.
1943// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
1944
1945#ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED
1946#define CPPTL_JSON_ASSERTIONS_H_INCLUDED
1947
1948#include <stdlib.h>
1949#include <sstream>
1950
1951#if !defined(JSON_IS_AMALGAMATION)
1952#include "config.h"
1953#endif // if !defined(JSON_IS_AMALGAMATION)
1954
1959#if JSON_USE_EXCEPTION
1960
1961// @todo <= add detail about condition in exception
1962# define JSON_ASSERT(condition) \
1963 {if (!(condition)) {Json::throwLogicError( "assert json failed" );}}
1964
1965# define JSON_FAIL_MESSAGE(message) \
1966 { \
1967 std::ostringstream oss; oss << message; \
1968 Json::throwLogicError(oss.str()); \
1969 abort(); \
1970 }
1971
1972#else // JSON_USE_EXCEPTION
1973
1974# define JSON_ASSERT(condition) assert(condition)
1975
1976// The call to assert() will show the failure message in debug builds. In
1977// release builds we abort, for a core-dump or debugger.
1978# define JSON_FAIL_MESSAGE(message) \
1979 { \
1980 std::ostringstream oss; oss << message; \
1981 assert(false && oss.str().c_str()); \
1982 abort(); \
1983 }
1984
1985
1986#endif
1987
1988#define JSON_ASSERT_MESSAGE(condition, message) \
1989 if (!(condition)) { \
1990 JSON_FAIL_MESSAGE(message); \
1991 }
1992
1993#endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED
1994
1995// //////////////////////////////////////////////////////////////////////
1996// End of content of file: include/json/assertions.h
1997// //////////////////////////////////////////////////////////////////////
1998
1999
2000
2001
2002
2003#endif //ifndef JSON_AMALGATED_H_INCLUDED
Build a CharReader implementation.
Definition json.h:1480
Json::Value settings_
Definition json.h:1520
Definition json.h:1458
virtual CharReader * newCharReader() const =0
Allocate a CharReader via operator new().
Definition json.h:1434
virtual bool parse(char const *beginDoc, char const *endDoc, Value *root, std::string *errs)=0
Read a Value from a JSON document. The document must be a UTF-8 encoded string containing the documen...
Definition json.h:413
Outputs a Value in JSON format without formatting (not human friendly).
Definition json.h:1762
Configuration passed to reader and writer. This configuration object can be used to force the Reader ...
Definition json.h:314
bool strictRoot_
Definition json.h:341
bool allowComments_
true if comments are allowed. Default: true.
Definition json.h:337
Definition json.h:440
Experimental and untested: represents an element of the "path" to access a node.
Definition json.h:977
Experimental and untested: represents a "path" to access a node.
Definition json.h:1008
Unserialize a JSON document into a Value.
Definition json.h:1264
Definition json.h:429
Lightweight wrapper to tag static string.
Definition json.h:490
Build a StreamWriter implementation.
Definition json.h:1692
Json::Value settings_
Definition json.h:1717
A simple abstract factory.
Definition json.h:1661
virtual StreamWriter * newStreamWriter() const =0
Allocate a CharReader via operator new().
Definition json.h:1645
virtual int write(Value const &root, std::ostream *sout)=0
Writes a Value in JSON format in a human friendly way, to a stream rather than to a string.
Definition json.h:1866
Writes a Value in JSON format in a human friendly way.
Definition json.h:1804
const iterator for object and array value.
Definition json.h:1105
base class for Value iterators.
Definition json.h:1040
Iterator for object and array value.
Definition json.h:1154
Represents a JSON value.
Definition json.h:536
static const Int64 maxInt64
Maximum signed 64 bits int value that can be stored in a Json::Value.
Definition json.h:575
static const Value null
Definition json.h:555
Value const * demand(char const *begin, char const *end)
static const Int minInt
Minimum signed int value that can be stored in a Json::Value.
Definition json.h:565
static const Int64 minInt64
Minimum signed 64 bits int value that can be stored in a Json::Value.
Definition json.h:573
static const LargestInt maxLargestInt
Maximum signed integer value that can be stored in a Json::Value.
Definition json.h:560
static const LargestUInt maxLargestUInt
Maximum unsigned integer value that can be stored in a Json::Value.
Definition json.h:562
static const Int maxInt
Maximum signed int value that can be stored in a Json::Value.
Definition json.h:567
static const UInt maxUInt
Maximum unsigned int value that can be stored in a Json::Value.
Definition json.h:569
static const UInt64 maxUInt64
Maximum unsigned 64 bits int value that can be stored in a Json::Value.
Definition json.h:577
static const LargestInt minLargestInt
Minimum signed integer value that can be stored in a Json::Value.
Definition json.h:558
Abstract class for writers.
Definition json.h:1746
JSON (JavaScript Object Notation).
Definition json-forwards.h:182
JSON_API std::istream & operator>>(std::istream &, Value &)
Read from 'sin' into 'root'.
Definition jsoncpp.cpp:2011
CommentPlacement
Definition json.h:463
@ commentAfterOnSameLine
a comment just after a value on the same line
Definition json.h:465
@ commentBefore
a comment placed on the line before a value
Definition json.h:464
@ numberOfCommentPlacement
root value)
Definition json.h:468
@ commentAfter
Definition json.h:466
ValueType
Type of the value held by a Value object.
Definition json.h:452
@ booleanValue
bool value
Definition json.h:458
@ nullValue
'null' value
Definition json.h:453
@ stringValue
UTF-8 string value.
Definition json.h:457
@ realValue
double value
Definition json.h:456
@ arrayValue
array value (ordered list)
Definition json.h:459
@ intValue
signed integer value
Definition json.h:454
@ objectValue
object value (collection of name/value pairs).
Definition json.h:460
@ uintValue
unsigned integer value
Definition json.h:455
JSON_API std::ostream & operator<<(std::ostream &, const Value &root)
Output using the StyledStreamWriter.
Definition jsoncpp.cpp:4950
bool JSON_API parseFromStream(CharReader::Factory const &, std::istream &, Value *root, std::string *errs)
Definition jsoncpp.cpp:1997
JSONCPP_NORETURN void throwRuntimeError(std::string const &msg)
used internally
Definition jsoncpp.cpp:2386
JSONCPP_NORETURN void throwLogicError(std::string const &msg)
used internally
Definition jsoncpp.cpp:2390
std::string JSON_API writeString(StreamWriter::Factory const &factory, Value const &root)
Write into stringstream, then return string, for convenience. A StreamWriter will be created from the...
Definition jsoncpp.cpp:4943