PyNE C++
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 #ifdef PYNE_IS_AMALGAMATED
72  #if !defined(JSON_IS_AMALGAMATION)
73  #define JSON_IS_AMALGAMATION
74  #endif
75 #endif
76 
77 
78 
79 #ifndef JSON_AMALGATED_H_INCLUDED
80 # define JSON_AMALGATED_H_INCLUDED
81 #define JSON_IS_AMALGATED
84 
85 // //////////////////////////////////////////////////////////////////////
86 // Beginning of content of file: include/json/config.h
87 // //////////////////////////////////////////////////////////////////////
88 
89 // Copyright 2007-2010 Baptiste Lepilleur
90 // Distributed under MIT license, or public domain if desired and
91 // recognized in your jurisdiction.
92 // See file LICENSE for detail or copy at https://github.com/open-source-parsers/jsoncpp/blob/master/LICENSE
93 
94 #ifndef JSON_CONFIG_H_INCLUDED
95 # define JSON_CONFIG_H_INCLUDED
96 
98 //# define JSON_IN_CPPTL 1
99 
101 //# define JSON_USE_CPPTL 1
104 //# define JSON_USE_CPPTL_SMALLMAP 1
108 //# define JSON_VALUE_USE_INTERNAL_MAP 1
113 //# define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1
114 
117 # define JSON_USE_EXCEPTION 1
118 
122 // #define JSON_IS_AMALGAMATION
123 
124 
125 # ifdef JSON_IN_CPPTL
126 # include <cpptl/config.h>
127 # ifndef JSON_USE_CPPTL
128 # define JSON_USE_CPPTL 1
129 # endif
130 # endif
131 
132 # ifdef JSON_IN_CPPTL
133 # define JSON_API CPPTL_API
134 # elif defined(JSON_DLL_BUILD)
135 # define JSON_API __declspec(dllexport)
136 # elif defined(JSON_DLL)
137 # define JSON_API __declspec(dllimport)
138 # else
139 # define JSON_API
140 # endif
141 
142 // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for integer
143 // Storages, and 64 bits integer support is disabled.
144 // #define JSON_NO_INT64 1
145 
146 #if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC 6
147 // Microsoft Visual Studio 6 only support conversion from __int64 to double
148 // (no conversion from unsigned __int64).
149 #define JSON_USE_INT64_DOUBLE_CONVERSION 1
150 #endif // if defined(_MSC_VER) && _MSC_VER < 1200 // MSVC 6
151 
152 #if defined(_MSC_VER) && _MSC_VER >= 1500 // MSVC 2008
153 # define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
155 #endif
156 
157 #if !defined(JSONCPP_DEPRECATED)
158 # define JSONCPP_DEPRECATED(message)
159 #endif // if !defined(JSONCPP_DEPRECATED)
160 
161 namespace Json {
162  typedef int Int;
163  typedef unsigned int UInt;
164 # if defined(JSON_NO_INT64)
165  typedef int LargestInt;
166  typedef unsigned int LargestUInt;
167 # undef JSON_HAS_INT64
168 # else // if defined(JSON_NO_INT64)
169  // For Microsoft Visual use specific types as long long is not supported
170 # if defined(_MSC_VER) // Microsoft Visual Studio
171  typedef __int64 Int64;
172  typedef unsigned __int64 UInt64;
173 # else // if defined(_MSC_VER) // Other platforms, use long long
174  typedef long long int Int64;
175  typedef unsigned long long int UInt64;
176 # endif // if defined(_MSC_VER)
177  typedef Int64 LargestInt;
178  typedef UInt64 LargestUInt;
179 # define JSON_HAS_INT64
180 # endif // if defined(JSON_NO_INT64)
181 } // end namespace Json
182 
183 
184 #endif // JSON_CONFIG_H_INCLUDED
185 
186 // //////////////////////////////////////////////////////////////////////
187 // End of content of file: include/json/config.h
188 // //////////////////////////////////////////////////////////////////////
189 
190 
191 
192 
193 
194 
195 // //////////////////////////////////////////////////////////////////////
196 // Beginning of content of file: include/json/forwards.h
197 // //////////////////////////////////////////////////////////////////////
198 
199 // Copyright 2007-2010 Baptiste Lepilleur
200 // Distributed under MIT license, or public domain if desired and
201 // recognized in your jurisdiction.
202 // See file LICENSE for detail or copy at https://github.com/open-source-parsers/jsoncpp/blob/master/LICENSE
203 
204 #ifndef JSON_FORWARDS_H_INCLUDED
205 # define JSON_FORWARDS_H_INCLUDED
206 
207 #if !defined(JSON_IS_AMALGAMATION)
208 # include "config.h"
209 #endif // if !defined(JSON_IS_AMALGAMATION)
210 
211 namespace Json {
212 
213  // writer.h
214  class FastWriter;
215  class StyledWriter;
216 
217  // reader.h
218  class Reader;
219 
220  // features.h
221  class Features;
222 
223  // value.h
224  typedef unsigned int ArrayIndex;
225  class StaticString;
226  class Path;
227  class PathArgument;
228  class Value;
229  class ValueIteratorBase;
230  class ValueIterator;
231  class ValueConstIterator;
232 #ifdef JSON_VALUE_USE_INTERNAL_MAP
233  class ValueMapAllocator;
234  class ValueInternalLink;
235  class ValueInternalArray;
236  class ValueInternalMap;
237 #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
238 
239 } // namespace Json
240 
241 
242 #endif // JSON_FORWARDS_H_INCLUDED
243 
244 // //////////////////////////////////////////////////////////////////////
245 // End of content of file: include/json/forwards.h
246 // //////////////////////////////////////////////////////////////////////
247 
248 
249 
250 
251 
252 
253 // //////////////////////////////////////////////////////////////////////
254 // Beginning of content of file: include/json/features.h
255 // //////////////////////////////////////////////////////////////////////
256 
257 // Copyright 2007-2010 Baptiste Lepilleur
258 // Distributed under MIT license, or public domain if desired and
259 // recognized in your jurisdiction.
260 // See file LICENSE for detail or copy at https://github.com/open-source-parsers/jsoncpp/blob/master/LICENSE
261 
262 #ifndef CPPTL_JSON_FEATURES_H_INCLUDED
263 # define CPPTL_JSON_FEATURES_H_INCLUDED
264 
265 #if !defined(JSON_IS_AMALGAMATION)
266 # include "forwards.h"
267 #endif // if !defined(JSON_IS_AMALGAMATION)
268 
269 namespace Json {
270 
275  class JSON_API Features
276  {
277  public:
283  static Features all();
284 
290  static Features strictMode();
291 
294  Features();
295 
297  bool allowComments_;
298 
300  bool strictRoot_;
301  };
302 
303 } // namespace Json
304 
305 #endif // CPPTL_JSON_FEATURES_H_INCLUDED
306 
307 // //////////////////////////////////////////////////////////////////////
308 // End of content of file: include/json/features.h
309 // //////////////////////////////////////////////////////////////////////
310 
311 
312 
313 
314 
315 
316 // //////////////////////////////////////////////////////////////////////
317 // Beginning of content of file: include/json/value.h
318 // //////////////////////////////////////////////////////////////////////
319 
320 // Copyright 2007-2010 Baptiste Lepilleur
321 // Distributed under MIT license, or public domain if desired and
322 // recognized in your jurisdiction.
323 // See file LICENSE for detail or copy at https://github.com/open-source-parsers/jsoncpp/blob/master/LICENSE
324 
325 #ifndef CPPTL_JSON_H_INCLUDED
326 # define CPPTL_JSON_H_INCLUDED
327 
328 #if !defined(JSON_IS_AMALGAMATION)
329 # include "forwards.h"
330 #endif // if !defined(JSON_IS_AMALGAMATION)
331 # include <string>
332 # include <vector>
333 
334 # ifndef JSON_USE_CPPTL_SMALLMAP
335 # include <map>
336 # else
337 # include <cpptl/smallmap.h>
338 # endif
339 # ifdef JSON_USE_CPPTL
340 # include <cpptl/forwards.h>
341 # endif
342 
345 namespace Json {
346 
350  {
351  nullValue = 0,
359  };
360 
362  {
366  numberOfCommentPlacement
367  };
368 
369 //# ifdef JSON_USE_CPPTL
370 // typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
371 // typedef CppTL::AnyEnumerator<const Value &> EnumValues;
372 //# endif
373 
388  class JSON_API StaticString
389  {
390  public:
391  explicit StaticString( const char *czstring )
392  : str_( czstring )
393  {
394  }
395 
396  operator const char *() const
397  {
398  return str_;
399  }
400 
401  const char *c_str() const
402  {
403  return str_;
404  }
405 
406  private:
407  const char *str_;
408  };
409 
437  class JSON_API Value
438  {
439  friend class ValueIteratorBase;
440 # ifdef JSON_VALUE_USE_INTERNAL_MAP
441  friend class ValueInternalLink;
442  friend class ValueInternalMap;
443 # endif
444  public:
445  typedef std::vector<std::string> Members;
446  typedef ValueIterator iterator;
447  typedef ValueConstIterator const_iterator;
448  typedef Json::UInt UInt;
449  typedef Json::Int Int;
450 # if defined(JSON_HAS_INT64)
451  typedef Json::UInt64 UInt64;
452  typedef Json::Int64 Int64;
453 #endif // defined(JSON_HAS_INT64)
454  typedef Json::LargestInt LargestInt;
455  typedef Json::LargestUInt LargestUInt;
456  typedef Json::ArrayIndex ArrayIndex;
457 
458  static const Value null;
460  static const LargestInt minLargestInt;
462  static const LargestInt maxLargestInt;
464  static const LargestUInt maxLargestUInt;
465 
467  static const Int minInt;
469  static const Int maxInt;
471  static const UInt maxUInt;
472 
474  static const Int64 minInt64;
476  static const Int64 maxInt64;
478  static const UInt64 maxUInt64;
479 
480  private:
481 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
482 # ifndef JSON_VALUE_USE_INTERNAL_MAP
483  class CZString
484  {
485  public:
486  enum DuplicationPolicy
487  {
488  noDuplication = 0,
489  duplicate,
490  duplicateOnCopy
491  };
492  CZString( ArrayIndex index );
493  CZString( const char *cstr, DuplicationPolicy allocate );
494  CZString( const CZString &other );
495  ~CZString();
496  CZString &operator =( const CZString &other );
497  bool operator<( const CZString &other ) const;
498  bool operator==( const CZString &other ) const;
499  ArrayIndex index() const;
500  const char *c_str() const;
501  bool isStaticString() const;
502  private:
503  void swap( CZString &other );
504  const char *cstr_;
505  ArrayIndex index_;
506  };
507 
508  public:
509 # ifndef JSON_USE_CPPTL_SMALLMAP
510  typedef std::map<CZString, Value> ObjectValues;
511 # else
512  typedef CppTL::SmallMap<CZString, Value> ObjectValues;
513 # endif // ifndef JSON_USE_CPPTL_SMALLMAP
514 # endif // ifndef JSON_VALUE_USE_INTERNAL_MAP
515 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
516 
517  public:
533  Value( ValueType type = nullValue );
534  Value( Int value );
535  Value( UInt value );
536 #if defined(JSON_HAS_INT64)
537  Value( Int64 value );
538  Value( UInt64 value );
539 #endif // if defined(JSON_HAS_INT64)
540  Value( double value );
541  Value( const char *value );
542  Value( const char *beginValue, const char *endValue );
553  Value( const StaticString &value );
554  Value( const std::string &value );
555 # ifdef JSON_USE_CPPTL
556  Value( const CppTL::ConstString &value );
557 # endif
558  Value( bool value );
559  Value( const Value &other );
560  ~Value();
561 
562  Value &operator=( const Value &other );
566  void swap( Value &other );
567 
568  ValueType type() const;
569 
570  bool operator <( const Value &other ) const;
571  bool operator <=( const Value &other ) const;
572  bool operator >=( const Value &other ) const;
573  bool operator >( const Value &other ) const;
574 
575  bool operator ==( const Value &other ) const;
576  bool operator !=( const Value &other ) const;
577 
578  int compare( const Value &other ) const;
579 
580  const char *asCString() const;
581  std::string asString() const;
582 # ifdef JSON_USE_CPPTL
583  CppTL::ConstString asConstString() const;
584 # endif
585  Int asInt() const;
586  UInt asUInt() const;
587  Int64 asInt64() const;
588  UInt64 asUInt64() const;
589  LargestInt asLargestInt() const;
590  LargestUInt asLargestUInt() const;
591  float asFloat() const;
592  double asDouble() const;
593  bool asBool() const;
594 
595  bool isNull() const;
596  bool isBool() const;
597  bool isInt() const;
598  bool isUInt() const;
599  bool isIntegral() const;
600  bool isDouble() const;
601  bool isNumeric() const;
602  bool isString() const;
603  bool isArray() const;
604  bool isObject() const;
605 
606  bool isConvertibleTo( ValueType other ) const;
607 
609  ArrayIndex size() const;
610 
613  bool empty() const;
614 
616  bool operator!() const;
617 
621  void clear();
622 
628  void resize( ArrayIndex size );
629 
635  Value &operator[]( ArrayIndex index );
636 
642  Value &operator[]( int index );
643 
647  const Value &operator[]( ArrayIndex index ) const;
648 
652  const Value &operator[]( int index ) const;
653 
656  Value get( ArrayIndex index,
657  const Value &defaultValue ) const;
659  bool isValidIndex( ArrayIndex index ) const;
663  Value &append( const Value &value );
664 
666  Value &operator[]( const char *key );
668  const Value &operator[]( const char *key ) const;
670  Value &operator[]( const std::string &key );
672  const Value &operator[]( const std::string &key ) const;
684  Value &operator[]( const StaticString &key );
685 # ifdef JSON_USE_CPPTL
686  Value &operator[]( const CppTL::ConstString &key );
689  const Value &operator[]( const CppTL::ConstString &key ) const;
690 # endif
691  Value get( const char *key,
693  const Value &defaultValue ) const;
695  Value get( const std::string &key,
696  const Value &defaultValue ) const;
697 # ifdef JSON_USE_CPPTL
698  Value get( const CppTL::ConstString &key,
700  const Value &defaultValue ) const;
701 # endif
702  Value removeMember( const char* key );
710  Value removeMember( const std::string &key );
711 
713  bool isMember( const char *key ) const;
715  bool isMember( const std::string &key ) const;
716 # ifdef JSON_USE_CPPTL
717  bool isMember( const CppTL::ConstString &key ) const;
719 # endif
720 
726  Members getMemberNames() const;
727 
728 //# ifdef JSON_USE_CPPTL
729 // EnumMemberNames enumMemberNames() const;
730 // EnumValues enumValues() const;
731 //# endif
732 
734  void setComment( const char *comment,
735  CommentPlacement placement );
737  void setComment( const std::string &comment,
738  CommentPlacement placement );
739  bool hasComment( CommentPlacement placement ) const;
741  std::string getComment( CommentPlacement placement ) const;
742 
743  std::string toStyledString() const;
744 
745  const_iterator begin() const;
746  const_iterator end() const;
747 
748  iterator begin();
749  iterator end();
750 
751  private:
752  Value &resolveReference( const char *key,
753  bool isStatic );
754 
755 # ifdef JSON_VALUE_USE_INTERNAL_MAP
756  inline bool isItemAvailable() const
757  {
758  return itemIsUsed_ == 0;
759  }
760 
761  inline void setItemUsed( bool isUsed = true )
762  {
763  itemIsUsed_ = isUsed ? 1 : 0;
764  }
765 
766  inline bool isMemberNameStatic() const
767  {
768  return memberNameIsStatic_ == 0;
769  }
770 
771  inline void setMemberNameIsStatic( bool isStatic )
772  {
773  memberNameIsStatic_ = isStatic ? 1 : 0;
774  }
775 # endif // # ifdef JSON_VALUE_USE_INTERNAL_MAP
776 
777  private:
778  struct CommentInfo
779  {
780  CommentInfo();
781  ~CommentInfo();
782 
783  void setComment( const char *text );
784 
785  char *comment_;
786  };
787 
788  //struct MemberNamesTransform
789  //{
790  // typedef const char *result_type;
791  // const char *operator()( const CZString &name ) const
792  // {
793  // return name.c_str();
794  // }
795  //};
796 
797  union ValueHolder
798  {
799  LargestInt int_;
800  LargestUInt uint_;
801  double real_;
802  bool bool_;
803  char *string_;
804 # ifdef JSON_VALUE_USE_INTERNAL_MAP
805  ValueInternalArray *array_;
806  ValueInternalMap *map_;
807 #else
808  ObjectValues *map_;
809 # endif
810  } value_;
811  ValueType type_ : 8;
812  int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
813 # ifdef JSON_VALUE_USE_INTERNAL_MAP
814  unsigned int itemIsUsed_ : 1; // used by the ValueInternalMap container.
815  int memberNameIsStatic_ : 1; // used by the ValueInternalMap container.
816 # endif
817  CommentInfo *comments_;
818  };
819 
820 
823  class PathArgument
824  {
825  public:
826  friend class Path;
827 
828  PathArgument();
829  PathArgument( ArrayIndex index );
830  PathArgument( const char *key );
831  PathArgument( const std::string &key );
832 
833  private:
834  enum Kind
835  {
836  kindNone = 0,
837  kindIndex,
838  kindKey
839  };
840  std::string key_;
841  ArrayIndex index_;
842  Kind kind_;
843  };
844 
856  class Path
857  {
858  public:
859  Path( const std::string &path,
860  const PathArgument &a1 = PathArgument(),
861  const PathArgument &a2 = PathArgument(),
862  const PathArgument &a3 = PathArgument(),
863  const PathArgument &a4 = PathArgument(),
864  const PathArgument &a5 = PathArgument() );
865 
866  const Value &resolve( const Value &root ) const;
867  Value resolve( const Value &root,
868  const Value &defaultValue ) const;
870  Value &make( Value &root ) const;
871 
872  private:
873  typedef std::vector<const PathArgument *> InArgs;
874  typedef std::vector<PathArgument> Args;
875 
876  void makePath( const std::string &path,
877  const InArgs &in );
878  void addPathInArg( const std::string &path,
879  const InArgs &in,
880  InArgs::const_iterator &itInArg,
881  PathArgument::Kind kind );
882  void invalidPath( const std::string &path,
883  int location );
884 
885  Args args_;
886  };
887 
888 
889 
890 #ifdef JSON_VALUE_USE_INTERNAL_MAP
891 
935  class JSON_API ValueMapAllocator
936  {
937  public:
938  virtual ~ValueMapAllocator();
939  virtual ValueInternalMap *newMap() = 0;
940  virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) = 0;
941  virtual void destructMap( ValueInternalMap *map ) = 0;
942  virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) = 0;
943  virtual void releaseMapBuckets( ValueInternalLink *links ) = 0;
944  virtual ValueInternalLink *allocateMapLink() = 0;
945  virtual void releaseMapLink( ValueInternalLink *link ) = 0;
946  };
947 
951  class JSON_API ValueInternalLink
952  {
953  public:
954  enum { itemPerLink = 6 }; // sizeof(ValueInternalLink) = 128 on 32 bits architecture.
955  enum InternalFlags {
956  flagAvailable = 0,
957  flagUsed = 1
958  };
959 
960  ValueInternalLink();
961 
962  ~ValueInternalLink();
963 
964  Value items_[itemPerLink];
965  char *keys_[itemPerLink];
966  ValueInternalLink *previous_;
967  ValueInternalLink *next_;
968  };
969 
970 
983  class JSON_API ValueInternalMap
984  {
985  friend class ValueIteratorBase;
986  friend class Value;
987  public:
988  typedef unsigned int HashKey;
989  typedef unsigned int BucketIndex;
990 
991 # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
992  struct IteratorState
993  {
994  IteratorState()
995  : map_(0)
996  , link_(0)
997  , itemIndex_(0)
998  , bucketIndex_(0)
999  {
1000  }
1001  ValueInternalMap *map_;
1002  ValueInternalLink *link_;
1003  BucketIndex itemIndex_;
1004  BucketIndex bucketIndex_;
1005  };
1006 # endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
1007 
1008  ValueInternalMap();
1009  ValueInternalMap( const ValueInternalMap &other );
1010  ValueInternalMap &operator =( const ValueInternalMap &other );
1011  ~ValueInternalMap();
1012 
1013  void swap( ValueInternalMap &other );
1014 
1015  BucketIndex size() const;
1016 
1017  void clear();
1018 
1019  bool reserveDelta( BucketIndex growth );
1020 
1021  bool reserve( BucketIndex newItemCount );
1022 
1023  const Value *find( const char *key ) const;
1024 
1025  Value *find( const char *key );
1026 
1027  Value &resolveReference( const char *key,
1028  bool isStatic );
1029 
1030  void remove( const char *key );
1031 
1032  void doActualRemove( ValueInternalLink *link,
1033  BucketIndex index,
1034  BucketIndex bucketIndex );
1035 
1036  ValueInternalLink *&getLastLinkInBucket( BucketIndex bucketIndex );
1037 
1038  Value &setNewItem( const char *key,
1039  bool isStatic,
1040  ValueInternalLink *link,
1041  BucketIndex index );
1042 
1043  Value &unsafeAdd( const char *key,
1044  bool isStatic,
1045  HashKey hashedKey );
1046 
1047  HashKey hash( const char *key ) const;
1048 
1049  int compare( const ValueInternalMap &other ) const;
1050 
1051  private:
1052  void makeBeginIterator( IteratorState &it ) const;
1053  void makeEndIterator( IteratorState &it ) const;
1054  static bool equals( const IteratorState &x, const IteratorState &other );
1055  static void increment( IteratorState &iterator );
1056  static void incrementBucket( IteratorState &iterator );
1057  static void decrement( IteratorState &iterator );
1058  static const char *key( const IteratorState &iterator );
1059  static const char *key( const IteratorState &iterator, bool &isStatic );
1060  static Value &value( const IteratorState &iterator );
1061  static int distance( const IteratorState &x, const IteratorState &y );
1062 
1063  private:
1064  ValueInternalLink *buckets_;
1065  ValueInternalLink *tailLink_;
1066  BucketIndex bucketsSize_;
1067  BucketIndex itemCount_;
1068  };
1069 
1081  class JSON_API ValueInternalArray
1082  {
1083  friend class Value;
1084  friend class ValueIteratorBase;
1085  public:
1086  enum { itemsPerPage = 8 }; // should be a power of 2 for fast divide and modulo.
1087  typedef Value::ArrayIndex ArrayIndex;
1088  typedef unsigned int PageIndex;
1089 
1090 # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
1091  struct IteratorState // Must be a POD
1092  {
1093  IteratorState()
1094  : array_(0)
1095  , currentPageIndex_(0)
1096  , currentItemIndex_(0)
1097  {
1098  }
1099  ValueInternalArray *array_;
1100  Value **currentPageIndex_;
1101  unsigned int currentItemIndex_;
1102  };
1103 # endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
1104 
1105  ValueInternalArray();
1106  ValueInternalArray( const ValueInternalArray &other );
1107  ValueInternalArray &operator =( const ValueInternalArray &other );
1108  ~ValueInternalArray();
1109  void swap( ValueInternalArray &other );
1110 
1111  void clear();
1112  void resize( ArrayIndex newSize );
1113 
1114  Value &resolveReference( ArrayIndex index );
1115 
1116  Value *find( ArrayIndex index ) const;
1117 
1118  ArrayIndex size() const;
1119 
1120  int compare( const ValueInternalArray &other ) const;
1121 
1122  private:
1123  static bool equals( const IteratorState &x, const IteratorState &other );
1124  static void increment( IteratorState &iterator );
1125  static void decrement( IteratorState &iterator );
1126  static Value &dereference( const IteratorState &iterator );
1127  static Value &unsafeDereference( const IteratorState &iterator );
1128  static int distance( const IteratorState &x, const IteratorState &y );
1129  static ArrayIndex indexOf( const IteratorState &iterator );
1130  void makeBeginIterator( IteratorState &it ) const;
1131  void makeEndIterator( IteratorState &it ) const;
1132  void makeIterator( IteratorState &it, ArrayIndex index ) const;
1133 
1134  void makeIndexValid( ArrayIndex index );
1135 
1136  Value **pages_;
1137  ArrayIndex size_;
1138  PageIndex pageCount_;
1139  };
1140 
1200  class JSON_API ValueArrayAllocator
1201  {
1202  public:
1203  virtual ~ValueArrayAllocator();
1204  virtual ValueInternalArray *newArray() = 0;
1205  virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) = 0;
1206  virtual void destructArray( ValueInternalArray *array ) = 0;
1218  virtual void reallocateArrayPageIndex( Value **&indexes,
1219  ValueInternalArray::PageIndex &indexCount,
1220  ValueInternalArray::PageIndex minNewIndexCount ) = 0;
1221  virtual void releaseArrayPageIndex( Value **indexes,
1222  ValueInternalArray::PageIndex indexCount ) = 0;
1223  virtual Value *allocateArrayPage() = 0;
1224  virtual void releaseArrayPage( Value *value ) = 0;
1225  };
1226 #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
1227 
1228 
1232  class ValueIteratorBase
1233  {
1234  public:
1235  typedef unsigned int size_t;
1236  typedef int difference_type;
1237  typedef ValueIteratorBase SelfType;
1238 
1239  ValueIteratorBase();
1240 #ifndef JSON_VALUE_USE_INTERNAL_MAP
1241  explicit ValueIteratorBase( const Value::ObjectValues::iterator &current );
1242 #else
1243  ValueIteratorBase( const ValueInternalArray::IteratorState &state );
1244  ValueIteratorBase( const ValueInternalMap::IteratorState &state );
1245 #endif
1246 
1247  bool operator ==( const SelfType &other ) const
1248  {
1249  return isEqual( other );
1250  }
1251 
1252  bool operator !=( const SelfType &other ) const
1253  {
1254  return !isEqual( other );
1255  }
1256 
1257  difference_type operator -( const SelfType &other ) const
1258  {
1259  return computeDistance( other );
1260  }
1261 
1263  Value key() const;
1264 
1266  UInt index() const;
1267 
1269  const char *memberName() const;
1270 
1271  protected:
1272  Value &deref() const;
1273 
1274  void increment();
1275 
1276  void decrement();
1277 
1278  difference_type computeDistance( const SelfType &other ) const;
1279 
1280  bool isEqual( const SelfType &other ) const;
1281 
1282  void copy( const SelfType &other );
1283 
1284  private:
1285 #ifndef JSON_VALUE_USE_INTERNAL_MAP
1286  Value::ObjectValues::iterator current_;
1287  // Indicates that iterator is for a null value.
1288  bool isNull_;
1289 #else
1290  union
1291  {
1292  ValueInternalArray::IteratorState array_;
1293  ValueInternalMap::IteratorState map_;
1294  } iterator_;
1295  bool isArray_;
1296 #endif
1297  };
1298 
1302  class ValueConstIterator : public ValueIteratorBase
1303  {
1304  friend class Value;
1305  public:
1306  typedef unsigned int size_t;
1307  typedef int difference_type;
1308  typedef const Value &reference;
1309  typedef const Value *pointer;
1310  typedef ValueConstIterator SelfType;
1311 
1312  ValueConstIterator();
1313  private:
1316 #ifndef JSON_VALUE_USE_INTERNAL_MAP
1317  explicit ValueConstIterator( const Value::ObjectValues::iterator &current );
1318 #else
1319  ValueConstIterator( const ValueInternalArray::IteratorState &state );
1320  ValueConstIterator( const ValueInternalMap::IteratorState &state );
1321 #endif
1322  public:
1323  SelfType &operator =( const ValueIteratorBase &other );
1324 
1325  SelfType operator++( int )
1326  {
1327  SelfType temp( *this );
1328  ++*this;
1329  return temp;
1330  }
1331 
1332  SelfType operator--( int )
1333  {
1334  SelfType temp( *this );
1335  --*this;
1336  return temp;
1337  }
1338 
1339  SelfType &operator--()
1340  {
1341  decrement();
1342  return *this;
1343  }
1344 
1345  SelfType &operator++()
1346  {
1347  increment();
1348  return *this;
1349  }
1350 
1351  reference operator *() const
1352  {
1353  return deref();
1354  }
1355  };
1356 
1357 
1360  class ValueIterator : public ValueIteratorBase
1361  {
1362  friend class Value;
1363  public:
1364  typedef unsigned int size_t;
1365  typedef int difference_type;
1366  typedef Value &reference;
1367  typedef Value *pointer;
1368  typedef ValueIterator SelfType;
1369 
1370  ValueIterator();
1371  ValueIterator( const ValueConstIterator &other );
1372  ValueIterator( const ValueIterator &other );
1373  private:
1376 #ifndef JSON_VALUE_USE_INTERNAL_MAP
1377  explicit ValueIterator( const Value::ObjectValues::iterator &current );
1378 #else
1379  ValueIterator( const ValueInternalArray::IteratorState &state );
1380  ValueIterator( const ValueInternalMap::IteratorState &state );
1381 #endif
1382  public:
1383 
1384  SelfType &operator =( const SelfType &other );
1385 
1386  SelfType operator++( int )
1387  {
1388  SelfType temp( *this );
1389  ++*this;
1390  return temp;
1391  }
1392 
1393  SelfType operator--( int )
1394  {
1395  SelfType temp( *this );
1396  --*this;
1397  return temp;
1398  }
1399 
1400  SelfType &operator--()
1401  {
1402  decrement();
1403  return *this;
1404  }
1405 
1406  SelfType &operator++()
1407  {
1408  increment();
1409  return *this;
1410  }
1411 
1412  reference operator *() const
1413  {
1414  return deref();
1415  }
1416  };
1417 
1418 
1419 } // namespace Json
1420 
1421 
1422 #endif // CPPTL_JSON_H_INCLUDED
1423 
1424 // //////////////////////////////////////////////////////////////////////
1425 // End of content of file: include/json/value.h
1426 // //////////////////////////////////////////////////////////////////////
1427 
1428 
1429 
1430 
1431 
1432 
1433 // //////////////////////////////////////////////////////////////////////
1434 // Beginning of content of file: include/json/reader.h
1435 // //////////////////////////////////////////////////////////////////////
1436 
1437 // Copyright 2007-2010 Baptiste Lepilleur
1438 // Distributed under MIT license, or public domain if desired and
1439 // recognized in your jurisdiction.
1440 // See file LICENSE for detail or copy at https://github.com/open-source-parsers/jsoncpp/blob/master/LICENSE
1441 
1442 #ifndef CPPTL_JSON_READER_H_INCLUDED
1443 # define CPPTL_JSON_READER_H_INCLUDED
1444 
1445 #if !defined(JSON_IS_AMALGAMATION)
1446 # include "features.h"
1447 # include "value.h"
1448 #endif // if !defined(JSON_IS_AMALGAMATION)
1449 # include <deque>
1450 # include <stack>
1451 # include <string>
1452 # include <iostream>
1453 
1454 namespace Json {
1455 
1459  class JSON_API Reader
1460  {
1461  public:
1462  typedef char Char;
1463  typedef const Char *Location;
1464 
1468  Reader();
1469 
1473  Reader( const Features &features );
1474 
1485  bool parse( const std::string &document,
1486  Value &root,
1487  bool collectComments = true );
1488 
1501  bool parse( const char *beginDoc, const char *endDoc,
1502  Value &root,
1503  bool collectComments = true );
1504 
1507  bool parse( std::istream &is,
1508  Value &root,
1509  bool collectComments = true );
1510 
1517  JSONCPP_DEPRECATED("Use getFormattedErrorMessages instead")
1518  std::string getFormatedErrorMessages() const;
1519 
1525  std::string getFormattedErrorMessages() const;
1526 
1527  private:
1528  enum TokenType
1529  {
1530  tokenEndOfStream = 0,
1531  tokenObjectBegin,
1532  tokenObjectEnd,
1533  tokenArrayBegin,
1534  tokenArrayEnd,
1535  tokenString,
1536  tokenNumber,
1537  tokenTrue,
1538  tokenFalse,
1539  tokenNull,
1540  tokenArraySeparator,
1541  tokenMemberSeparator,
1542  tokenComment,
1543  tokenError
1544  };
1545 
1546  class Token
1547  {
1548  public:
1549  TokenType type_;
1550  Location start_;
1551  Location end_;
1552  };
1553 
1554  class ErrorInfo
1555  {
1556  public:
1557  Token token_;
1558  std::string message_;
1559  Location extra_;
1560  };
1561 
1562  typedef std::deque<ErrorInfo> Errors;
1563 
1564  bool expectToken( TokenType type, Token &token, const char *message );
1565  bool readToken( Token &token );
1566  void skipSpaces();
1567  bool match( Location pattern,
1568  int patternLength );
1569  bool readComment();
1570  bool readCStyleComment();
1571  bool readCppStyleComment();
1572  bool readString();
1573  void readNumber();
1574  bool readValue();
1575  bool readObject( Token &token );
1576  bool readArray( Token &token );
1577  bool decodeNumber( Token &token );
1578  bool decodeString( Token &token );
1579  bool decodeString( Token &token, std::string &decoded );
1580  bool decodeDouble( Token &token );
1581  bool decodeUnicodeCodePoint( Token &token,
1582  Location &current,
1583  Location end,
1584  unsigned int &unicode );
1585  bool decodeUnicodeEscapeSequence( Token &token,
1586  Location &current,
1587  Location end,
1588  unsigned int &unicode );
1589  bool addError( const std::string &message,
1590  Token &token,
1591  Location extra = 0 );
1592  bool recoverFromError( TokenType skipUntilToken );
1593  bool addErrorAndRecover( const std::string &message,
1594  Token &token,
1595  TokenType skipUntilToken );
1596  void skipUntilSpace();
1597  Value &currentValue();
1598  Char getNextChar();
1599  void getLocationLineAndColumn( Location location,
1600  int &line,
1601  int &column ) const;
1602  std::string getLocationLineAndColumn( Location location ) const;
1603  void addComment( Location begin,
1604  Location end,
1605  CommentPlacement placement );
1606  void skipCommentTokens( Token &token );
1607 
1608  typedef std::stack<Value *> Nodes;
1609  Nodes nodes_;
1610  Errors errors_;
1611  std::string document_;
1612  Location begin_;
1613  Location end_;
1614  Location current_;
1615  Location lastValueEnd_;
1616  Value *lastValue_;
1617  std::string commentsBefore_;
1618  Features features_;
1619  bool collectComments_;
1620  };
1621 
1646  std::istream& operator>>( std::istream&, Value& );
1647 
1648 } // namespace Json
1649 
1650 #endif // CPPTL_JSON_READER_H_INCLUDED
1651 
1652 // //////////////////////////////////////////////////////////////////////
1653 // End of content of file: include/json/reader.h
1654 // //////////////////////////////////////////////////////////////////////
1655 
1656 
1657 
1658 
1659 
1660 
1661 // //////////////////////////////////////////////////////////////////////
1662 // Beginning of content of file: include/json/writer.h
1663 // //////////////////////////////////////////////////////////////////////
1664 
1665 // Copyright 2007-2010 Baptiste Lepilleur
1666 // Distributed under MIT license, or public domain if desired and
1667 // recognized in your jurisdiction.
1668 // See file LICENSE for detail or copy at https://github.com/open-source-parsers/jsoncpp/blob/master/LICENSE
1669 
1670 #ifndef JSON_WRITER_H_INCLUDED
1671 # define JSON_WRITER_H_INCLUDED
1672 
1673 #if !defined(JSON_IS_AMALGAMATION)
1674 # include "value.h"
1675 #endif // if !defined(JSON_IS_AMALGAMATION)
1676 # include <vector>
1677 # include <string>
1678 # include <iostream>
1679 
1680 namespace Json {
1681 
1682  class Value;
1683 
1686  class JSON_API Writer
1687  {
1688  public:
1689  virtual ~Writer();
1690 
1691  virtual std::string write( const Value &root ) = 0;
1692  };
1693 
1700  class JSON_API FastWriter : public Writer
1701  {
1702  public:
1703  FastWriter();
1704  virtual ~FastWriter(){}
1705 
1706  void enableYAMLCompatibility();
1707 
1708  public: // overridden from Writer
1709  virtual std::string write( const Value &root );
1710 
1711  private:
1712  void writeValue( const Value &value );
1713 
1714  std::string document_;
1715  bool yamlCompatiblityEnabled_;
1716  };
1717 
1736  class JSON_API StyledWriter: public Writer
1737  {
1738  public:
1739  StyledWriter();
1740  virtual ~StyledWriter(){}
1741 
1742  public: // overridden from Writer
1747  virtual std::string write( const Value &root );
1748 
1749  private:
1750  void writeValue( const Value &value );
1751  void writeArrayValue( const Value &value );
1752  bool isMultineArray( const Value &value );
1753  void pushValue( const std::string &value );
1754  void writeIndent();
1755  void writeWithIndent( const std::string &value );
1756  void indent();
1757  void unindent();
1758  void writeCommentBeforeValue( const Value &root );
1759  void writeCommentAfterValueOnSameLine( const Value &root );
1760  bool hasCommentForValue( const Value &value );
1761  static std::string normalizeEOL( const std::string &text );
1762 
1763  typedef std::vector<std::string> ChildValues;
1764 
1765  ChildValues childValues_;
1766  std::string document_;
1767  std::string indentString_;
1768  int rightMargin_;
1769  int indentSize_;
1770  bool addChildValues_;
1771  };
1772 
1793  class JSON_API StyledStreamWriter
1794  {
1795  public:
1796  StyledStreamWriter( std::string indentation="\t" );
1797  ~StyledStreamWriter(){}
1798 
1799  public:
1805  void write( std::ostream &out, const Value &root );
1806 
1807  private:
1808  void writeValue( const Value &value );
1809  void writeArrayValue( const Value &value );
1810  bool isMultineArray( const Value &value );
1811  void pushValue( const std::string &value );
1812  void writeIndent();
1813  void writeWithIndent( const std::string &value );
1814  void indent();
1815  void unindent();
1816  void writeCommentBeforeValue( const Value &root );
1817  void writeCommentAfterValueOnSameLine( const Value &root );
1818  bool hasCommentForValue( const Value &value );
1819  static std::string normalizeEOL( const std::string &text );
1820 
1821  typedef std::vector<std::string> ChildValues;
1822 
1823  ChildValues childValues_;
1824  std::ostream* document_;
1825  std::string indentString_;
1826  int rightMargin_;
1827  std::string indentation_;
1828  bool addChildValues_;
1829  };
1830 
1831 # if defined(JSON_HAS_INT64)
1832  std::string JSON_API valueToString( Int value );
1833  std::string JSON_API valueToString( UInt value );
1834 # endif // if defined(JSON_HAS_INT64)
1835  std::string JSON_API valueToString( LargestInt value );
1836  std::string JSON_API valueToString( LargestUInt value );
1837  std::string JSON_API valueToString( double value );
1838  std::string JSON_API valueToString( bool value );
1839  std::string JSON_API valueToQuotedString( const char *value );
1840 
1843  std::ostream& operator<<( std::ostream&, const Value &root );
1844 
1845 } // namespace Json
1846 
1847 
1848 
1849 #endif // JSON_WRITER_H_INCLUDED
1850 
1851 // //////////////////////////////////////////////////////////////////////
1852 // End of content of file: include/json/writer.h
1853 // //////////////////////////////////////////////////////////////////////
1854 
1855 
1856 
1857 
1858 
1859 #endif //ifndef JSON_AMALGATED_H_INCLUDED
array value (ordered list)
Definition: json.h:357
unsigned integer value
Definition: json.h:353
object value (collection of name/value pairs).
Definition: json.h:358
std::istream & operator>>(std::istream &, Value &)
Read from &#39;sin&#39; into &#39;root&#39;.
Definition: jsoncpp.cpp:964
&#39;null&#39; value
Definition: json.h:351
CommentPlacement
Definition: json.h:361
JSON (JavaScript Object Notation).
Definition: json-forwards.h:162
double value
Definition: json.h:354
a comment on the line after a value (only make sense for root value)
Definition: json.h:365
ValueType
Type of the value held by a Value object.
Definition: json.h:349
bool value
Definition: json.h:356
signed integer value
Definition: json.h:352
a comment placed on the line before a value
Definition: json.h:363
UTF-8 string value.
Definition: json.h:355
a comment just after a value on the same line
Definition: json.h:364
std::ostream & operator<<(std::ostream &, const Value &root)
Output using the StyledStreamWriter.
Definition: jsoncpp.cpp:3829