json.h
Go to the documentation of this file.
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_AMALGATED
80 
81 // //////////////////////////////////////////////////////////////////////
82 // Beginning of content of file: include/json/config.h
83 // //////////////////////////////////////////////////////////////////////
84 
85 // Copyright 2007-2010 Baptiste Lepilleur
86 // Distributed under MIT license, or public domain if desired and
87 // recognized in your jurisdiction.
88 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
89 
90 #ifndef JSON_CONFIG_H_INCLUDED
91 # define JSON_CONFIG_H_INCLUDED
92 
94 //# define JSON_IN_CPPTL 1
95 
97 //# define JSON_USE_CPPTL 1
100 //# define JSON_USE_CPPTL_SMALLMAP 1
104 //# define JSON_VALUE_USE_INTERNAL_MAP 1
109 //# define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1
110 
113 # define JSON_USE_EXCEPTION 1
114 
118 #define JSON_IS_AMALGAMATION
119 
120 
121 # ifdef JSON_IN_CPPTL
122 # include <cpptl/config.h>
123 # ifndef JSON_USE_CPPTL
124 # define JSON_USE_CPPTL 1
125 # endif
126 # endif
127 
128 # ifdef JSON_IN_CPPTL
129 # define JSON_API CPPTL_API
130 # elif defined(JSON_DLL_BUILD)
131 # define JSON_API __declspec(dllexport)
132 # elif defined(JSON_DLL)
133 # define JSON_API __declspec(dllimport)
134 # else
135 # define JSON_API
136 # endif
137 
138 // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for integer
139 // Storages, and 64 bits integer support is disabled.
140 // #define JSON_NO_INT64 1
141 
142 #if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC 6
143 // Microsoft Visual Studio 6 only support conversion from __int64 to double
144 // (no conversion from unsigned __int64).
145 #define JSON_USE_INT64_DOUBLE_CONVERSION 1
146 #endif // if defined(_MSC_VER) && _MSC_VER < 1200 // MSVC 6
147 
148 #if defined(_MSC_VER) && _MSC_VER >= 1500 // MSVC 2008
149 # define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
151 #endif
152 
153 #if !defined(JSONCPP_DEPRECATED)
154 # define JSONCPP_DEPRECATED(message)
155 #endif // if !defined(JSONCPP_DEPRECATED)
156 
157 namespace Json {
158  typedef int Int;
159  typedef unsigned int UInt;
160 # if defined(JSON_NO_INT64)
161  typedef int LargestInt;
162  typedef unsigned int LargestUInt;
163 # undef JSON_HAS_INT64
164 # else // if defined(JSON_NO_INT64)
165  // For Microsoft Visual use specific types as long long is not supported
166 # if defined(_MSC_VER) // Microsoft Visual Studio
167  typedef __int64 Int64;
168  typedef unsigned __int64 UInt64;
169 # else // if defined(_MSC_VER) // Other platforms, use long long
170  typedef long long int Int64;
171  typedef unsigned long long int UInt64;
172 # endif // if defined(_MSC_VER)
173  typedef Int64 LargestInt;
174  typedef UInt64 LargestUInt;
175 # define JSON_HAS_INT64
176 # endif // if defined(JSON_NO_INT64)
177 } // end namespace Json
178 
179 
180 #endif // JSON_CONFIG_H_INCLUDED
181 
182 // //////////////////////////////////////////////////////////////////////
183 // End of content of file: include/json/config.h
184 // //////////////////////////////////////////////////////////////////////
185 
186 
187 
188 
189 
190 
191 // //////////////////////////////////////////////////////////////////////
192 // Beginning of content of file: include/json/forwards.h
193 // //////////////////////////////////////////////////////////////////////
194 
195 // Copyright 2007-2010 Baptiste Lepilleur
196 // Distributed under MIT license, or public domain if desired and
197 // recognized in your jurisdiction.
198 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
199 
200 #ifndef JSON_FORWARDS_H_INCLUDED
201 # define JSON_FORWARDS_H_INCLUDED
202 
203 #if !defined(JSON_IS_AMALGAMATION)
204 # include "config.h"
205 #endif // if !defined(JSON_IS_AMALGAMATION)
206 
207 namespace Json {
208 
209  // writer.h
210  class FastWriter;
211  class StyledWriter;
212 
213  // reader.h
214  class Reader;
215 
216  // features.h
217  class Features;
218 
219  // value.h
220  typedef unsigned int ArrayIndex;
221  class StaticString;
222  class Path;
223  class PathArgument;
224  class Value;
225  class ValueIteratorBase;
226  class ValueIterator;
227  class ValueConstIterator;
228 #ifdef JSON_VALUE_USE_INTERNAL_MAP
229  class ValueMapAllocator;
230  class ValueInternalLink;
231  class ValueInternalArray;
232  class ValueInternalMap;
233 #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
234 
235 } // namespace Json
236 
237 
238 #endif // JSON_FORWARDS_H_INCLUDED
239 
240 // //////////////////////////////////////////////////////////////////////
241 // End of content of file: include/json/forwards.h
242 // //////////////////////////////////////////////////////////////////////
243 
244 
245 
246 
247 
248 
249 // //////////////////////////////////////////////////////////////////////
250 // Beginning of content of file: include/json/features.h
251 // //////////////////////////////////////////////////////////////////////
252 
253 // Copyright 2007-2010 Baptiste Lepilleur
254 // Distributed under MIT license, or public domain if desired and
255 // recognized in your jurisdiction.
256 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
257 
258 #ifndef CPPTL_JSON_FEATURES_H_INCLUDED
259 # define CPPTL_JSON_FEATURES_H_INCLUDED
260 
261 #if !defined(JSON_IS_AMALGAMATION)
262 # include "forwards.h"
263 #endif // if !defined(JSON_IS_AMALGAMATION)
264 
265 namespace Json {
266 
272  {
273  public:
279  static Features all();
280 
286  static Features strictMode();
287 
290  Features();
291 
294 
297  };
298 
299 } // namespace Json
300 
301 #endif // CPPTL_JSON_FEATURES_H_INCLUDED
302 
303 // //////////////////////////////////////////////////////////////////////
304 // End of content of file: include/json/features.h
305 // //////////////////////////////////////////////////////////////////////
306 
307 
308 
309 
310 
311 
312 // //////////////////////////////////////////////////////////////////////
313 // Beginning of content of file: include/json/value.h
314 // //////////////////////////////////////////////////////////////////////
315 
316 // Copyright 2007-2010 Baptiste Lepilleur
317 // Distributed under MIT license, or public domain if desired and
318 // recognized in your jurisdiction.
319 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
320 
321 #ifndef CPPTL_JSON_H_INCLUDED
322 # define CPPTL_JSON_H_INCLUDED
323 
324 #if !defined(JSON_IS_AMALGAMATION)
325 # include "forwards.h"
326 #endif // if !defined(JSON_IS_AMALGAMATION)
327 # include <string>
328 # include <vector>
329 
330 # ifndef JSON_USE_CPPTL_SMALLMAP
331 # include <map>
332 # else
333 # include <cpptl/smallmap.h>
334 # endif
335 # ifdef JSON_USE_CPPTL
336 # include <cpptl/forwards.h>
337 # endif
338 
341 namespace Json {
342 
346  {
347  nullValue = 0,
355  };
356 
358  {
363  };
364 
365 //# ifdef JSON_USE_CPPTL
366 // typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
367 // typedef CppTL::AnyEnumerator<const Value &> EnumValues;
368 //# endif
369 
385  {
386  public:
387  explicit StaticString( const char *czstring )
388  : str_( czstring )
389  {
390  }
391 
392  operator const char *() const
393  {
394  return str_;
395  }
396 
397  const char *c_str() const
398  {
399  return str_;
400  }
401 
402  private:
403  const char *str_;
404  };
405 
434  {
435  friend class ValueIteratorBase;
436 # ifdef JSON_VALUE_USE_INTERNAL_MAP
437  friend class ValueInternalLink;
438  friend class ValueInternalMap;
439 # endif
440  public:
441  typedef std::vector<std::string> Members;
444  typedef Json::UInt UInt;
445  typedef Json::Int Int;
446 # if defined(JSON_HAS_INT64)
449 #endif // defined(JSON_HAS_INT64)
453 
454  static const Value null;
456  static const LargestInt minLargestInt;
458  static const LargestInt maxLargestInt;
460  static const LargestUInt maxLargestUInt;
461 
463  static const Int minInt;
465  static const Int maxInt;
467  static const UInt maxUInt;
468 
470  static const Int64 minInt64;
472  static const Int64 maxInt64;
474  static const UInt64 maxUInt64;
475 
476  private:
477 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
478 # ifndef JSON_VALUE_USE_INTERNAL_MAP
479  class CZString
480  {
481  public:
483  {
484  noDuplication = 0,
486  duplicateOnCopy
487  };
488  CZString( ArrayIndex index );
489  CZString( const char *cstr, DuplicationPolicy allocate );
490  CZString( const CZString &other );
491  ~CZString();
492  CZString &operator =( const CZString &other );
493  bool operator<( const CZString &other ) const;
494  bool operator==( const CZString &other ) const;
495  ArrayIndex index() const;
496  const char *c_str() const;
497  bool isStaticString() const;
498  private:
499  void swap( CZString &other );
500  const char *cstr_;
501  ArrayIndex index_;
502  };
503 
504  public:
505 # ifndef JSON_USE_CPPTL_SMALLMAP
506  typedef std::map<CZString, Value> ObjectValues;
507 # else
508  typedef CppTL::SmallMap<CZString, Value> ObjectValues;
509 # endif // ifndef JSON_USE_CPPTL_SMALLMAP
510 # endif // ifndef JSON_VALUE_USE_INTERNAL_MAP
511 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
512 
513  public:
529  Value( ValueType type = nullValue );
530  Value( Int value );
531  Value( UInt value );
532 #if defined(JSON_HAS_INT64)
533  Value( Int64 value );
534  Value( UInt64 value );
535 #endif // if defined(JSON_HAS_INT64)
536  Value( double value );
537  Value( const char *value );
538  Value( const char *beginValue, const char *endValue );
549  Value( const StaticString &value );
550  Value( const std::string &value );
551 # ifdef JSON_USE_CPPTL
552  Value( const CppTL::ConstString &value );
553 # endif
554  Value( bool value );
555  Value( const Value &other );
556  ~Value();
557 
558  Value &operator=( const Value &other );
562  void swap( Value &other );
563 
564  ValueType type() const;
565 
566  bool operator <( const Value &other ) const;
567  bool operator <=( const Value &other ) const;
568  bool operator >=( const Value &other ) const;
569  bool operator >( const Value &other ) const;
570 
571  bool operator ==( const Value &other ) const;
572  bool operator !=( const Value &other ) const;
573 
574  int compare( const Value &other ) const;
575 
576  const char *asCString() const;
577  std::string asString() const;
578 # ifdef JSON_USE_CPPTL
579  CppTL::ConstString asConstString() const;
580 # endif
581  Int asInt() const;
582  UInt asUInt() const;
583  Int64 asInt64() const;
584  UInt64 asUInt64() const;
585  LargestInt asLargestInt() const;
586  LargestUInt asLargestUInt() const;
587  float asFloat() const;
588  double asDouble() const;
589  bool asBool() const;
590 
591  bool isNull() const;
592  bool isBool() const;
593  bool isInt() const;
594  bool isUInt() const;
595  bool isIntegral() const;
596  bool isDouble() const;
597  bool isNumeric() const;
598  bool isString() const;
599  bool isArray() const;
600  bool isObject() const;
601 
602  bool isConvertibleTo( ValueType other ) const;
603 
605  ArrayIndex size() const;
606 
609  bool empty() const;
610 
612  bool operator!() const;
613 
617  void clear();
618 
624  void resize( ArrayIndex size );
625 
631  Value &operator[]( ArrayIndex index );
632 
638  Value &operator[]( int index );
639 
643  const Value &operator[]( ArrayIndex index ) const;
644 
648  const Value &operator[]( int index ) const;
649 
652  Value get( ArrayIndex index,
653  const Value &defaultValue ) const;
655  bool isValidIndex( ArrayIndex index ) const;
659  Value &append( const Value &value );
660 
662  Value &operator[]( const char *key );
664  const Value &operator[]( const char *key ) const;
666  Value &operator[]( const std::string &key );
668  const Value &operator[]( const std::string &key ) const;
680  Value &operator[]( const StaticString &key );
681 # ifdef JSON_USE_CPPTL
682  Value &operator[]( const CppTL::ConstString &key );
685  const Value &operator[]( const CppTL::ConstString &key ) const;
686 # endif
687  Value get( const char *key,
689  const Value &defaultValue ) const;
691  Value get( const std::string &key,
692  const Value &defaultValue ) const;
693 # ifdef JSON_USE_CPPTL
694  Value get( const CppTL::ConstString &key,
696  const Value &defaultValue ) const;
697 # endif
698  Value removeMember( const char* key );
706  Value removeMember( const std::string &key );
707 
709  bool isMember( const char *key ) const;
711  bool isMember( const std::string &key ) const;
712 # ifdef JSON_USE_CPPTL
713  bool isMember( const CppTL::ConstString &key ) const;
715 # endif
716 
722  Members getMemberNames() const;
723 
724 //# ifdef JSON_USE_CPPTL
725 // EnumMemberNames enumMemberNames() const;
726 // EnumValues enumValues() const;
727 //# endif
728 
730  void setComment( const char *comment,
731  CommentPlacement placement );
733  void setComment( const std::string &comment,
734  CommentPlacement placement );
735  bool hasComment( CommentPlacement placement ) const;
737  std::string getComment( CommentPlacement placement ) const;
738 
739  std::string toStyledString() const;
740 
741  const_iterator begin() const;
742  const_iterator end() const;
743 
744  iterator begin();
745  iterator end();
746 
747  private:
748  Value &resolveReference( const char *key,
749  bool isStatic );
750 
751 # ifdef JSON_VALUE_USE_INTERNAL_MAP
752  inline bool isItemAvailable() const
753  {
754  return itemIsUsed_ == 0;
755  }
756 
757  inline void setItemUsed( bool isUsed = true )
758  {
759  itemIsUsed_ = isUsed ? 1 : 0;
760  }
761 
762  inline bool isMemberNameStatic() const
763  {
764  return memberNameIsStatic_ == 0;
765  }
766 
767  inline void setMemberNameIsStatic( bool isStatic )
768  {
769  memberNameIsStatic_ = isStatic ? 1 : 0;
770  }
771 # endif // # ifdef JSON_VALUE_USE_INTERNAL_MAP
772 
773  private:
774  struct CommentInfo
775  {
776  CommentInfo();
777  ~CommentInfo();
778 
779  void setComment( const char *text );
780 
781  char *comment_;
782  };
783 
784  //struct MemberNamesTransform
785  //{
786  // typedef const char *result_type;
787  // const char *operator()( const CZString &name ) const
788  // {
789  // return name.c_str();
790  // }
791  //};
792 
794  {
795  LargestInt int_;
796  LargestUInt uint_;
797  double real_;
798  bool bool_;
799  char *string_;
800 # ifdef JSON_VALUE_USE_INTERNAL_MAP
801  ValueInternalArray *array_;
802  ValueInternalMap *map_;
803 #else
804  ObjectValues *map_;
805 # endif
806  } value_;
808  int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
809 # ifdef JSON_VALUE_USE_INTERNAL_MAP
810  unsigned int itemIsUsed_ : 1; // used by the ValueInternalMap container.
811  int memberNameIsStatic_ : 1; // used by the ValueInternalMap container.
812 # endif
814  };
815 
816 
820  {
821  public:
822  friend class Path;
823 
824  PathArgument();
825  PathArgument( ArrayIndex index );
826  PathArgument( const char *key );
827  PathArgument( const std::string &key );
828 
829  private:
830  enum Kind
831  {
832  kindNone = 0,
834  kindKey
835  };
836  std::string key_;
839  };
840 
852  class Path
853  {
854  public:
855  Path( const std::string &path,
856  const PathArgument &a1 = PathArgument(),
857  const PathArgument &a2 = PathArgument(),
858  const PathArgument &a3 = PathArgument(),
859  const PathArgument &a4 = PathArgument(),
860  const PathArgument &a5 = PathArgument() );
861 
862  const Value &resolve( const Value &root ) const;
863  Value resolve( const Value &root,
864  const Value &defaultValue ) const;
866  Value &make( Value &root ) const;
867 
868  private:
869  typedef std::vector<const PathArgument *> InArgs;
870  typedef std::vector<PathArgument> Args;
871 
872  void makePath( const std::string &path,
873  const InArgs &in );
874  void addPathInArg( const std::string &path,
875  const InArgs &in,
876  InArgs::const_iterator &itInArg,
877  PathArgument::Kind kind );
878  void invalidPath( const std::string &path,
879  int location );
880 
881  Args args_;
882  };
883 
884 
885 
886 #ifdef JSON_VALUE_USE_INTERNAL_MAP
887 
931  class JSON_API ValueMapAllocator
932  {
933  public:
934  virtual ~ValueMapAllocator();
935  virtual ValueInternalMap *newMap() = 0;
936  virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) = 0;
937  virtual void destructMap( ValueInternalMap *map ) = 0;
938  virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) = 0;
939  virtual void releaseMapBuckets( ValueInternalLink *links ) = 0;
940  virtual ValueInternalLink *allocateMapLink() = 0;
941  virtual void releaseMapLink( ValueInternalLink *link ) = 0;
942  };
943 
947  class JSON_API ValueInternalLink
948  {
949  public:
950  enum { itemPerLink = 6 }; // sizeof(ValueInternalLink) = 128 on 32 bits architecture.
951  enum InternalFlags {
952  flagAvailable = 0,
953  flagUsed = 1
954  };
955 
956  ValueInternalLink();
957 
958  ~ValueInternalLink();
959 
960  Value items_[itemPerLink];
961  char *keys_[itemPerLink];
962  ValueInternalLink *previous_;
963  ValueInternalLink *next_;
964  };
965 
966 
979  class JSON_API ValueInternalMap
980  {
981  friend class ValueIteratorBase;
982  friend class Value;
983  public:
984  typedef unsigned int HashKey;
985  typedef unsigned int BucketIndex;
986 
987 # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
988  struct IteratorState
989  {
990  IteratorState()
991  : map_(0)
992  , link_(0)
993  , itemIndex_(0)
994  , bucketIndex_(0)
995  {
996  }
997  ValueInternalMap *map_;
998  ValueInternalLink *link_;
999  BucketIndex itemIndex_;
1000  BucketIndex bucketIndex_;
1001  };
1002 # endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
1003 
1004  ValueInternalMap();
1005  ValueInternalMap( const ValueInternalMap &other );
1006  ValueInternalMap &operator =( const ValueInternalMap &other );
1007  ~ValueInternalMap();
1008 
1009  void swap( ValueInternalMap &other );
1010 
1011  BucketIndex size() const;
1012 
1013  void clear();
1014 
1015  bool reserveDelta( BucketIndex growth );
1016 
1017  bool reserve( BucketIndex newItemCount );
1018 
1019  const Value *find( const char *key ) const;
1020 
1021  Value *find( const char *key );
1022 
1023  Value &resolveReference( const char *key,
1024  bool isStatic );
1025 
1026  void remove( const char *key );
1027 
1028  void doActualRemove( ValueInternalLink *link,
1029  BucketIndex index,
1030  BucketIndex bucketIndex );
1031 
1032  ValueInternalLink *&getLastLinkInBucket( BucketIndex bucketIndex );
1033 
1034  Value &setNewItem( const char *key,
1035  bool isStatic,
1036  ValueInternalLink *link,
1037  BucketIndex index );
1038 
1039  Value &unsafeAdd( const char *key,
1040  bool isStatic,
1041  HashKey hashedKey );
1042 
1043  HashKey hash( const char *key ) const;
1044 
1045  int compare( const ValueInternalMap &other ) const;
1046 
1047  private:
1048  void makeBeginIterator( IteratorState &it ) const;
1049  void makeEndIterator( IteratorState &it ) const;
1050  static bool equals( const IteratorState &x, const IteratorState &other );
1051  static void increment( IteratorState &iterator );
1052  static void incrementBucket( IteratorState &iterator );
1053  static void decrement( IteratorState &iterator );
1054  static const char *key( const IteratorState &iterator );
1055  static const char *key( const IteratorState &iterator, bool &isStatic );
1056  static Value &value( const IteratorState &iterator );
1057  static int distance( const IteratorState &x, const IteratorState &y );
1058 
1059  private:
1060  ValueInternalLink *buckets_;
1061  ValueInternalLink *tailLink_;
1062  BucketIndex bucketsSize_;
1063  BucketIndex itemCount_;
1064  };
1065 
1077  class JSON_API ValueInternalArray
1078  {
1079  friend class Value;
1080  friend class ValueIteratorBase;
1081  public:
1082  enum { itemsPerPage = 8 }; // should be a power of 2 for fast divide and modulo.
1083  typedef Value::ArrayIndex ArrayIndex;
1084  typedef unsigned int PageIndex;
1085 
1086 # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
1087  struct IteratorState // Must be a POD
1088  {
1089  IteratorState()
1090  : array_(0)
1091  , currentPageIndex_(0)
1092  , currentItemIndex_(0)
1093  {
1094  }
1095  ValueInternalArray *array_;
1096  Value **currentPageIndex_;
1097  unsigned int currentItemIndex_;
1098  };
1099 # endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
1100 
1101  ValueInternalArray();
1102  ValueInternalArray( const ValueInternalArray &other );
1103  ValueInternalArray &operator =( const ValueInternalArray &other );
1104  ~ValueInternalArray();
1105  void swap( ValueInternalArray &other );
1106 
1107  void clear();
1108  void resize( ArrayIndex newSize );
1109 
1110  Value &resolveReference( ArrayIndex index );
1111 
1112  Value *find( ArrayIndex index ) const;
1113 
1114  ArrayIndex size() const;
1115 
1116  int compare( const ValueInternalArray &other ) const;
1117 
1118  private:
1119  static bool equals( const IteratorState &x, const IteratorState &other );
1120  static void increment( IteratorState &iterator );
1121  static void decrement( IteratorState &iterator );
1122  static Value &dereference( const IteratorState &iterator );
1123  static Value &unsafeDereference( const IteratorState &iterator );
1124  static int distance( const IteratorState &x, const IteratorState &y );
1125  static ArrayIndex indexOf( const IteratorState &iterator );
1126  void makeBeginIterator( IteratorState &it ) const;
1127  void makeEndIterator( IteratorState &it ) const;
1128  void makeIterator( IteratorState &it, ArrayIndex index ) const;
1129 
1130  void makeIndexValid( ArrayIndex index );
1131 
1132  Value **pages_;
1133  ArrayIndex size_;
1134  PageIndex pageCount_;
1135  };
1136 
1196  class JSON_API ValueArrayAllocator
1197  {
1198  public:
1199  virtual ~ValueArrayAllocator();
1200  virtual ValueInternalArray *newArray() = 0;
1201  virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) = 0;
1202  virtual void destructArray( ValueInternalArray *array ) = 0;
1214  virtual void reallocateArrayPageIndex( Value **&indexes,
1215  ValueInternalArray::PageIndex &indexCount,
1216  ValueInternalArray::PageIndex minNewIndexCount ) = 0;
1217  virtual void releaseArrayPageIndex( Value **indexes,
1218  ValueInternalArray::PageIndex indexCount ) = 0;
1219  virtual Value *allocateArrayPage() = 0;
1220  virtual void releaseArrayPage( Value *value ) = 0;
1221  };
1222 #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
1223 
1224 
1229  {
1230  public:
1231  typedef unsigned int size_t;
1232  typedef int difference_type;
1234 
1236 #ifndef JSON_VALUE_USE_INTERNAL_MAP
1237  explicit ValueIteratorBase( const Value::ObjectValues::iterator &current );
1238 #else
1239  ValueIteratorBase( const ValueInternalArray::IteratorState &state );
1240  ValueIteratorBase( const ValueInternalMap::IteratorState &state );
1241 #endif
1242 
1243  bool operator ==( const SelfType &other ) const
1244  {
1245  return isEqual( other );
1246  }
1247 
1248  bool operator !=( const SelfType &other ) const
1249  {
1250  return !isEqual( other );
1251  }
1252 
1253  difference_type operator -( const SelfType &other ) const
1254  {
1255  return computeDistance( other );
1256  }
1257 
1259  Value key() const;
1260 
1262  UInt index() const;
1263 
1265  const char *memberName() const;
1266 
1267  protected:
1268  Value &deref() const;
1269 
1270  void increment();
1271 
1272  void decrement();
1273 
1274  difference_type computeDistance( const SelfType &other ) const;
1275 
1276  bool isEqual( const SelfType &other ) const;
1277 
1278  void copy( const SelfType &other );
1279 
1280  private:
1281 #ifndef JSON_VALUE_USE_INTERNAL_MAP
1282  Value::ObjectValues::iterator current_;
1283  // Indicates that iterator is for a null value.
1284  bool isNull_;
1285 #else
1286  union
1287  {
1288  ValueInternalArray::IteratorState array_;
1289  ValueInternalMap::IteratorState map_;
1290  } iterator_;
1291  bool isArray_;
1292 #endif
1293  };
1294 
1299  {
1300  friend class Value;
1301  public:
1302  typedef unsigned int size_t;
1303  typedef int difference_type;
1304  typedef const Value &reference;
1305  typedef const Value *pointer;
1307 
1309  private:
1312 #ifndef JSON_VALUE_USE_INTERNAL_MAP
1313  explicit ValueConstIterator( const Value::ObjectValues::iterator &current );
1314 #else
1315  ValueConstIterator( const ValueInternalArray::IteratorState &state );
1316  ValueConstIterator( const ValueInternalMap::IteratorState &state );
1317 #endif
1318  public:
1319  SelfType &operator =( const ValueIteratorBase &other );
1320 
1321  SelfType operator++( int )
1322  {
1323  SelfType temp( *this );
1324  ++*this;
1325  return temp;
1326  }
1327 
1328  SelfType operator--( int )
1329  {
1330  SelfType temp( *this );
1331  --*this;
1332  return temp;
1333  }
1334 
1335  SelfType &operator--()
1336  {
1337  decrement();
1338  return *this;
1339  }
1340 
1341  SelfType &operator++()
1342  {
1343  increment();
1344  return *this;
1345  }
1346 
1347  reference operator *() const
1348  {
1349  return deref();
1350  }
1351  };
1352 
1353 
1357  {
1358  friend class Value;
1359  public:
1360  typedef unsigned int size_t;
1361  typedef int difference_type;
1362  typedef Value &reference;
1363  typedef Value *pointer;
1365 
1366  ValueIterator();
1367  ValueIterator( const ValueConstIterator &other );
1368  ValueIterator( const ValueIterator &other );
1369  private:
1372 #ifndef JSON_VALUE_USE_INTERNAL_MAP
1373  explicit ValueIterator( const Value::ObjectValues::iterator &current );
1374 #else
1375  ValueIterator( const ValueInternalArray::IteratorState &state );
1376  ValueIterator( const ValueInternalMap::IteratorState &state );
1377 #endif
1378  public:
1379 
1380  SelfType &operator =( const SelfType &other );
1381 
1382  SelfType operator++( int )
1383  {
1384  SelfType temp( *this );
1385  ++*this;
1386  return temp;
1387  }
1388 
1389  SelfType operator--( int )
1390  {
1391  SelfType temp( *this );
1392  --*this;
1393  return temp;
1394  }
1395 
1396  SelfType &operator--()
1397  {
1398  decrement();
1399  return *this;
1400  }
1401 
1402  SelfType &operator++()
1403  {
1404  increment();
1405  return *this;
1406  }
1407 
1408  reference operator *() const
1409  {
1410  return deref();
1411  }
1412  };
1413 
1414 
1415 } // namespace Json
1416 
1417 
1418 #endif // CPPTL_JSON_H_INCLUDED
1419 
1420 // //////////////////////////////////////////////////////////////////////
1421 // End of content of file: include/json/value.h
1422 // //////////////////////////////////////////////////////////////////////
1423 
1424 
1425 
1426 
1427 
1428 
1429 // //////////////////////////////////////////////////////////////////////
1430 // Beginning of content of file: include/json/reader.h
1431 // //////////////////////////////////////////////////////////////////////
1432 
1433 // Copyright 2007-2010 Baptiste Lepilleur
1434 // Distributed under MIT license, or public domain if desired and
1435 // recognized in your jurisdiction.
1436 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
1437 
1438 #ifndef CPPTL_JSON_READER_H_INCLUDED
1439 # define CPPTL_JSON_READER_H_INCLUDED
1440 
1441 #if !defined(JSON_IS_AMALGAMATION)
1442 # include "features.h"
1443 # include "value.h"
1444 #endif // if !defined(JSON_IS_AMALGAMATION)
1445 # include <deque>
1446 # include <stack>
1447 # include <string>
1448 # include <iostream>
1449 
1450 namespace Json {
1451 
1456  {
1457  public:
1458  typedef char Char;
1459  typedef const Char *Location;
1460 
1464  Reader();
1465 
1469  Reader( const Features &features );
1470 
1481  bool parse( const std::string &document,
1482  Value &root,
1483  bool collectComments = true );
1484 
1497  bool parse( const char *beginDoc, const char *endDoc,
1498  Value &root,
1499  bool collectComments = true );
1500 
1503  bool parse( std::istream &is,
1504  Value &root,
1505  bool collectComments = true );
1506 
1513  JSONCPP_DEPRECATED("Use getFormattedErrorMessages instead")
1514  std::string getFormatedErrorMessages() const;
1515 
1521  std::string getFormattedErrorMessages() const;
1522 
1523  private:
1525  {
1526  tokenEndOfStream = 0,
1539  tokenError
1540  };
1541 
1542  class Token
1543  {
1544  public:
1546  Location start_;
1547  Location end_;
1548  };
1549 
1551  {
1552  public:
1554  std::string message_;
1555  Location extra_;
1556  };
1557 
1558  typedef std::deque<ErrorInfo> Errors;
1559 
1560  bool expectToken( TokenType type, Token &token, const char *message );
1561  bool readToken( Token &token );
1562  void skipSpaces();
1563  bool match( Location pattern,
1564  int patternLength );
1565  bool readComment();
1566  bool readCStyleComment();
1567  bool readCppStyleComment();
1568  bool readString();
1569  void readNumber();
1570  bool readValue();
1571  bool readObject( Token &token );
1572  bool readArray( Token &token );
1573  bool decodeNumber( Token &token );
1574  bool decodeString( Token &token );
1575  bool decodeString( Token &token, std::string &decoded );
1576  bool decodeDouble( Token &token );
1577  bool decodeUnicodeCodePoint( Token &token,
1578  Location &current,
1579  Location end,
1580  unsigned int &unicode );
1581  bool decodeUnicodeEscapeSequence( Token &token,
1582  Location &current,
1583  Location end,
1584  unsigned int &unicode );
1585  bool addError( const std::string &message,
1586  Token &token,
1587  Location extra = 0 );
1588  bool recoverFromError( TokenType skipUntilToken );
1589  bool addErrorAndRecover( const std::string &message,
1590  Token &token,
1591  TokenType skipUntilToken );
1592  void skipUntilSpace();
1593  Value &currentValue();
1594  Char getNextChar();
1595  void getLocationLineAndColumn( Location location,
1596  int &line,
1597  int &column ) const;
1598  std::string getLocationLineAndColumn( Location location ) const;
1599  void addComment( Location begin,
1600  Location end,
1601  CommentPlacement placement );
1602  void skipCommentTokens( Token &token );
1603 
1604  typedef std::stack<Value *> Nodes;
1605  Nodes nodes_;
1606  Errors errors_;
1607  std::string document_;
1608  Location begin_;
1609  Location end_;
1610  Location current_;
1611  Location lastValueEnd_;
1613  std::string commentsBefore_;
1616  };
1617 
1642  std::istream& operator>>( std::istream&, Value& );
1643 
1644 } // namespace Json
1645 
1646 #endif // CPPTL_JSON_READER_H_INCLUDED
1647 
1648 // //////////////////////////////////////////////////////////////////////
1649 // End of content of file: include/json/reader.h
1650 // //////////////////////////////////////////////////////////////////////
1651 
1652 
1653 
1654 
1655 
1656 
1657 // //////////////////////////////////////////////////////////////////////
1658 // Beginning of content of file: include/json/writer.h
1659 // //////////////////////////////////////////////////////////////////////
1660 
1661 // Copyright 2007-2010 Baptiste Lepilleur
1662 // Distributed under MIT license, or public domain if desired and
1663 // recognized in your jurisdiction.
1664 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
1665 
1666 #ifndef JSON_WRITER_H_INCLUDED
1667 # define JSON_WRITER_H_INCLUDED
1668 
1669 #if !defined(JSON_IS_AMALGAMATION)
1670 # include "value.h"
1671 #endif // if !defined(JSON_IS_AMALGAMATION)
1672 # include <vector>
1673 # include <string>
1674 # include <iostream>
1675 
1676 namespace Json {
1677 
1678  class Value;
1679 
1683  {
1684  public:
1685  virtual ~Writer();
1686 
1687  virtual std::string write( const Value &root ) = 0;
1688  };
1689 
1696  class JSON_API FastWriter : public Writer
1697  {
1698  public:
1699  FastWriter();
1700  virtual ~FastWriter(){}
1701 
1702  void enableYAMLCompatibility();
1703 
1704  public: // overridden from Writer
1705  virtual std::string write( const Value &root );
1706 
1707  private:
1708  void writeValue( const Value &value );
1709 
1710  std::string document_;
1712  };
1713 
1733  {
1734  public:
1735  StyledWriter();
1736  virtual ~StyledWriter(){}
1737 
1738  public: // overridden from Writer
1743  virtual std::string write( const Value &root );
1744 
1745  private:
1746  void writeValue( const Value &value );
1747  void writeArrayValue( const Value &value );
1748  bool isMultineArray( const Value &value );
1749  void pushValue( const std::string &value );
1750  void writeIndent();
1751  void writeWithIndent( const std::string &value );
1752  void indent();
1753  void unindent();
1754  void writeCommentBeforeValue( const Value &root );
1755  void writeCommentAfterValueOnSameLine( const Value &root );
1756  bool hasCommentForValue( const Value &value );
1757  static std::string normalizeEOL( const std::string &text );
1758 
1759  typedef std::vector<std::string> ChildValues;
1760 
1761  ChildValues childValues_;
1762  std::string document_;
1763  std::string indentString_;
1767  };
1768 
1790  {
1791  public:
1792  StyledStreamWriter( std::string indentation="\t" );
1794 
1795  public:
1801  void write( std::ostream &out, const Value &root );
1802 
1803  private:
1804  void writeValue( const Value &value );
1805  void writeArrayValue( const Value &value );
1806  bool isMultineArray( const Value &value );
1807  void pushValue( const std::string &value );
1808  void writeIndent();
1809  void writeWithIndent( const std::string &value );
1810  void indent();
1811  void unindent();
1812  void writeCommentBeforeValue( const Value &root );
1813  void writeCommentAfterValueOnSameLine( const Value &root );
1814  bool hasCommentForValue( const Value &value );
1815  static std::string normalizeEOL( const std::string &text );
1816 
1817  typedef std::vector<std::string> ChildValues;
1818 
1819  ChildValues childValues_;
1820  std::ostream* document_;
1821  std::string indentString_;
1823  std::string indentation_;
1825  };
1826 
1827 # if defined(JSON_HAS_INT64)
1828  std::string JSON_API valueToString( Int value );
1829  std::string JSON_API valueToString( UInt value );
1830 # endif // if defined(JSON_HAS_INT64)
1831  std::string JSON_API valueToString( LargestInt value );
1832  std::string JSON_API valueToString( LargestUInt value );
1833  std::string JSON_API valueToString( double value );
1834  std::string JSON_API valueToString( bool value );
1835  std::string JSON_API valueToQuotedString( const char *value );
1836 
1839  std::ostream& operator<<( std::ostream&, const Value &root );
1840 
1841 } // namespace Json
1842 
1843 
1844 
1845 #endif // JSON_WRITER_H_INCLUDED
1846 
1847 // //////////////////////////////////////////////////////////////////////
1848 // End of content of file: include/json/writer.h
1849 // //////////////////////////////////////////////////////////////////////
1850 
1851 
1852 
1853 
1854 
1855 #endif //ifndef JSON_AMALGATED_H_INCLUDED
unsigned int UInt
unsigned integer value
Definition: json.h:349
const char * str_
Definition: json.h:403
std::stack< Value * > Nodes
Definition: json.h:1604
std::vector< std::string > ChildValues
Definition: json.h:1759
std::vector< std::string > Members
Definition: json.h:441
std::ostream * document_
Definition: json.h:1820
LargestInt int_
Definition: json.h:795
double value
Definition: json.h:350
std::string JSON_API valueToQuotedString(const char *value)
Definition: jsoncpp.cpp:3503
Location current_
Definition: json.h:1610
ValueIterator iterator
Definition: json.h:442
std::ostream & operator<<(std::ostream &, const Value &root)
Output using the StyledStreamWriter.
Definition: jsoncpp.cpp:4213
SelfType operator--(int)
Definition: json.h:1328
bool allowComments_
true if comments are allowed. Default: true.
Definition: json.h:293
#define JSON_API
Definition: json.h:135
Writes a Value in JSON format in a human friendly way, to a stream rather than to a string...
Definition: json.h:1789
ValueType type_
Definition: json.h:807
Json::LargestInt LargestInt
Definition: json.h:450
signed integer value
Definition: json.h:348
static const LargestUInt maxLargestUInt
Maximum unsigned integer value that can be stored in a Json::Value.
Definition: json.h:460
const char * c_str() const
Definition: json.h:397
char Char
Definition: json.h:1458
unsigned int size_t
Definition: json.h:1302
UInt64 LargestUInt
static const LargestInt minLargestInt
Minimum signed integer value that can be stored in a Json::Value.
Definition: json.h:456
std::string indentString_
Definition: json.h:1763
TFSIMD_FORCE_INLINE bool operator==(const Matrix3x3 &m1, const Matrix3x3 &m2)
Json::Int Int
Definition: json.h:445
ArrayIndex index_
Definition: json.h:501
Experimental and untested: represents an element of the "path" to access a node.
Definition: json.h:819
Json::ArrayIndex ArrayIndex
Definition: json.h:452
SelfType & operator++()
Definition: json.h:1341
std::string commentsBefore_
Definition: json.h:1613
std::vector< const PathArgument * > InArgs
Definition: json.h:869
Lightweight wrapper to tag static string.
Definition: json.h:384
ValueConstIterator const_iterator
Definition: json.h:443
bool yamlCompatiblityEnabled_
Definition: json.h:1711
std::string document_
Definition: json.h:1710
int allocated_
Definition: json.h:808
LargestUInt uint_
Definition: json.h:796
TokenType type_
Definition: json.h:1545
bool collectComments_
Definition: json.h:1615
unsigned int ArrayIndex
ObjectValues * map_
Definition: json.h:804
const Value & reference
Definition: json.h:1304
static const UInt maxUInt
Maximum unsigned int value that can be stored in a Json::Value.
Definition: json.h:467
std::string JSON_API valueToString(Int value)
Represents a JSON value.
Definition: json.h:433
Json::Int64 Int64
Definition: json.h:448
ROSCPP_DECL std::string resolve(const std::string &name, bool remap=true)
std::string message_
Definition: json.h:1554
void swap(Bag &a, Bag &b)
Configuration passed to reader and writer. This configuration object can be used to force the Reader ...
Definition: json.h:271
bool addChildValues_
Definition: json.h:1766
a comment placed on the line before a value
Definition: json.h:359
static const UInt64 maxUInt64
Maximum unsigned 64 bits int value that can be stored in a Json::Value.
Definition: json.h:474
std::deque< ErrorInfo > Errors
Definition: json.h:1558
static const Int64 maxInt64
Maximum signed 64 bits int value that can be stored in a Json::Value.
Definition: json.h:472
long long int Int64
Location start_
Definition: json.h:1546
Outputs a Value in JSON format without formatting (not human friendly).
Definition: json.h:1696
SelfType & operator--()
Definition: json.h:1396
static const Int minInt
Minimum signed int value that can be stored in a Json::Value.
Definition: json.h:463
Int64 LargestInt
static const Value null
Definition: json.h:454
std::map< CZString, Value > ObjectValues
Definition: json.h:506
static const Int64 minInt64
Minimum signed 64 bits int value that can be stored in a Json::Value.
Definition: json.h:470
Abstract class for writers.
Definition: json.h:1682
ValueConstIterator SelfType
Definition: json.h:1306
Json::UInt UInt
Definition: json.h:444
ArrayIndex index_
Definition: json.h:837
object value (collection of name/value pairs).
Definition: json.h:354
bool value
Definition: json.h:352
Json::LargestUInt LargestUInt
Definition: json.h:451
SelfType operator--(int)
Definition: json.h:1389
Location end_
Definition: json.h:1547
ValueType
Type of the value held by a Value object.
Definition: json.h:345
Errors errors_
Definition: json.h:1606
virtual ~StyledWriter()
Definition: json.h:1736
Args args_
Definition: json.h:881
std::string key_
Definition: json.h:836
JSON (JavaScript Object Notation).
ValueIteratorBase SelfType
Definition: json.h:1233
a comment just after a value on the same line
Definition: json.h:360
std::istream & operator>>(std::istream &, Value &)
Read from &#39;sin&#39; into &#39;root&#39;.
Definition: jsoncpp.cpp:1059
Json::UInt64 UInt64
Definition: json.h:447
SelfType & operator++()
Definition: json.h:1402
Location end_
Definition: json.h:1609
base class for Value iterators.
Definition: json.h:1228
std::string indentString_
Definition: json.h:1821
CommentPlacement
Definition: json.h:357
int Int
a comment on the line after a value (only make sense for root value)
Definition: json.h:361
Value * pointer
Definition: json.h:1363
&#39;null&#39; value
Definition: json.h:347
SelfType & operator--()
Definition: json.h:1335
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
Definition: jsoncpp.cpp:244
UTF-8 string value.
Definition: json.h:351
SelfType operator++(int)
Definition: json.h:1382
static const Int maxInt
Maximum signed int value that can be stored in a Json::Value.
Definition: json.h:465
unsigned int size_t
Definition: json.h:1231
Nodes nodes_
Definition: json.h:1605
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)
std::string indentation_
Definition: json.h:1823
StaticString(const char *czstring)
Definition: json.h:387
Unserialize a JSON document into a Value.
Definition: json.h:1455
SelfType operator++(int)
Definition: json.h:1321
const char * cstr_
Definition: json.h:500
ChildValues childValues_
Definition: json.h:1819
unsigned long long int UInt64
Features features_
Definition: json.h:1614
std::vector< PathArgument > Args
Definition: json.h:870
ValueIterator SelfType
Definition: json.h:1364
CommentInfo * comments_
Definition: json.h:813
static const LargestInt maxLargestInt
Maximum signed integer value that can be stored in a Json::Value.
Definition: json.h:458
std::string document_
Definition: json.h:1762
Iterator for object and array value.
Definition: json.h:1356
Location lastValueEnd_
Definition: json.h:1611
const Char * Location
Definition: json.h:1459
std::string document_
Definition: json.h:1607
std::vector< std::string > ChildValues
Definition: json.h:1817
Writes a Value in JSON format in a human friendly way.
Definition: json.h:1732
Experimental and untested: represents a "path" to access a node.
Definition: json.h:852
virtual ~FastWriter()
Definition: json.h:1700
ChildValues childValues_
Definition: json.h:1761
bool strictRoot_
true if root must be either an array or an object value. Default: false.
Definition: json.h:296
Location begin_
Definition: json.h:1608
const iterator for object and array value.
Definition: json.h:1298
const Value * pointer
Definition: json.h:1305
Value * lastValue_
Definition: json.h:1612
#define JSONCPP_DEPRECATED(message)
Definition: json.h:154
unsigned int size_t
Definition: json.h:1360
void increment(int *value)
Value::ObjectValues::iterator current_
Definition: json.h:1282
array value (ordered list)
Definition: json.h:353
Value & reference
Definition: json.h:1362


find_object_2d
Author(s): Mathieu Labbe
autogenerated on Mon Dec 12 2022 03:20:09