Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
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 #ifndef JSON_AMALGATED_H_INCLUDED
72 #define JSON_AMALGATED_H_INCLUDED
73 #define JSON_IS_AMALGATED
76 
77 // //////////////////////////////////////////////////////////////////////
78 // Beginning of content of file: include/json/config.h
79 // //////////////////////////////////////////////////////////////////////
80 
81 // Copyright 2007-2010 Baptiste Lepilleur
82 // Distributed under MIT license, or public domain if desired and
83 // recognized in your jurisdiction.
84 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
85 
86 #ifndef JSON_CONFIG_H_INCLUDED
87 #define JSON_CONFIG_H_INCLUDED
88 
90 //# define JSON_IN_CPPTL 1
91 
93 //# define JSON_USE_CPPTL 1
96 //# define JSON_USE_CPPTL_SMALLMAP 1
100 //# define JSON_VALUE_USE_INTERNAL_MAP 1
105 //# define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1
106 
109 #define JSON_USE_EXCEPTION 1
110 
114 // #define JSON_IS_AMALGATED
115 
116 #ifdef JSON_IN_CPPTL
117 #include <cpptl/config.h>
118 #ifndef JSON_USE_CPPTL
119 #define JSON_USE_CPPTL 1
120 #endif
121 #endif
122 
123 #ifdef JSON_IN_CPPTL
124 #define JSON_API CPPTL_API
125 #elif defined(JSON_DLL_BUILD)
126 #define JSON_API __declspec(dllexport)
127 #elif defined(JSON_DLL)
128 #define JSON_API __declspec(dllimport)
129 #else
130 #define JSON_API
131 #endif
132 
133 // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for integer
134 // Storages, and 64 bits integer support is disabled.
135 // #define JSON_NO_INT64 1
136 
137 #if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC 6
138 // Microsoft Visual Studio 6 only support conversion from __int64 to double
139 // (no conversion from unsigned __int64).
140 #define JSON_USE_INT64_DOUBLE_CONVERSION 1
141 #endif // if defined(_MSC_VER) && _MSC_VER < 1200 // MSVC 6
142 
143 #if defined(_MSC_VER) && _MSC_VER >= 1500 // MSVC 2008
144 #define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
146 #endif
147 
148 #if !defined(JSONCPP_DEPRECATED)
149 #define JSONCPP_DEPRECATED(message)
150 #endif // if !defined(JSONCPP_DEPRECATED)
151 
152 namespace Json
153 {
154 typedef int Int;
155 typedef unsigned int UInt;
156 #if defined(JSON_NO_INT64)
157 typedef int LargestInt;
158 typedef unsigned int LargestUInt;
159 #undef JSON_HAS_INT64
160 #else // if defined(JSON_NO_INT64)
161 // For Microsoft Visual use specific types as long long is not supported
162 #if defined(_MSC_VER) // Microsoft Visual Studio
163 typedef __int64 Int64;
164 typedef unsigned __int64 UInt64;
165 #else // if defined(_MSC_VER) // Other platforms, use long long
166 typedef long long int Int64;
167 typedef unsigned long long int UInt64;
168 #endif // if defined(_MSC_VER)
169 typedef Int64 LargestInt;
170 typedef UInt64 LargestUInt;
171 #define JSON_HAS_INT64
172 #endif // if defined(JSON_NO_INT64)
173 } // end namespace Json
174 
175 #endif // JSON_CONFIG_H_INCLUDED
176 
177 // //////////////////////////////////////////////////////////////////////
178 // End of content of file: include/json/config.h
179 // //////////////////////////////////////////////////////////////////////
180 
181 // //////////////////////////////////////////////////////////////////////
182 // Beginning of content of file: include/json/forwards.h
183 // //////////////////////////////////////////////////////////////////////
184 
185 // Copyright 2007-2010 Baptiste Lepilleur
186 // Distributed under MIT license, or public domain if desired and
187 // recognized in your jurisdiction.
188 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
189 
190 #ifndef JSON_FORWARDS_H_INCLUDED
191 #define JSON_FORWARDS_H_INCLUDED
192 
193 #if !defined(JSON_IS_AMALGATED)
194 #include "config.h"
195 #endif // if !defined(JSON_IS_AMALGATED)
196 
197 namespace Json
198 {
199 // writer.h
200 class FastWriter;
201 class StyledWriter;
202 
203 // reader.h
204 class Reader;
205 
206 // features.h
207 class Features;
208 
209 // value.h
210 typedef unsigned int ArrayIndex;
211 class StaticString;
212 class Path;
213 class PathArgument;
214 class Value;
215 class ValueIteratorBase;
216 class ValueIterator;
217 class ValueConstIterator;
218 #ifdef JSON_VALUE_USE_INTERNAL_MAP
219 class ValueMapAllocator;
220 class ValueInternalLink;
221 class ValueInternalArray;
222 class ValueInternalMap;
223 #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
224 
225 } // namespace Json
226 
227 #endif // JSON_FORWARDS_H_INCLUDED
228 
229 // //////////////////////////////////////////////////////////////////////
230 // End of content of file: include/json/forwards.h
231 // //////////////////////////////////////////////////////////////////////
232 
233 // //////////////////////////////////////////////////////////////////////
234 // Beginning of content of file: include/json/features.h
235 // //////////////////////////////////////////////////////////////////////
236 
237 // Copyright 2007-2010 Baptiste Lepilleur
238 // Distributed under MIT license, or public domain if desired and
239 // recognized in your jurisdiction.
240 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
241 
242 #ifndef CPPTL_JSON_FEATURES_H_INCLUDED
243 #define CPPTL_JSON_FEATURES_H_INCLUDED
244 
245 #if !defined(JSON_IS_AMALGATED)
246 #include "forwards.h"
247 #endif // if !defined(JSON_IS_AMALGATED)
248 
249 namespace Json
250 {
255 class JSON_API Features
256 {
257 public:
263  static Features all();
264 
270  static Features strictMode();
271 
274  Features();
275 
278 
281 };
282 
283 } // namespace Json
284 
285 #endif // CPPTL_JSON_FEATURES_H_INCLUDED
286 
287 // //////////////////////////////////////////////////////////////////////
288 // End of content of file: include/json/features.h
289 // //////////////////////////////////////////////////////////////////////
290 
291 // //////////////////////////////////////////////////////////////////////
292 // Beginning of content of file: include/json/value.h
293 // //////////////////////////////////////////////////////////////////////
294 
295 // Copyright 2007-2010 Baptiste Lepilleur
296 // Distributed under MIT license, or public domain if desired and
297 // recognized in your jurisdiction.
298 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
299 
300 #ifndef CPPTL_JSON_H_INCLUDED
301 #define CPPTL_JSON_H_INCLUDED
302 
303 #if !defined(JSON_IS_AMALGATED)
304 #include "forwards.h"
305 #endif // if !defined(JSON_IS_AMALGATED)
306 #include <string>
307 #include <vector>
308 
309 #ifndef JSON_USE_CPPTL_SMALLMAP
310 #include <map>
311 #else
312 #include <cpptl/smallmap.h>
313 #endif
314 #ifdef JSON_USE_CPPTL
315 #include <cpptl/forwards.h>
316 #endif
317 
320 namespace Json
321 {
325 {
326  nullValue = 0,
334 };
335 
337 {
341  numberOfCommentPlacement
342 };
343 
344 //# ifdef JSON_USE_CPPTL
345 // typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
346 // typedef CppTL::AnyEnumerator<const Value &> EnumValues;
347 //# endif
348 
363 class JSON_API StaticString
364 {
365 public:
366  explicit StaticString(const char *czstring)
367  : str_(czstring)
368  {
369  }
370 
371  operator const char *() const { return str_; }
372  const char *c_str() const { return str_; }
373 private:
374  const char *str_;
375 };
376 
404 class JSON_API Value
405 {
406  friend class ValueIteratorBase;
407 #ifdef JSON_VALUE_USE_INTERNAL_MAP
408  friend class ValueInternalLink;
409  friend class ValueInternalMap;
410 #endif
411 public:
412  typedef std::vector<std::string> Members;
413  typedef ValueIterator iterator;
415  typedef Json::UInt UInt;
416  typedef Json::Int Int;
417 #if defined(JSON_HAS_INT64)
418  typedef Json::UInt64 UInt64;
419  typedef Json::Int64 Int64;
420 #endif // defined(JSON_HAS_INT64)
421  typedef Json::LargestInt LargestInt;
422  typedef Json::LargestUInt LargestUInt;
423  typedef Json::ArrayIndex ArrayIndex;
424 
425  static const Value null;
427  static const LargestInt minLargestInt;
429  static const LargestInt maxLargestInt;
431  static const LargestUInt maxLargestUInt;
432 
434  static const Int minInt;
436  static const Int maxInt;
438  static const UInt maxUInt;
439 
441  static const Int64 minInt64;
443  static const Int64 maxInt64;
445  static const UInt64 maxUInt64;
446 
447 private:
448 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
449 #ifndef JSON_VALUE_USE_INTERNAL_MAP
450  class CZString
451  {
452  public:
453  enum DuplicationPolicy
454  {
455  noDuplication = 0,
456  duplicate,
457  duplicateOnCopy
458  };
459  CZString(ArrayIndex index);
460  CZString(const char *cstr, DuplicationPolicy allocate);
461  CZString(const CZString &other);
462  ~CZString();
463  CZString &operator=(const CZString &other);
464  bool operator<(const CZString &other) const;
465  bool operator==(const CZString &other) const;
466  ArrayIndex index() const;
467  const char *c_str() const;
468  bool isStaticString() const;
469 
470  private:
471  void swap(CZString &other);
472  const char *cstr_;
473  ArrayIndex index_;
474  };
475 
476 public:
477 #ifndef JSON_USE_CPPTL_SMALLMAP
478  typedef std::map<CZString, Value> ObjectValues;
479 #else
480  typedef CppTL::SmallMap<CZString, Value> ObjectValues;
481 #endif // ifndef JSON_USE_CPPTL_SMALLMAP
482 #endif // ifndef JSON_VALUE_USE_INTERNAL_MAP
483 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
484 
485 public:
501  Value(ValueType type = nullValue);
502  Value(Int value);
503  Value(UInt value);
504 #if defined(JSON_HAS_INT64)
505  Value(Int64 value);
506  Value(UInt64 value);
507 #endif // if defined(JSON_HAS_INT64)
508  Value(double value);
509  Value(const char *value);
510  Value(const char *beginValue, const char *endValue);
521  Value(const StaticString &value);
522  Value(const std::string &value);
523 #ifdef JSON_USE_CPPTL
524  Value(const CppTL::ConstString &value);
525 #endif
526  Value(bool value);
527  Value(const Value &other);
528  ~Value();
529 
530  Value &operator=(const Value &other);
534  void swap(Value &other);
535 
536  ValueType type() const;
537 
538  bool operator<(const Value &other) const;
539  bool operator<=(const Value &other) const;
540  bool operator>=(const Value &other) const;
541  bool operator>(const Value &other) const;
542 
543  bool operator==(const Value &other) const;
544  bool operator!=(const Value &other) const;
545 
546  int compare(const Value &other) const;
547 
548  const char *asCString() const;
549  std::string asString() const;
550 #ifdef JSON_USE_CPPTL
551  CppTL::ConstString asConstString() const;
552 #endif
553  Int asInt() const;
554  UInt asUInt() const;
555  Int64 asInt64() const;
556  UInt64 asUInt64() const;
557  LargestInt asLargestInt() const;
558  LargestUInt asLargestUInt() const;
559  float asFloat() const;
560  double asDouble() const;
561  bool asBool() const;
562 
563  bool isNull() const;
564  bool isBool() const;
565  bool isInt() const;
566  bool isUInt() const;
567  bool isIntegral() const;
568  bool isDouble() const;
569  bool isNumeric() const;
570  bool isString() const;
571  bool isArray() const;
572  bool isObject() const;
573 
574  bool isConvertibleTo(ValueType other) const;
575 
577  ArrayIndex size() const;
578 
581  bool empty() const;
582 
584  bool operator!() const;
585 
589  void clear();
590 
596  void resize(ArrayIndex size);
597 
603  Value &operator[](ArrayIndex index);
604 
610  Value &operator[](int index);
611 
615  const Value &operator[](ArrayIndex index) const;
616 
620  const Value &operator[](int index) const;
621 
624  Value get(ArrayIndex index, const Value &defaultValue) const;
626  bool isValidIndex(ArrayIndex index) const;
630  Value &append(const Value &value);
631 
633  Value &operator[](const char *key);
635  const Value &operator[](const char *key) const;
637  Value &operator[](const std::string &key);
639  const Value &operator[](const std::string &key) const;
651  Value &operator[](const StaticString &key);
652 #ifdef JSON_USE_CPPTL
653  Value &operator[](const CppTL::ConstString &key);
656  const Value &operator[](const CppTL::ConstString &key) const;
657 #endif
658  Value get(const char *key, const Value &defaultValue) const;
661  Value get(const std::string &key, const Value &defaultValue) const;
662 #ifdef JSON_USE_CPPTL
663  Value get(const CppTL::ConstString &key, const Value &defaultValue) const;
665 #endif
666  Value removeMember(const char *key);
674  Value removeMember(const std::string &key);
675 
677  bool isMember(const char *key) const;
679  bool isMember(const std::string &key) const;
680 #ifdef JSON_USE_CPPTL
681  bool isMember(const CppTL::ConstString &key) const;
683 #endif
684 
690  Members getMemberNames() const;
691 
692  //# ifdef JSON_USE_CPPTL
693  // EnumMemberNames enumMemberNames() const;
694  // EnumValues enumValues() const;
695  //# endif
696 
698  void setComment(const char *comment, CommentPlacement placement);
700  void setComment(const std::string &comment, CommentPlacement placement);
701  bool hasComment(CommentPlacement placement) const;
703  std::string getComment(CommentPlacement placement) const;
704 
705  std::string toStyledString() const;
706 
707  const_iterator begin() const;
708  const_iterator end() const;
709 
710  iterator begin();
711  iterator end();
712 
713 private:
714  Value &resolveReference(const char *key, bool isStatic);
715 
716 #ifdef JSON_VALUE_USE_INTERNAL_MAP
717  inline bool isItemAvailable() const { return itemIsUsed_ == 0; }
718  inline void setItemUsed(bool isUsed = true) { itemIsUsed_ = isUsed ? 1 : 0; }
719  inline bool isMemberNameStatic() const { return memberNameIsStatic_ == 0; }
720  inline void setMemberNameIsStatic(bool isStatic) { memberNameIsStatic_ = isStatic ? 1 : 0; }
721 #endif // # ifdef JSON_VALUE_USE_INTERNAL_MAP
722 
723 private:
724  struct CommentInfo
725  {
726  CommentInfo();
727  ~CommentInfo();
728 
729  void setComment(const char *text);
730 
731  char *comment_;
732  };
733 
734  // struct MemberNamesTransform
735  //{
736  // typedef const char *result_type;
737  // const char *operator()( const CZString &name ) const
738  // {
739  // return name.c_str();
740  // }
741  //};
742 
743  union ValueHolder
744  {
745  LargestInt int_;
746  LargestUInt uint_;
747  double real_;
748  bool bool_;
749  char *string_;
750 #ifdef JSON_VALUE_USE_INTERNAL_MAP
751  ValueInternalArray *array_;
752  ValueInternalMap *map_;
753 #else
754  ObjectValues *map_;
755 #endif
756  } value_;
757  ValueType type_ : 8;
758  int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
759 #ifdef JSON_VALUE_USE_INTERNAL_MAP
760  unsigned int itemIsUsed_ : 1; // used by the ValueInternalMap container.
761  int memberNameIsStatic_ : 1; // used by the ValueInternalMap container.
762 #endif
763  CommentInfo *comments_;
764 };
765 
769 {
770 public:
771  friend class Path;
772 
773  PathArgument();
774  PathArgument(ArrayIndex index);
775  PathArgument(const char *key);
776  PathArgument(const std::string &key);
777 
778 private:
779  enum Kind
780  {
781  kindNone = 0,
782  kindIndex,
783  kindKey
784  };
785  std::string key_;
786  ArrayIndex index_;
787  Kind kind_;
788 };
789 
801 class Path
802 {
803 public:
804  Path(const std::string &path,
805  const PathArgument &a1 = PathArgument(),
806  const PathArgument &a2 = PathArgument(),
807  const PathArgument &a3 = PathArgument(),
808  const PathArgument &a4 = PathArgument(),
809  const PathArgument &a5 = PathArgument());
810 
811  const Value &resolve(const Value &root) const;
812  Value resolve(const Value &root, const Value &defaultValue) const;
814  Value &make(Value &root) const;
815 
816 private:
817  typedef std::vector<const PathArgument *> InArgs;
818  typedef std::vector<PathArgument> Args;
819 
820  void makePath(const std::string &path, const InArgs &in);
821  void addPathInArg(const std::string &path,
822  const InArgs &in,
823  InArgs::const_iterator &itInArg,
824  PathArgument::Kind kind);
825  void invalidPath(const std::string &path, int location);
826 
827  Args args_;
828 };
829 
830 #ifdef JSON_VALUE_USE_INTERNAL_MAP
831 
875 class JSON_API ValueMapAllocator
876 {
877 public:
878  virtual ~ValueMapAllocator();
879  virtual ValueInternalMap *newMap() = 0;
880  virtual ValueInternalMap *newMapCopy(const ValueInternalMap &other) = 0;
881  virtual void destructMap(ValueInternalMap *map) = 0;
882  virtual ValueInternalLink *allocateMapBuckets(unsigned int size) = 0;
883  virtual void releaseMapBuckets(ValueInternalLink *links) = 0;
884  virtual ValueInternalLink *allocateMapLink() = 0;
885  virtual void releaseMapLink(ValueInternalLink *link) = 0;
886 };
887 
891 class JSON_API ValueInternalLink
892 {
893 public:
894  enum
895  {
896  itemPerLink = 6
897  }; // sizeof(ValueInternalLink) = 128 on 32 bits architecture.
898  enum InternalFlags
899  {
900  flagAvailable = 0,
901  flagUsed = 1
902  };
903 
905 
907 
908  Value items_[itemPerLink];
909  char *keys_[itemPerLink];
910  ValueInternalLink *previous_;
911  ValueInternalLink *next_;
912 };
913 
926 class JSON_API ValueInternalMap
927 {
928  friend class ValueIteratorBase;
929  friend class Value;
930 
931 public:
932  typedef unsigned int HashKey;
933  typedef unsigned int BucketIndex;
934 
935 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
937  {
938  IteratorState()
939  : map_(0)
940  , link_(0)
941  , itemIndex_(0)
942  , bucketIndex_(0)
943  {
944  }
945  ValueInternalMap *map_;
946  ValueInternalLink *link_;
947  BucketIndex itemIndex_;
948  BucketIndex bucketIndex_;
949  };
950 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
951 
953  ValueInternalMap(const ValueInternalMap &other);
954  ValueInternalMap &operator=(const ValueInternalMap &other);
955  ~ValueInternalMap();
956 
957  void swap(ValueInternalMap &other);
958 
959  BucketIndex size() const;
960 
961  void clear();
962 
963  bool reserveDelta(BucketIndex growth);
964 
965  bool reserve(BucketIndex newItemCount);
966 
967  const Value *find(const char *key) const;
968 
969  Value *find(const char *key);
970 
971  Value &resolveReference(const char *key, bool isStatic);
972 
973  void remove(const char *key);
974 
975  void doActualRemove(ValueInternalLink *link, BucketIndex index, BucketIndex bucketIndex);
976 
977  ValueInternalLink *&getLastLinkInBucket(BucketIndex bucketIndex);
978 
979  Value &setNewItem(const char *key, bool isStatic, ValueInternalLink *link, BucketIndex index);
980 
981  Value &unsafeAdd(const char *key, bool isStatic, HashKey hashedKey);
982 
983  HashKey hash(const char *key) const;
984 
985  int compare(const ValueInternalMap &other) const;
986 
987 private:
988  void makeBeginIterator(IteratorState &it) const;
989  void makeEndIterator(IteratorState &it) const;
990  static bool equals(const IteratorState &x, const IteratorState &other);
991  static void increment(IteratorState &iterator);
992  static void incrementBucket(IteratorState &iterator);
993  static void decrement(IteratorState &iterator);
994  static const char *key(const IteratorState &iterator);
995  static const char *key(const IteratorState &iterator, bool &isStatic);
996  static Value &value(const IteratorState &iterator);
997  static int distance(const IteratorState &x, const IteratorState &y);
998 
999 private:
1000  ValueInternalLink *buckets_;
1001  ValueInternalLink *tailLink_;
1002  BucketIndex bucketsSize_;
1003  BucketIndex itemCount_;
1004 };
1005 
1017 class JSON_API ValueInternalArray
1018 {
1019  friend class Value;
1020  friend class ValueIteratorBase;
1021 
1022 public:
1023  enum
1024  {
1025  itemsPerPage = 8
1026  }; // should be a power of 2 for fast divide and modulo.
1027  typedef Value::ArrayIndex ArrayIndex;
1028  typedef unsigned int PageIndex;
1029 
1030 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
1031  struct IteratorState // Must be a POD
1032  {
1033  IteratorState()
1034  : array_(0)
1035  , currentPageIndex_(0)
1036  , currentItemIndex_(0)
1037  {
1038  }
1039  ValueInternalArray *array_;
1040  Value **currentPageIndex_;
1041  unsigned int currentItemIndex_;
1042  };
1043 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
1044 
1046  ValueInternalArray(const ValueInternalArray &other);
1047  ValueInternalArray &operator=(const ValueInternalArray &other);
1048  ~ValueInternalArray();
1049  void swap(ValueInternalArray &other);
1050 
1051  void clear();
1052  void resize(ArrayIndex newSize);
1053 
1054  Value &resolveReference(ArrayIndex index);
1055 
1056  Value *find(ArrayIndex index) const;
1057 
1058  ArrayIndex size() const;
1059 
1060  int compare(const ValueInternalArray &other) const;
1061 
1062 private:
1063  static bool equals(const IteratorState &x, const IteratorState &other);
1064  static void increment(IteratorState &iterator);
1065  static void decrement(IteratorState &iterator);
1066  static Value &dereference(const IteratorState &iterator);
1067  static Value &unsafeDereference(const IteratorState &iterator);
1068  static int distance(const IteratorState &x, const IteratorState &y);
1069  static ArrayIndex indexOf(const IteratorState &iterator);
1070  void makeBeginIterator(IteratorState &it) const;
1071  void makeEndIterator(IteratorState &it) const;
1072  void makeIterator(IteratorState &it, ArrayIndex index) const;
1073 
1074  void makeIndexValid(ArrayIndex index);
1075 
1076  Value **pages_;
1077  ArrayIndex size_;
1078  PageIndex pageCount_;
1079 };
1080 
1140 class JSON_API ValueArrayAllocator
1141 {
1142 public:
1143  virtual ~ValueArrayAllocator();
1144  virtual ValueInternalArray *newArray() = 0;
1145  virtual ValueInternalArray *newArrayCopy(const ValueInternalArray &other) = 0;
1146  virtual void destructArray(ValueInternalArray *array) = 0;
1158  virtual void reallocateArrayPageIndex(Value **&indexes,
1159  ValueInternalArray::PageIndex &indexCount,
1160  ValueInternalArray::PageIndex minNewIndexCount) = 0;
1161  virtual void releaseArrayPageIndex(Value **indexes, ValueInternalArray::PageIndex indexCount) = 0;
1162  virtual Value *allocateArrayPage() = 0;
1163  virtual void releaseArrayPage(Value *value) = 0;
1164 };
1165 #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
1166 
1171 {
1172 public:
1173  typedef unsigned int size_t;
1174  typedef int difference_type;
1175  typedef ValueIteratorBase SelfType;
1176 
1178 #ifndef JSON_VALUE_USE_INTERNAL_MAP
1179  explicit ValueIteratorBase(const Value::ObjectValues::iterator &current);
1180 #else
1183 #endif
1184 
1185  bool operator==(const SelfType &other) const { return isEqual(other); }
1186  bool operator!=(const SelfType &other) const { return !isEqual(other); }
1187  difference_type operator-(const SelfType &other) const { return computeDistance(other); }
1189  Value key() const;
1190 
1192  UInt index() const;
1193 
1195  const char *memberName() const;
1196 
1197 protected:
1198  Value &deref() const;
1199 
1200  void increment();
1201 
1202  void decrement();
1203 
1204  difference_type computeDistance(const SelfType &other) const;
1205 
1206  bool isEqual(const SelfType &other) const;
1207 
1208  void copy(const SelfType &other);
1209 
1210 private:
1211 #ifndef JSON_VALUE_USE_INTERNAL_MAP
1212  Value::ObjectValues::iterator current_;
1213  // Indicates that iterator is for a null value.
1214  bool isNull_;
1215 #else
1216  union
1217  {
1220  } iterator_;
1221  bool isArray_;
1222 #endif
1223 };
1224 
1229 {
1230  friend class Value;
1231 
1232 public:
1233  typedef unsigned int size_t;
1234  typedef int difference_type;
1235  typedef const Value &reference;
1236  typedef const Value *pointer;
1237  typedef ValueConstIterator SelfType;
1238 
1240 
1241 private:
1244 #ifndef JSON_VALUE_USE_INTERNAL_MAP
1245  explicit ValueConstIterator(const Value::ObjectValues::iterator &current);
1246 #else
1249 #endif
1250 public:
1251  SelfType &operator=(const ValueIteratorBase &other);
1252 
1253  SelfType operator++(int)
1254  {
1255  SelfType temp(*this);
1256  ++*this;
1257  return temp;
1258  }
1259 
1260  SelfType operator--(int)
1261  {
1262  SelfType temp(*this);
1263  --*this;
1264  return temp;
1265  }
1266 
1267  SelfType &operator--()
1268  {
1269  decrement();
1270  return *this;
1271  }
1272 
1273  SelfType &operator++()
1274  {
1275  increment();
1276  return *this;
1277  }
1278 
1279  reference operator*() const { return deref(); }
1280 };
1281 
1285 {
1286  friend class Value;
1287 
1288 public:
1289  typedef unsigned int size_t;
1290  typedef int difference_type;
1291  typedef Value &reference;
1292  typedef Value *pointer;
1293  typedef ValueIterator SelfType;
1294 
1295  ValueIterator();
1296  ValueIterator(const ValueConstIterator &other);
1297  ValueIterator(const ValueIterator &other);
1298 
1299 private:
1302 #ifndef JSON_VALUE_USE_INTERNAL_MAP
1303  explicit ValueIterator(const Value::ObjectValues::iterator &current);
1304 #else
1307 #endif
1308 public:
1309  SelfType &operator=(const SelfType &other);
1310 
1311  SelfType operator++(int)
1312  {
1313  SelfType temp(*this);
1314  ++*this;
1315  return temp;
1316  }
1317 
1318  SelfType operator--(int)
1319  {
1320  SelfType temp(*this);
1321  --*this;
1322  return temp;
1323  }
1324 
1325  SelfType &operator--()
1326  {
1327  decrement();
1328  return *this;
1329  }
1330 
1331  SelfType &operator++()
1332  {
1333  increment();
1334  return *this;
1335  }
1336 
1337  reference operator*() const { return deref(); }
1338 };
1339 
1340 } // namespace Json
1341 
1342 #endif // CPPTL_JSON_H_INCLUDED
1343 
1344 // //////////////////////////////////////////////////////////////////////
1345 // End of content of file: include/json/value.h
1346 // //////////////////////////////////////////////////////////////////////
1347 
1348 // //////////////////////////////////////////////////////////////////////
1349 // Beginning of content of file: include/json/reader.h
1350 // //////////////////////////////////////////////////////////////////////
1351 
1352 // Copyright 2007-2010 Baptiste Lepilleur
1353 // Distributed under MIT license, or public domain if desired and
1354 // recognized in your jurisdiction.
1355 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
1356 
1357 #ifndef CPPTL_JSON_READER_H_INCLUDED
1358 #define CPPTL_JSON_READER_H_INCLUDED
1359 
1360 #if !defined(JSON_IS_AMALGATED)
1361 #include "features.h"
1362 #include "value.h"
1363 #endif // if !defined(JSON_IS_AMALGATED)
1364 #include <deque>
1365 #include <stack>
1366 #include <string>
1367 #include <iostream>
1368 
1369 namespace Json
1370 {
1374 class JSON_API Reader
1375 {
1376 public:
1377  typedef char Char;
1378  typedef const Char *Location;
1379 
1383  Reader();
1384 
1388  Reader(const Features &features);
1389 
1400  bool parse(const std::string &document, Value &root, bool collectComments = true);
1401 
1414  bool parse(const char *beginDoc, const char *endDoc, Value &root, bool collectComments = true);
1415 
1418  bool parse(std::istream &is, Value &root, bool collectComments = true);
1419 
1426  JSONCPP_DEPRECATED("Use getFormattedErrorMessages instead")
1427  std::string getFormatedErrorMessages() const;
1428 
1434  std::string getFormattedErrorMessages() const;
1435 
1436 private:
1437  enum TokenType
1438  {
1439  tokenEndOfStream = 0,
1440  tokenObjectBegin,
1441  tokenObjectEnd,
1442  tokenArrayBegin,
1443  tokenArrayEnd,
1444  tokenString,
1445  tokenNumber,
1446  tokenTrue,
1447  tokenFalse,
1448  tokenNull,
1449  tokenArraySeparator,
1450  tokenMemberSeparator,
1451  tokenComment,
1452  tokenError
1453  };
1454 
1455  class Token
1456  {
1457  public:
1458  TokenType type_;
1459  Location start_;
1460  Location end_;
1461  };
1462 
1463  class ErrorInfo
1464  {
1465  public:
1466  Token token_;
1467  std::string message_;
1468  Location extra_;
1469  };
1470 
1471  typedef std::deque<ErrorInfo> Errors;
1472 
1473  bool expectToken(TokenType type, Token &token, const char *message);
1474  bool readToken(Token &token);
1475  void skipSpaces();
1476  bool match(Location pattern, int patternLength);
1477  bool readComment();
1478  bool readCStyleComment();
1479  bool readCppStyleComment();
1480  bool readString();
1481  void readNumber();
1482  bool readValue();
1483  bool readObject(Token &token);
1484  bool readArray(Token &token);
1485  bool decodeNumber(Token &token);
1486  bool decodeString(Token &token);
1487  bool decodeString(Token &token, std::string &decoded);
1488  bool decodeDouble(Token &token);
1489  bool decodeUnicodeCodePoint(Token &token, Location &current, Location end, unsigned int &unicode);
1490  bool decodeUnicodeEscapeSequence(Token &token, Location &current, Location end, unsigned int &unicode);
1491  bool addError(const std::string &message, Token &token, Location extra = 0);
1492  bool recoverFromError(TokenType skipUntilToken);
1493  bool addErrorAndRecover(const std::string &message, Token &token, TokenType skipUntilToken);
1494  void skipUntilSpace();
1495  Value &currentValue();
1496  Char getNextChar();
1497  void getLocationLineAndColumn(Location location, int &line, int &column) const;
1498  std::string getLocationLineAndColumn(Location location) const;
1499  void addComment(Location begin, Location end, CommentPlacement placement);
1500  void skipCommentTokens(Token &token);
1501 
1502  typedef std::stack<Value *> Nodes;
1503  Nodes nodes_;
1504  Errors errors_;
1505  std::string document_;
1506  Location begin_;
1507  Location end_;
1508  Location current_;
1509  Location lastValueEnd_;
1510  Value *lastValue_;
1511  std::string commentsBefore_;
1512  Features features_;
1513  bool collectComments_;
1514 };
1515 
1540 std::istream &operator>>(std::istream &, Value &);
1541 
1542 } // namespace Json
1543 
1544 #endif // CPPTL_JSON_READER_H_INCLUDED
1545 
1546 // //////////////////////////////////////////////////////////////////////
1547 // End of content of file: include/json/reader.h
1548 // //////////////////////////////////////////////////////////////////////
1549 
1550 // //////////////////////////////////////////////////////////////////////
1551 // Beginning of content of file: include/json/writer.h
1552 // //////////////////////////////////////////////////////////////////////
1553 
1554 // Copyright 2007-2010 Baptiste Lepilleur
1555 // Distributed under MIT license, or public domain if desired and
1556 // recognized in your jurisdiction.
1557 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
1558 
1559 #ifndef JSON_WRITER_H_INCLUDED
1560 #define JSON_WRITER_H_INCLUDED
1561 
1562 #if !defined(JSON_IS_AMALGATED)
1563 #include "value.h"
1564 #endif // if !defined(JSON_IS_AMALGATED)
1565 #include <vector>
1566 #include <string>
1567 #include <iostream>
1568 
1569 namespace Json
1570 {
1571 class Value;
1572 
1575 class JSON_API Writer
1576 {
1577 public:
1578  virtual ~Writer();
1579 
1580  virtual std::string write(const Value &root) = 0;
1581 };
1582 
1589 class JSON_API FastWriter : public Writer
1590 {
1591 public:
1592  FastWriter();
1593  virtual ~FastWriter() {}
1594  void enableYAMLCompatibility();
1595 
1596 public: // overridden from Writer
1597  virtual std::string write(const Value &root);
1598 
1599 private:
1600  void writeValue(const Value &value);
1601 
1602  std::string document_;
1603  bool yamlCompatiblityEnabled_;
1604 };
1605 
1624 class JSON_API StyledWriter : public Writer
1625 {
1626 public:
1627  StyledWriter();
1628  virtual ~StyledWriter() {}
1629 public: // overridden from Writer
1634  virtual std::string write(const Value &root);
1635 
1636 private:
1637  void writeValue(const Value &value);
1638  void writeArrayValue(const Value &value);
1639  bool isMultineArray(const Value &value);
1640  void pushValue(const std::string &value);
1641  void writeIndent();
1642  void writeWithIndent(const std::string &value);
1643  void indent();
1644  void unindent();
1645  void writeCommentBeforeValue(const Value &root);
1646  void writeCommentAfterValueOnSameLine(const Value &root);
1647  bool hasCommentForValue(const Value &value);
1648  static std::string normalizeEOL(const std::string &text);
1649 
1650  typedef std::vector<std::string> ChildValues;
1651 
1652  ChildValues childValues_;
1653  std::string document_;
1654  std::string indentString_;
1655  int rightMargin_;
1656  int indentSize_;
1657  bool addChildValues_;
1658 };
1659 
1680 class JSON_API StyledStreamWriter
1681 {
1682 public:
1683  StyledStreamWriter(std::string indentation = "\t");
1684  ~StyledStreamWriter() {}
1685 public:
1691  void write(std::ostream &out, const Value &root);
1692 
1693 private:
1694  void writeValue(const Value &value);
1695  void writeArrayValue(const Value &value);
1696  bool isMultineArray(const Value &value);
1697  void pushValue(const std::string &value);
1698  void writeIndent();
1699  void writeWithIndent(const std::string &value);
1700  void indent();
1701  void unindent();
1702  void writeCommentBeforeValue(const Value &root);
1703  void writeCommentAfterValueOnSameLine(const Value &root);
1704  bool hasCommentForValue(const Value &value);
1705  static std::string normalizeEOL(const std::string &text);
1706 
1707  typedef std::vector<std::string> ChildValues;
1708 
1709  ChildValues childValues_;
1710  std::ostream *document_;
1711  std::string indentString_;
1712  int rightMargin_;
1713  std::string indentation_;
1714  bool addChildValues_;
1715 };
1716 
1717 #if defined(JSON_HAS_INT64)
1718 std::string JSON_API valueToString(Int value);
1719 std::string JSON_API valueToString(UInt value);
1720 #endif // if defined(JSON_HAS_INT64)
1721 std::string JSON_API valueToString(LargestInt value);
1722 std::string JSON_API valueToString(LargestUInt value);
1723 std::string JSON_API valueToString(double value);
1724 std::string JSON_API valueToString(bool value);
1725 std::string JSON_API valueToQuotedString(const char *value);
1726 
1729 std::ostream &operator<<(std::ostream &, const Value &root);
1730 
1731 } // namespace Json
1732 
1733 #endif // JSON_WRITER_H_INCLUDED
1734 
1735 // //////////////////////////////////////////////////////////////////////
1736 // End of content of file: include/json/writer.h
1737 // //////////////////////////////////////////////////////////////////////
1738 
1739 #endif // ifndef JSON_AMALGATED_H_INCLUDED
Outputs a Value in JSON format without formatting (not human friendly).
Definition: json.h:1589
Experimental: do not use. Allocator to customize Value internal array. Below is an example of a simpl...
Definition: json.h:1140
Writes a Value in JSON format in a human friendly way.
Definition: json.h:1624
static const Int64 maxInt64
Maximum signed 64 bits int value that can be stored in a Json::Value.
Definition: json.h:443
base class for Value iterators.
Definition: json.h:1170
array value (ordered list)
Definition: json.h:332
unsigned integer value
Definition: json.h:328
object value (collection of name/value pairs).
Definition: json.h:333
std::istream & operator>>(std::istream &, Value &)
Read from &#39;sin&#39; into &#39;root&#39;.
Definition: jsoncpp.cpp:943
static const Int maxInt
Maximum signed int value that can be stored in a Json::Value.
Definition: json.h:436
Lightweight wrapper to tag static string.
Definition: json.h:363
static const UInt maxUInt
Maximum unsigned int value that can be stored in a Json::Value.
Definition: json.h:438
const iterator for object and array value.
Definition: json.h:1228
Experimental and untested: represents an element of the "path" to access a node.
Definition: json.h:768
static const LargestInt minLargestInt
Minimum signed integer value that can be stored in a Json::Value.
Definition: json.h:427
&#39;null&#39; value
Definition: json.h:326
bool allowComments_
true if comments are allowed. Default: true.
Definition: json.h:277
CommentPlacement
Definition: json.h:336
Allocator to customize Value internal map. Below is an example of a simple implementation (default im...
Definition: json.h:875
JSON (JavaScript Object Notation).
Definition: json.h:152
Experimental and untested: represents a "path" to access a node.
Definition: json.h:801
static const UInt64 maxUInt64
Maximum unsigned 64 bits int value that can be stored in a Json::Value.
Definition: json.h:445
double value
Definition: json.h:329
A simplified deque implementation used internally by Value.
Definition: json.h:1017
Abstract class for writers.
Definition: json.h:1575
Represents a JSON value.
Definition: json.h:404
static const Int64 minInt64
Minimum signed 64 bits int value that can be stored in a Json::Value.
Definition: json.h:441
static const Int minInt
Minimum signed int value that can be stored in a Json::Value.
Definition: json.h:434
a comment on the line after a value (only make sense for root value)
Definition: json.h:340
Unserialize a JSON document into a Value.
Definition: json.h:1374
Writes a Value in JSON format in a human friendly way, to a stream rather than to a string...
Definition: json.h:1680
Iterator for object and array value.
Definition: json.h:1284
A linked page based hash-table implementation used internally by Value.
Definition: json.h:926
ValueType
Type of the value held by a Value object.
Definition: json.h:324
bool strictRoot_
true if root must be either an array or an object value. Default: false.
Definition: json.h:280
bool value
Definition: json.h:331
signed integer value
Definition: json.h:327
Configuration passed to reader and writer. This configuration object can be used to force the Reader ...
Definition: json.h:255
a comment placed on the line before a value
Definition: json.h:338
UTF-8 string value.
Definition: json.h:330
a comment just after a value on the same line
Definition: json.h:339
std::ostream & operator<<(std::ostream &, const Value &root)
Output using the StyledStreamWriter.
Definition: jsoncpp.cpp:3774
static const LargestInt maxLargestInt
Maximum signed integer value that can be stored in a Json::Value.
Definition: json.h:429
static const LargestUInt maxLargestUInt
Maximum unsigned integer value that can be stored in a Json::Value.
Definition: json.h:431