LoveBrains  1.0.0
json.h
1 
4 // //////////////////////////////////////////////////////////////////////
5 // Beginning of content of file: LICENSE
6 // //////////////////////////////////////////////////////////////////////
7 
8 /*
9 The JsonCpp library's source code, including accompanying documentation,
10 tests and demonstration applications, are licensed under the following
11 conditions...
12 
13 The author (Baptiste Lepilleur) explicitly disclaims copyright in all
14 jurisdictions which recognize such a disclaimer. In such jurisdictions,
15 this software is released into the Public Domain.
16 
17 In jurisdictions which do not recognize Public Domain property (e.g. Germany as of
18 2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is
19 released under the terms of the MIT License (see below).
20 
21 In jurisdictions which recognize Public Domain property, the user of this
22 software may choose to accept it either as 1) Public Domain, 2) under the
23 conditions of the MIT License (see below), or 3) under the terms of dual
24 Public Domain/MIT License conditions described here, as they choose.
25 
26 The MIT License is about as close to Public Domain as a license can get, and is
27 described in clear, concise terms at:
28 
29  http://en.wikipedia.org/wiki/MIT_License
30 
31 The full text of the MIT License follows:
32 
33 ========================================================================
34 Copyright (c) 2007-2010 Baptiste Lepilleur
35 
36 Permission is hereby granted, free of charge, to any person
37 obtaining a copy of this software and associated documentation
38 files (the "Software"), to deal in the Software without
39 restriction, including without limitation the rights to use, copy,
40 modify, merge, publish, distribute, sublicense, and/or sell copies
41 of the Software, and to permit persons to whom the Software is
42 furnished to do so, subject to the following conditions:
43 
44 The above copyright notice and this permission notice shall be
45 included in all copies or substantial portions of the Software.
46 
47 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
51 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
52 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
53 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
54 SOFTWARE.
55 ========================================================================
56 (END LICENSE TEXT)
57 
58 The MIT license is compatible with both the GPL and commercial
59 software, affording one all of the rights of Public Domain with the
60 minor nuisance of being required to keep the above copyright notice
61 and license text in the source code. Note also that by accepting the
62 Public Domain "license" you can re-license your copy using whatever
63 license 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
77 #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 "1.6.5"
91 # define JSONCPP_VERSION_MAJOR 1
92 # define JSONCPP_VERSION_MINOR 6
93 # define JSONCPP_VERSION_PATCH 5
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 JSON_NO_INT64 is defined, then Json only support C++ "int" type for
166 // integer
167 // Storages, and 64 bits integer support is disabled.
168 // #define JSON_NO_INT64 1
169 
170 #if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC 6
171 // Microsoft Visual Studio 6 only support conversion from __int64 to double
172 // (no conversion from unsigned __int64).
173 #define JSON_USE_INT64_DOUBLE_CONVERSION 1
174 // Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255'
175 // characters in the debug information)
176 // All projects I've ever seen with VS6 were using this globally (not bothering
177 // with pragma push/pop).
178 #pragma warning(disable : 4786)
179 #endif // if defined(_MSC_VER) && _MSC_VER < 1200 // MSVC 6
180 
181 #if defined(_MSC_VER) && _MSC_VER >= 1500 // MSVC 2008
182 #define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
184 #elif defined(__clang__) && defined(__has_feature)
185 #if __has_feature(attribute_deprecated_with_message)
186 #define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))
187 #endif
188 #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
189 #define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))
190 #elif defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
191 #define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
192 #endif
193 
194 #if !defined(JSONCPP_DEPRECATED)
195 #define JSONCPP_DEPRECATED(message)
196 #endif // if !defined(JSONCPP_DEPRECATED)
197 
198 namespace Json {
199 typedef int Int;
200 typedef unsigned int UInt;
201 #if defined(JSON_NO_INT64)
202 typedef int LargestInt;
203 typedef unsigned int LargestUInt;
204 #undef JSON_HAS_INT64
205 #else // if defined(JSON_NO_INT64)
206 // For Microsoft Visual use specific types as long long is not supported
207 #if defined(_MSC_VER) // Microsoft Visual Studio
208 typedef __int64 Int64;
209 typedef unsigned __int64 UInt64;
210 #else // if defined(_MSC_VER) // Other platforms, use long long
211 typedef long long int Int64;
212 typedef unsigned long long int UInt64;
213 #endif // if defined(_MSC_VER)
214 typedef Int64 LargestInt;
215 typedef UInt64 LargestUInt;
216 #define JSON_HAS_INT64
217 #endif // if defined(JSON_NO_INT64)
218 } // end namespace Json
219 
220 #endif // JSON_CONFIG_H_INCLUDED
221 
222 // //////////////////////////////////////////////////////////////////////
223 // End of content of file: include/json/config.h
224 // //////////////////////////////////////////////////////////////////////
225 
226 
227 
228 
229 
230 
231 // //////////////////////////////////////////////////////////////////////
232 // Beginning of content of file: include/json/forwards.h
233 // //////////////////////////////////////////////////////////////////////
234 
235 // Copyright 2007-2010 Baptiste Lepilleur
236 // Distributed under MIT license, or public domain if desired and
237 // recognized in your jurisdiction.
238 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
239 
240 #ifndef JSON_FORWARDS_H_INCLUDED
241 #define JSON_FORWARDS_H_INCLUDED
242 
243 #if !defined(JSON_IS_AMALGAMATION)
244 #include "config.h"
245 #endif // if !defined(JSON_IS_AMALGAMATION)
246 
247 namespace Json {
248 
249 // writer.h
250 class FastWriter;
251 class StyledWriter;
252 
253 // reader.h
254 class Reader;
255 
256 // features.h
257 class Features;
258 
259 // value.h
260 typedef unsigned int ArrayIndex;
261 class StaticString;
262 class Path;
263 class PathArgument;
264 class Value;
265 class ValueIteratorBase;
266 class ValueIterator;
267 class ValueConstIterator;
268 
269 } // namespace Json
270 
271 #endif // JSON_FORWARDS_H_INCLUDED
272 
273 // //////////////////////////////////////////////////////////////////////
274 // End of content of file: include/json/forwards.h
275 // //////////////////////////////////////////////////////////////////////
276 
277 
278 
279 
280 
281 
282 // //////////////////////////////////////////////////////////////////////
283 // Beginning of content of file: include/json/features.h
284 // //////////////////////////////////////////////////////////////////////
285 
286 // Copyright 2007-2010 Baptiste Lepilleur
287 // Distributed under MIT license, or public domain if desired and
288 // recognized in your jurisdiction.
289 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
290 
291 #ifndef CPPTL_JSON_FEATURES_H_INCLUDED
292 #define CPPTL_JSON_FEATURES_H_INCLUDED
293 
294 #if !defined(JSON_IS_AMALGAMATION)
295 #include "forwards.h"
296 #endif // if !defined(JSON_IS_AMALGAMATION)
297 
298 namespace Json {
299 
304 class JSON_API Features {
305 public:
312  static Features all();
313 
320  static Features strictMode();
321 
324  Features();
325 
327  bool allowComments_;
328 
331  bool strictRoot_;
332 
334  bool allowDroppedNullPlaceholders_;
335 
337  bool allowNumericKeys_;
338 };
339 
340 } // namespace Json
341 
342 #endif // CPPTL_JSON_FEATURES_H_INCLUDED
343 
344 // //////////////////////////////////////////////////////////////////////
345 // End of content of file: include/json/features.h
346 // //////////////////////////////////////////////////////////////////////
347 
348 
349 
350 
351 
352 
353 // //////////////////////////////////////////////////////////////////////
354 // Beginning of content of file: include/json/value.h
355 // //////////////////////////////////////////////////////////////////////
356 
357 // Copyright 2007-2010 Baptiste Lepilleur
358 // Distributed under MIT license, or public domain if desired and
359 // recognized in your jurisdiction.
360 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
361 
362 #ifndef CPPTL_JSON_H_INCLUDED
363 #define CPPTL_JSON_H_INCLUDED
364 
365 #if !defined(JSON_IS_AMALGAMATION)
366 #include "forwards.h"
367 #endif // if !defined(JSON_IS_AMALGAMATION)
368 #include <string>
369 #include <vector>
370 #include <exception>
371 
372 #ifndef JSON_USE_CPPTL_SMALLMAP
373 #include <map>
374 #else
375 #include <cpptl/smallmap.h>
376 #endif
377 #ifdef JSON_USE_CPPTL
378 #include <cpptl/forwards.h>
379 #endif
380 
381 // Disable warning C4251: <data member>: <type> needs to have dll-interface to
382 // be used by...
383 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
384 #pragma warning(push)
385 #pragma warning(disable : 4251)
386 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
387 
390 namespace Json {
391 
396 class JSON_API Exception : public std::exception {
397 public:
398  Exception(std::string const& msg);
399  virtual ~Exception() throw();
400  virtual char const* what() const throw();
401 protected:
402  std::string const msg_;
403 };
404 
411 class JSON_API RuntimeError : public Exception {
412 public:
413  RuntimeError(std::string const& msg);
414 };
415 
422 class JSON_API LogicError : public Exception {
423 public:
424  LogicError(std::string const& msg);
425 };
426 
428 void throwRuntimeError(std::string const& msg);
430 void throwLogicError(std::string const& msg);
431 
434 enum ValueType {
435  nullValue = 0,
436  intValue,
437  uintValue,
438  realValue,
439  stringValue,
440  booleanValue,
441  arrayValue,
442  objectValue
443 };
444 
446  commentBefore = 0,
448  commentAfter,
451 };
452 
453 //# ifdef JSON_USE_CPPTL
454 // typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
455 // typedef CppTL::AnyEnumerator<const Value &> EnumValues;
456 //# endif
457 
472 class JSON_API StaticString {
473 public:
474  explicit StaticString(const char* czstring) : c_str_(czstring) {}
475 
476  operator const char*() const { return c_str_; }
477 
478  const char* c_str() const { return c_str_; }
479 
480 private:
481  const char* c_str_;
482 };
483 
518 class JSON_API Value {
519  friend class ValueIteratorBase;
520 public:
521  typedef std::vector<std::string> Members;
522  typedef ValueIterator iterator;
523  typedef ValueConstIterator const_iterator;
524  typedef Json::UInt UInt;
525  typedef Json::Int Int;
526 #if defined(JSON_HAS_INT64)
527  typedef Json::UInt64 UInt64;
528  typedef Json::Int64 Int64;
529 #endif // defined(JSON_HAS_INT64)
530  typedef Json::LargestInt LargestInt;
531  typedef Json::LargestUInt LargestUInt;
532  typedef Json::ArrayIndex ArrayIndex;
533 
534  static const Value& null;
535  static const Value& nullRef;
536  static const LargestInt minLargestInt;
539  static const LargestInt maxLargestInt;
541  static const LargestUInt maxLargestUInt;
542 
544  static const Int minInt;
546  static const Int maxInt;
548  static const UInt maxUInt;
549 
550 #if defined(JSON_HAS_INT64)
551  static const Int64 minInt64;
554  static const Int64 maxInt64;
556  static const UInt64 maxUInt64;
557 #endif // defined(JSON_HAS_INT64)
558 
559 private:
560 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
561  class CZString {
562  public:
563  enum DuplicationPolicy {
564  noDuplication = 0,
565  duplicate,
566  duplicateOnCopy
567  };
568  CZString(ArrayIndex index);
569  CZString(char const* str, unsigned length, DuplicationPolicy allocate);
570  CZString(CZString const& other);
571  ~CZString();
572  CZString& operator=(CZString other);
573  bool operator<(CZString const& other) const;
574  bool operator==(CZString const& other) const;
575  ArrayIndex index() const;
576  //const char* c_str() const; ///< \deprecated
577  char const* data() const;
578  unsigned length() const;
579  bool isStaticString() const;
580 
581  private:
582  void swap(CZString& other);
583 
584  struct StringStorage {
585  unsigned policy_: 2;
586  unsigned length_: 30; // 1GB max
587  };
588 
589  char const* cstr_; // actually, a prefixed string, unless policy is noDup
590  union {
591  ArrayIndex index_;
592  StringStorage storage_;
593  };
594  };
595 
596 public:
597 #ifndef JSON_USE_CPPTL_SMALLMAP
598  typedef std::map<CZString, Value> ObjectValues;
599 #else
600  typedef CppTL::SmallMap<CZString, Value> ObjectValues;
601 #endif // ifndef JSON_USE_CPPTL_SMALLMAP
602 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
603 
604 public:
620  Value(ValueType type = nullValue);
621  Value(Int value);
622  Value(UInt value);
623 #if defined(JSON_HAS_INT64)
624  Value(Int64 value);
625  Value(UInt64 value);
626 #endif // if defined(JSON_HAS_INT64)
627  Value(double value);
628  Value(const char* value);
629  Value(const char* begin, const char* end);
630 
645  Value(const StaticString& value);
646  Value(const std::string& value);
647 #ifdef JSON_USE_CPPTL
648  Value(const CppTL::ConstString& value);
649 #endif
650  Value(bool value);
652  Value(const Value& other);
653  ~Value();
654 
657  Value& operator=(Value other);
659  void swap(Value& other);
661  void swapPayload(Value& other);
662 
663  ValueType type() const;
664 
666  bool operator<(const Value& other) const;
667  bool operator<=(const Value& other) const;
668  bool operator>=(const Value& other) const;
669  bool operator>(const Value& other) const;
670  bool operator==(const Value& other) const;
671  bool operator!=(const Value& other) const;
672  int compare(const Value& other) const;
673 
674  const char* asCString() const;
675  std::string asString() const;
676 
679  bool getString(
680  char const** begin, char const** end) const;
681 #ifdef JSON_USE_CPPTL
682  CppTL::ConstString asConstString() const;
683 #endif
684  Int asInt() const;
685  UInt asUInt() const;
686 #if defined(JSON_HAS_INT64)
687  Int64 asInt64() const;
688  UInt64 asUInt64() const;
689 #endif // if defined(JSON_HAS_INT64)
690  LargestInt asLargestInt() const;
691  LargestUInt asLargestUInt() const;
692  float asFloat() const;
693  double asDouble() const;
694  bool asBool() const;
695 
696  bool isNull() const;
697  bool isBool() const;
698  bool isInt() const;
699  bool isInt64() const;
700  bool isUInt() const;
701  bool isUInt64() const;
702  bool isIntegral() const;
703  bool isDouble() const;
704  bool isNumeric() const;
705  bool isString() const;
706  bool isArray() const;
707  bool isObject() const;
708 
709  bool isConvertibleTo(ValueType other) const;
710 
712  ArrayIndex size() const;
713 
716  bool empty() const;
717 
719  bool operator!() const;
720 
724  void clear();
725 
731  void resize(ArrayIndex size);
732 
739  Value& operator[](ArrayIndex index);
740 
747  Value& operator[](int index);
748 
752  const Value& operator[](ArrayIndex index) const;
753 
757  const Value& operator[](int index) const;
758 
762  Value get(ArrayIndex index, const Value& defaultValue) const;
764  bool isValidIndex(ArrayIndex index) const;
768  Value& append(const Value& value);
769 
773  Value& operator[](const char* key);
776  const Value& operator[](const char* key) const;
779  Value& operator[](const std::string& key);
783  const Value& operator[](const std::string& key) const;
796  Value& operator[](const StaticString& key);
797 #ifdef JSON_USE_CPPTL
798  Value& operator[](const CppTL::ConstString& key);
802  const Value& operator[](const CppTL::ConstString& key) const;
803 #endif
804  Value get(const char* key, const Value& defaultValue) const;
810  Value get(const char* begin, const char* end, const Value& defaultValue) const;
814  Value get(const std::string& key, const Value& defaultValue) const;
815 #ifdef JSON_USE_CPPTL
816  Value get(const CppTL::ConstString& key, const Value& defaultValue) const;
819 #endif
820  Value const* find(char const* begin, char const* end) const;
827  Value const* demand(char const* begin, char const* end);
835  Value removeMember(const char* key);
839  Value removeMember(const std::string& key);
842  bool removeMember(const char* key, Value* removed);
849  bool removeMember(std::string const& key, Value* removed);
851  bool removeMember(const char* begin, const char* end, Value* removed);
858  bool removeIndex(ArrayIndex i, Value* removed);
859 
862  bool isMember(const char* key) const;
865  bool isMember(const std::string& key) const;
867  bool isMember(const char* begin, const char* end) const;
868 #ifdef JSON_USE_CPPTL
869  bool isMember(const CppTL::ConstString& key) const;
871 #endif
872 
878  Members getMemberNames() const;
879 
880  //# ifdef JSON_USE_CPPTL
881  // EnumMemberNames enumMemberNames() const;
882  // EnumValues enumValues() const;
883  //# endif
884 
886  JSONCPP_DEPRECATED("Use setComment(std::string const&) instead.")
887  void setComment(const char* comment, CommentPlacement placement);
889  void setComment(const char* comment, size_t len, CommentPlacement placement);
891  void setComment(const std::string& comment, CommentPlacement placement);
892  bool hasComment(CommentPlacement placement) const;
894  std::string getComment(CommentPlacement placement) const;
895 
896  std::string toStyledString() const;
897 
898  const_iterator begin() const;
899  const_iterator end() const;
900 
901  iterator begin();
902  iterator end();
903 
904  // Accessors for the [start, limit) range of bytes within the JSON text from
905  // which this value was parsed, if any.
906  void setOffsetStart(size_t start);
907  void setOffsetLimit(size_t limit);
908  size_t getOffsetStart() const;
909  size_t getOffsetLimit() const;
910 
911 private:
912  void initBasic(ValueType type, bool allocated = false);
913 
914  Value& resolveReference(const char* key);
915  Value& resolveReference(const char* key, const char* end);
916 
917  struct CommentInfo {
918  CommentInfo();
919  ~CommentInfo();
920 
921  void setComment(const char* text, size_t len);
922 
923  char* comment_;
924  };
925 
926  // struct MemberNamesTransform
927  //{
928  // typedef const char *result_type;
929  // const char *operator()( const CZString &name ) const
930  // {
931  // return name.c_str();
932  // }
933  //};
934 
935  union ValueHolder {
936  LargestInt int_;
937  LargestUInt uint_;
938  double real_;
939  bool bool_;
940  char* string_; // actually ptr to unsigned, followed by str, unless !allocated_
941  ObjectValues* map_;
942  } value_;
943  ValueType type_ : 8;
944  unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
945  // If not allocated_, string_ must be null-terminated.
946  CommentInfo* comments_;
947 
948  // [start, limit) byte offsets in the source JSON text from which this Value
949  // was extracted.
950  size_t start_;
951  size_t limit_;
952 };
953 
957 class JSON_API PathArgument {
958 public:
959  friend class Path;
960 
961  PathArgument();
962  PathArgument(ArrayIndex index);
963  PathArgument(const char* key);
964  PathArgument(const std::string& key);
965 
966 private:
967  enum Kind {
968  kindNone = 0,
969  kindIndex,
970  kindKey
971  };
972  std::string key_;
973  ArrayIndex index_;
974  Kind kind_;
975 };
976 
988 class JSON_API Path {
989 public:
990  Path(const std::string& path,
991  const PathArgument& a1 = PathArgument(),
992  const PathArgument& a2 = PathArgument(),
993  const PathArgument& a3 = PathArgument(),
994  const PathArgument& a4 = PathArgument(),
995  const PathArgument& a5 = PathArgument());
996 
997  const Value& resolve(const Value& root) const;
998  Value resolve(const Value& root, const Value& defaultValue) const;
1001  Value& make(Value& root) const;
1002 
1003 private:
1004  typedef std::vector<const PathArgument*> InArgs;
1005  typedef std::vector<PathArgument> Args;
1006 
1007  void makePath(const std::string& path, const InArgs& in);
1008  void addPathInArg(const std::string& path,
1009  const InArgs& in,
1010  InArgs::const_iterator& itInArg,
1011  PathArgument::Kind kind);
1012  void invalidPath(const std::string& path, int location);
1013 
1014  Args args_;
1015 };
1016 
1020 class JSON_API ValueIteratorBase {
1021 public:
1022  typedef std::bidirectional_iterator_tag iterator_category;
1023  typedef unsigned int size_t;
1024  typedef int difference_type;
1025  typedef ValueIteratorBase SelfType;
1026 
1027  bool operator==(const SelfType& other) const { return isEqual(other); }
1028 
1029  bool operator!=(const SelfType& other) const { return !isEqual(other); }
1030 
1031  difference_type operator-(const SelfType& other) const {
1032  return other.computeDistance(*this);
1033  }
1034 
1037  Value key() const;
1038 
1040  UInt index() const;
1041 
1045  std::string name() const;
1046 
1050  JSONCPP_DEPRECATED("Use `key = name();` instead.")
1051  char const* memberName() const;
1055  char const* memberName(char const** end) const;
1056 
1057 protected:
1058  Value& deref() const;
1059 
1060  void increment();
1061 
1062  void decrement();
1063 
1064  difference_type computeDistance(const SelfType& other) const;
1065 
1066  bool isEqual(const SelfType& other) const;
1067 
1068  void copy(const SelfType& other);
1069 
1070 private:
1071  Value::ObjectValues::iterator current_;
1072  // Indicates that iterator is for a null value.
1073  bool isNull_;
1074 
1075 public:
1076  // For some reason, BORLAND needs these at the end, rather
1077  // than earlier. No idea why.
1078  ValueIteratorBase();
1079  explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
1080 };
1081 
1085 class JSON_API ValueConstIterator : public ValueIteratorBase {
1086  friend class Value;
1087 
1088 public:
1089  typedef const Value value_type;
1090  //typedef unsigned int size_t;
1091  //typedef int difference_type;
1092  typedef const Value& reference;
1093  typedef const Value* pointer;
1094  typedef ValueConstIterator SelfType;
1095 
1096  ValueConstIterator();
1097 
1098 private:
1101  explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
1102 public:
1103  SelfType& operator=(const ValueIteratorBase& other);
1104 
1105  SelfType operator++(int) {
1106  SelfType temp(*this);
1107  ++*this;
1108  return temp;
1109  }
1110 
1111  SelfType operator--(int) {
1112  SelfType temp(*this);
1113  --*this;
1114  return temp;
1115  }
1116 
1117  SelfType& operator--() {
1118  decrement();
1119  return *this;
1120  }
1121 
1122  SelfType& operator++() {
1123  increment();
1124  return *this;
1125  }
1126 
1127  reference operator*() const { return deref(); }
1128 
1129  pointer operator->() const { return &deref(); }
1130 };
1131 
1134 class JSON_API ValueIterator : public ValueIteratorBase {
1135  friend class Value;
1136 
1137 public:
1138  typedef Value value_type;
1139  typedef unsigned int size_t;
1140  typedef int difference_type;
1141  typedef Value& reference;
1142  typedef Value* pointer;
1143  typedef ValueIterator SelfType;
1144 
1145  ValueIterator();
1146  ValueIterator(const ValueConstIterator& other);
1147  ValueIterator(const ValueIterator& other);
1148 
1149 private:
1152  explicit ValueIterator(const Value::ObjectValues::iterator& current);
1153 public:
1154  SelfType& operator=(const SelfType& other);
1155 
1156  SelfType operator++(int) {
1157  SelfType temp(*this);
1158  ++*this;
1159  return temp;
1160  }
1161 
1162  SelfType operator--(int) {
1163  SelfType temp(*this);
1164  --*this;
1165  return temp;
1166  }
1167 
1168  SelfType& operator--() {
1169  decrement();
1170  return *this;
1171  }
1172 
1173  SelfType& operator++() {
1174  increment();
1175  return *this;
1176  }
1177 
1178  reference operator*() const { return deref(); }
1179 
1180  pointer operator->() const { return &deref(); }
1181 };
1182 
1183 } // namespace Json
1184 
1185 
1186 namespace std {
1188 template<>
1189 inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); }
1190 }
1191 
1192 
1193 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1194 #pragma warning(pop)
1195 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1196 
1197 #endif // CPPTL_JSON_H_INCLUDED
1198 
1199 // //////////////////////////////////////////////////////////////////////
1200 // End of content of file: include/json/value.h
1201 // //////////////////////////////////////////////////////////////////////
1202 
1203 
1204 
1205 
1206 
1207 
1208 // //////////////////////////////////////////////////////////////////////
1209 // Beginning of content of file: include/json/reader.h
1210 // //////////////////////////////////////////////////////////////////////
1211 
1212 // Copyright 2007-2010 Baptiste Lepilleur
1213 // Distributed under MIT license, or public domain if desired and
1214 // recognized in your jurisdiction.
1215 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
1216 
1217 #ifndef CPPTL_JSON_READER_H_INCLUDED
1218 #define CPPTL_JSON_READER_H_INCLUDED
1219 
1220 #if !defined(JSON_IS_AMALGAMATION)
1221 #include "features.h"
1222 #include "value.h"
1223 #endif // if !defined(JSON_IS_AMALGAMATION)
1224 #include <deque>
1225 #include <iosfwd>
1226 #include <stack>
1227 #include <string>
1228 #include <istream>
1229 
1230 // Disable warning C4251: <data member>: <type> needs to have dll-interface to
1231 // be used by...
1232 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1233 #pragma warning(push)
1234 #pragma warning(disable : 4251)
1235 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1236 
1237 namespace Json {
1238 
1244 class JSON_API Reader {
1245 public:
1246  typedef char Char;
1247  typedef const Char* Location;
1248 
1255  struct StructuredError {
1256  size_t offset_start;
1257  size_t offset_limit;
1258  std::string message;
1259  };
1260 
1264  Reader();
1265 
1269  Reader(const Features& features);
1270 
1285  bool
1286  parse(const std::string& document, Value& root, bool collectComments = true);
1287 
1306  bool parse(const char* beginDoc,
1307  const char* endDoc,
1308  Value& root,
1309  bool collectComments = true);
1310 
1313  bool parse(std::istream& is, Value& root, bool collectComments = true);
1314 
1324  JSONCPP_DEPRECATED("Use getFormattedErrorMessages() instead.")
1325  std::string getFormatedErrorMessages() const;
1326 
1335  std::string getFormattedErrorMessages() const;
1336 
1344  std::vector<StructuredError> getStructuredErrors() const;
1345 
1352  bool pushError(const Value& value, const std::string& message);
1353 
1361  bool pushError(const Value& value, const std::string& message, const Value& extra);
1362 
1367  bool good() const;
1368 
1369 private:
1370  enum TokenType {
1371  tokenEndOfStream = 0,
1372  tokenObjectBegin,
1373  tokenObjectEnd,
1374  tokenArrayBegin,
1375  tokenArrayEnd,
1376  tokenString,
1377  tokenNumber,
1378  tokenTrue,
1379  tokenFalse,
1380  tokenNull,
1381  tokenArraySeparator,
1382  tokenMemberSeparator,
1383  tokenComment,
1384  tokenError
1385  };
1386 
1387  class Token {
1388  public:
1389  TokenType type_;
1390  Location start_;
1391  Location end_;
1392  };
1393 
1394  class ErrorInfo {
1395  public:
1396  Token token_;
1397  std::string message_;
1398  Location extra_;
1399  };
1400 
1401  typedef std::deque<ErrorInfo> Errors;
1402 
1403  bool readToken(Token& token);
1404  void skipSpaces();
1405  bool match(Location pattern, int patternLength);
1406  bool readComment();
1407  bool readCStyleComment();
1408  bool readCppStyleComment();
1409  bool readString();
1410  void readNumber();
1411  bool readValue();
1412  bool readObject(Token& token);
1413  bool readArray(Token& token);
1414  bool decodeNumber(Token& token);
1415  bool decodeNumber(Token& token, Value& decoded);
1416  bool decodeString(Token& token);
1417  bool decodeString(Token& token, std::string& decoded);
1418  bool decodeDouble(Token& token);
1419  bool decodeDouble(Token& token, Value& decoded);
1420  bool decodeUnicodeCodePoint(Token& token,
1421  Location& current,
1422  Location end,
1423  unsigned int& unicode);
1424  bool decodeUnicodeEscapeSequence(Token& token,
1425  Location& current,
1426  Location end,
1427  unsigned int& unicode);
1428  bool addError(const std::string& message, Token& token, Location extra = 0);
1429  bool recoverFromError(TokenType skipUntilToken);
1430  bool addErrorAndRecover(const std::string& message,
1431  Token& token,
1432  TokenType skipUntilToken);
1433  void skipUntilSpace();
1434  Value& currentValue();
1435  Char getNextChar();
1436  void
1437  getLocationLineAndColumn(Location location, int& line, int& column) const;
1438  std::string getLocationLineAndColumn(Location location) const;
1439  void addComment(Location begin, Location end, CommentPlacement placement);
1440  void skipCommentTokens(Token& token);
1441 
1442  typedef std::stack<Value*> Nodes;
1443  Nodes nodes_;
1444  Errors errors_;
1445  std::string document_;
1446  Location begin_;
1447  Location end_;
1448  Location current_;
1449  Location lastValueEnd_;
1450  Value* lastValue_;
1451  std::string commentsBefore_;
1452  Features features_;
1453  bool collectComments_;
1454 }; // Reader
1455 
1458 class JSON_API CharReader {
1459 public:
1460  virtual ~CharReader() {}
1478  virtual bool parse(
1479  char const* beginDoc, char const* endDoc,
1480  Value* root, std::string* errs) = 0;
1481 
1482  class Factory {
1483  public:
1484  virtual ~Factory() {}
1488  virtual CharReader* newCharReader() const = 0;
1489  }; // Factory
1490 }; // CharReader
1491 
1504 class JSON_API CharReaderBuilder : public CharReader::Factory {
1505 public:
1506  // Note: We use a Json::Value so that we can add data-members to this class
1507  // without a major version bump.
1541  Json::Value settings_;
1542 
1543  CharReaderBuilder();
1544  virtual ~CharReaderBuilder();
1545 
1546  virtual CharReader* newCharReader() const;
1547 
1551  bool validate(Json::Value* invalid) const;
1552 
1555  Value& operator[](std::string key);
1556 
1562  static void setDefaults(Json::Value* settings);
1568  static void strictMode(Json::Value* settings);
1569 };
1570 
1575 bool JSON_API parseFromStream(
1576  CharReader::Factory const&,
1577  std::istream&,
1578  Value* root, std::string* errs);
1579 
1604 JSON_API std::istream& operator>>(std::istream&, Value&);
1605 
1606 } // namespace Json
1607 
1608 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1609 #pragma warning(pop)
1610 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1611 
1612 #endif // CPPTL_JSON_READER_H_INCLUDED
1613 
1614 // //////////////////////////////////////////////////////////////////////
1615 // End of content of file: include/json/reader.h
1616 // //////////////////////////////////////////////////////////////////////
1617 
1618 
1619 
1620 
1621 
1622 
1623 // //////////////////////////////////////////////////////////////////////
1624 // Beginning of content of file: include/json/writer.h
1625 // //////////////////////////////////////////////////////////////////////
1626 
1627 // Copyright 2007-2010 Baptiste Lepilleur
1628 // Distributed under MIT license, or public domain if desired and
1629 // recognized in your jurisdiction.
1630 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
1631 
1632 #ifndef JSON_WRITER_H_INCLUDED
1633 #define JSON_WRITER_H_INCLUDED
1634 
1635 #if !defined(JSON_IS_AMALGAMATION)
1636 #include "value.h"
1637 #endif // if !defined(JSON_IS_AMALGAMATION)
1638 #include <vector>
1639 #include <string>
1640 #include <ostream>
1641 
1642 // Disable warning C4251: <data member>: <type> needs to have dll-interface to
1643 // be used by...
1644 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1645 #pragma warning(push)
1646 #pragma warning(disable : 4251)
1647 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1648 
1649 namespace Json {
1650 
1651 class Value;
1652 
1666 class JSON_API StreamWriter {
1667 protected:
1668  std::ostream* sout_; // not owned; will not delete
1669 public:
1670  StreamWriter();
1671  virtual ~StreamWriter();
1678  virtual int write(Value const& root, std::ostream* sout) = 0;
1679 
1682  class JSON_API Factory {
1683  public:
1684  virtual ~Factory();
1688  virtual StreamWriter* newStreamWriter() const = 0;
1689  }; // Factory
1690 }; // StreamWriter
1691 
1695 std::string JSON_API writeString(StreamWriter::Factory const& factory, Value const& root);
1696 
1697 
1713 class JSON_API StreamWriterBuilder : public StreamWriter::Factory {
1714 public:
1715  // Note: We use a Json::Value so that we can add data-members to this class
1716  // without a major version bump.
1734  Json::Value settings_;
1735 
1736  StreamWriterBuilder();
1737  virtual ~StreamWriterBuilder();
1738 
1742  virtual StreamWriter* newStreamWriter() const;
1743 
1747  bool validate(Json::Value* invalid) const;
1750  Value& operator[](std::string key);
1751 
1757  static void setDefaults(Json::Value* settings);
1758 };
1759 
1763 class JSON_API Writer {
1764 public:
1765  virtual ~Writer();
1766 
1767  virtual std::string write(const Value& root) = 0;
1768 };
1769 
1779 class JSON_API FastWriter : public Writer {
1780 
1781 public:
1782  FastWriter();
1783  virtual ~FastWriter() {}
1784 
1785  void enableYAMLCompatibility();
1786 
1792  void dropNullPlaceholders();
1793 
1794  void omitEndingLineFeed();
1795 
1796 public: // overridden from Writer
1797  virtual std::string write(const Value& root);
1798 
1799 private:
1800  void writeValue(const Value& value);
1801 
1802  std::string document_;
1803  bool yamlCompatiblityEnabled_;
1804  bool dropNullPlaceholders_;
1805  bool omitEndingLineFeed_;
1806 };
1807 
1832 class JSON_API StyledWriter : public Writer {
1833 public:
1834  StyledWriter();
1835  virtual ~StyledWriter() {}
1836 
1837 public: // overridden from Writer
1842  virtual std::string write(const Value& root);
1843 
1844 private:
1845  void writeValue(const Value& value);
1846  void writeArrayValue(const Value& value);
1847  bool isMultineArray(const Value& value);
1848  void pushValue(const std::string& value);
1849  void writeIndent();
1850  void writeWithIndent(const std::string& value);
1851  void indent();
1852  void unindent();
1853  void writeCommentBeforeValue(const Value& root);
1854  void writeCommentAfterValueOnSameLine(const Value& root);
1855  bool hasCommentForValue(const Value& value);
1856  static std::string normalizeEOL(const std::string& text);
1857 
1858  typedef std::vector<std::string> ChildValues;
1859 
1860  ChildValues childValues_;
1861  std::string document_;
1862  std::string indentString_;
1863  int rightMargin_;
1864  int indentSize_;
1865  bool addChildValues_;
1866 };
1867 
1894 class JSON_API StyledStreamWriter {
1895 public:
1896  StyledStreamWriter(std::string indentation = "\t");
1897  ~StyledStreamWriter() {}
1898 
1899 public:
1906  void write(std::ostream& out, const Value& root);
1907 
1908 private:
1909  void writeValue(const Value& value);
1910  void writeArrayValue(const Value& value);
1911  bool isMultineArray(const Value& value);
1912  void pushValue(const std::string& value);
1913  void writeIndent();
1914  void writeWithIndent(const std::string& value);
1915  void indent();
1916  void unindent();
1917  void writeCommentBeforeValue(const Value& root);
1918  void writeCommentAfterValueOnSameLine(const Value& root);
1919  bool hasCommentForValue(const Value& value);
1920  static std::string normalizeEOL(const std::string& text);
1921 
1922  typedef std::vector<std::string> ChildValues;
1923 
1924  ChildValues childValues_;
1925  std::ostream* document_;
1926  std::string indentString_;
1927  int rightMargin_;
1928  std::string indentation_;
1929  bool addChildValues_ : 1;
1930  bool indented_ : 1;
1931 };
1932 
1933 #if defined(JSON_HAS_INT64)
1934 std::string JSON_API valueToString(Int value);
1935 std::string JSON_API valueToString(UInt value);
1936 #endif // if defined(JSON_HAS_INT64)
1937 std::string JSON_API valueToString(LargestInt value);
1938 std::string JSON_API valueToString(LargestUInt value);
1939 std::string JSON_API valueToString(double value);
1940 std::string JSON_API valueToString(bool value);
1941 std::string JSON_API valueToQuotedString(const char* value);
1942 
1945 JSON_API std::ostream& operator<<(std::ostream&, const Value& root);
1946 
1947 } // namespace Json
1948 
1949 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1950 #pragma warning(pop)
1951 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1952 
1953 #endif // JSON_WRITER_H_INCLUDED
1954 
1955 // //////////////////////////////////////////////////////////////////////
1956 // End of content of file: include/json/writer.h
1957 // //////////////////////////////////////////////////////////////////////
1958 
1959 
1960 
1961 
1962 
1963 
1964 // //////////////////////////////////////////////////////////////////////
1965 // Beginning of content of file: include/json/assertions.h
1966 // //////////////////////////////////////////////////////////////////////
1967 
1968 // Copyright 2007-2010 Baptiste Lepilleur
1969 // Distributed under MIT license, or public domain if desired and
1970 // recognized in your jurisdiction.
1971 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
1972 
1973 #ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED
1974 #define CPPTL_JSON_ASSERTIONS_H_INCLUDED
1975 
1976 #include <stdlib.h>
1977 #include <sstream>
1978 
1979 #if !defined(JSON_IS_AMALGAMATION)
1980 #include "config.h"
1981 #endif // if !defined(JSON_IS_AMALGAMATION)
1982 
1987 #if JSON_USE_EXCEPTION
1988 
1989 // @todo <= add detail about condition in exception
1990 # define JSON_ASSERT(condition) \
1991  {if (!(condition)) {Json::throwLogicError( "assert json failed" );}}
1992 
1993 # define JSON_FAIL_MESSAGE(message) \
1994  { \
1995  std::ostringstream oss; oss << message; \
1996  Json::throwLogicError(oss.str()); \
1997  abort(); \
1998  }
1999 
2000 #else // JSON_USE_EXCEPTION
2001 
2002 # define JSON_ASSERT(condition) assert(condition)
2003 
2004 // The call to assert() will show the failure message in debug builds. In
2005 // release builds we abort, for a core-dump or debugger.
2006 # define JSON_FAIL_MESSAGE(message) \
2007  { \
2008  std::ostringstream oss; oss << message; \
2009  assert(false && oss.str().c_str()); \
2010  abort(); \
2011  }
2012 
2013 
2014 #endif
2015 
2016 #define JSON_ASSERT_MESSAGE(condition, message) \
2017  if (!(condition)) { \
2018  JSON_FAIL_MESSAGE(message); \
2019  }
2020 
2021 #endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED
2022 
2023 // //////////////////////////////////////////////////////////////////////
2024 // End of content of file: include/json/assertions.h
2025 // //////////////////////////////////////////////////////////////////////
2026 
2027 
2028 
2029 
2030 
2031 #endif //ifndef JSON_AMALGATED_H_INCLUDED
UTF-8 string value.
Definition: json.h:439
JSON_API std::ostream & operator<<(std::ostream &, const Value &root)
Output using the StyledStreamWriter.
'null' value
Definition: json.h:435
a comment just after a value on the same line
Definition: json.h:447
bool JSON_API parseFromStream(CharReader::Factory const &, std::istream &, Value *root, std::string *errs)
Definition: jsoncpp.cc:2138
void throwLogicError(std::string const &msg)
used internally
Definition: jsoncpp.cc:2530
array value (ordered list)
Definition: json.h:441
JSON_API std::istream & operator>>(std::istream &, Value &)
Read from 'sin' into 'root'.
Definition: jsoncpp.cc:2152
Definition: json.h:1186
object value (collection of name/value pairs).
Definition: json.h:442
CommentPlacement
Definition: json.h:445
bool value
Definition: json.h:440
a comment placed on the line before a value
Definition: json.h:446
JSON (JavaScript Object Notation).
Definition: json-forwards.h:172
void swap(Value &other)
Swap everything.
Definition: jsoncpp.cc:2823
unsigned integer value
Definition: json.h:437
double value
Definition: json.h:438
void throwRuntimeError(std::string const &msg)
used internally
Definition: jsoncpp.cc:2526
Represents a JSON value.
Definition: json.h:518
signed integer value
Definition: json.h:436
root value)
Definition: json.h:450
ValueType
Type of the value held by a Value object.
Definition: json.h:434
Definition: json.h:448
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.cc:5066