00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #ifndef JSON_AMALGATED_H_INCLUDED
00076 # define JSON_AMALGATED_H_INCLUDED
00077
00078
00079 #define JSON_IS_AMALGATED
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 #ifndef JSON_CONFIG_H_INCLUDED
00091 # define JSON_CONFIG_H_INCLUDED
00092
00094
00095
00097
00100
00104
00109
00110
00113 # define JSON_USE_EXCEPTION 1
00114
00118 #define JSON_IS_AMALGAMATION
00119
00120
00121 # ifdef JSON_IN_CPPTL
00122 # include <cpptl/config.h>
00123 # ifndef JSON_USE_CPPTL
00124 # define JSON_USE_CPPTL 1
00125 # endif
00126 # endif
00127
00128 # ifdef JSON_IN_CPPTL
00129 # define JSON_API CPPTL_API
00130 # elif defined(JSON_DLL_BUILD)
00131 # define JSON_API __declspec(dllexport)
00132 # elif defined(JSON_DLL)
00133 # define JSON_API __declspec(dllimport)
00134 # else
00135 # define JSON_API
00136 # endif
00137
00138
00139
00140
00141
00142 #if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC 6
00143
00144
00145 #define JSON_USE_INT64_DOUBLE_CONVERSION 1
00146 #endif // if defined(_MSC_VER) && _MSC_VER < 1200 // MSVC 6
00147
00148 #if defined(_MSC_VER) && _MSC_VER >= 1500 // MSVC 2008
00149
00150 # define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
00151 #endif
00152
00153 #if !defined(JSONCPP_DEPRECATED)
00154 # define JSONCPP_DEPRECATED(message)
00155 #endif // if !defined(JSONCPP_DEPRECATED)
00156
00157 namespace Json {
00158 typedef int Int;
00159 typedef unsigned int UInt;
00160 # if defined(JSON_NO_INT64)
00161 typedef int LargestInt;
00162 typedef unsigned int LargestUInt;
00163 # undef JSON_HAS_INT64
00164 # else // if defined(JSON_NO_INT64)
00165
00166 # if defined(_MSC_VER) // Microsoft Visual Studio
00167 typedef __int64 Int64;
00168 typedef unsigned __int64 UInt64;
00169 # else // if defined(_MSC_VER) // Other platforms, use long long
00170 typedef long long int Int64;
00171 typedef unsigned long long int UInt64;
00172 # endif // if defined(_MSC_VER)
00173 typedef Int64 LargestInt;
00174 typedef UInt64 LargestUInt;
00175 # define JSON_HAS_INT64
00176 # endif // if defined(JSON_NO_INT64)
00177 }
00178
00179
00180 #endif // JSON_CONFIG_H_INCLUDED
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 #ifndef JSON_FORWARDS_H_INCLUDED
00201 # define JSON_FORWARDS_H_INCLUDED
00202
00203 #if !defined(JSON_IS_AMALGAMATION)
00204 # include "config.h"
00205 #endif // if !defined(JSON_IS_AMALGAMATION)
00206
00207 namespace Json {
00208
00209
00210 class FastWriter;
00211 class StyledWriter;
00212
00213
00214 class Reader;
00215
00216
00217 class Features;
00218
00219
00220 typedef unsigned int ArrayIndex;
00221 class StaticString;
00222 class Path;
00223 class PathArgument;
00224 class Value;
00225 class ValueIteratorBase;
00226 class ValueIterator;
00227 class ValueConstIterator;
00228 #ifdef JSON_VALUE_USE_INTERNAL_MAP
00229 class ValueMapAllocator;
00230 class ValueInternalLink;
00231 class ValueInternalArray;
00232 class ValueInternalMap;
00233 #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
00234
00235 }
00236
00237
00238 #endif // JSON_FORWARDS_H_INCLUDED
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 #ifndef CPPTL_JSON_FEATURES_H_INCLUDED
00259 # define CPPTL_JSON_FEATURES_H_INCLUDED
00260
00261 #if !defined(JSON_IS_AMALGAMATION)
00262 # include "forwards.h"
00263 #endif // if !defined(JSON_IS_AMALGAMATION)
00264
00265 namespace Json {
00266
00271 class JSON_API Features
00272 {
00273 public:
00279 static Features all();
00280
00286 static Features strictMode();
00287
00290 Features();
00291
00293 bool allowComments_;
00294
00296 bool strictRoot_;
00297 };
00298
00299 }
00300
00301 #endif // CPPTL_JSON_FEATURES_H_INCLUDED
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 #ifndef CPPTL_JSON_H_INCLUDED
00322 # define CPPTL_JSON_H_INCLUDED
00323
00324 #if !defined(JSON_IS_AMALGAMATION)
00325 # include "forwards.h"
00326 #endif // if !defined(JSON_IS_AMALGAMATION)
00327 # include <string>
00328 # include <vector>
00329
00330 # ifndef JSON_USE_CPPTL_SMALLMAP
00331 # include <map>
00332 # else
00333 # include <cpptl/smallmap.h>
00334 # endif
00335 # ifdef JSON_USE_CPPTL
00336 # include <cpptl/forwards.h>
00337 # endif
00338
00341 namespace Json {
00342
00345 enum ValueType
00346 {
00347 nullValue = 0,
00348 intValue,
00349 uintValue,
00350 realValue,
00351 stringValue,
00352 booleanValue,
00353 arrayValue,
00354 objectValue
00355 };
00356
00357 enum CommentPlacement
00358 {
00359 commentBefore = 0,
00360 commentAfterOnSameLine,
00361 commentAfter,
00362 numberOfCommentPlacement
00363 };
00364
00365
00366
00367
00368
00369
00384 class JSON_API StaticString
00385 {
00386 public:
00387 explicit StaticString( const char *czstring )
00388 : str_( czstring )
00389 {
00390 }
00391
00392 operator const char *() const
00393 {
00394 return str_;
00395 }
00396
00397 const char *c_str() const
00398 {
00399 return str_;
00400 }
00401
00402 private:
00403 const char *str_;
00404 };
00405
00433 class JSON_API Value
00434 {
00435 friend class ValueIteratorBase;
00436 # ifdef JSON_VALUE_USE_INTERNAL_MAP
00437 friend class ValueInternalLink;
00438 friend class ValueInternalMap;
00439 # endif
00440 public:
00441 typedef std::vector<std::string> Members;
00442 typedef ValueIterator iterator;
00443 typedef ValueConstIterator const_iterator;
00444 typedef Json::UInt UInt;
00445 typedef Json::Int Int;
00446 # if defined(JSON_HAS_INT64)
00447 typedef Json::UInt64 UInt64;
00448 typedef Json::Int64 Int64;
00449 #endif // defined(JSON_HAS_INT64)
00450 typedef Json::LargestInt LargestInt;
00451 typedef Json::LargestUInt LargestUInt;
00452 typedef Json::ArrayIndex ArrayIndex;
00453
00454 static const Value null;
00456 static const LargestInt minLargestInt;
00458 static const LargestInt maxLargestInt;
00460 static const LargestUInt maxLargestUInt;
00461
00463 static const Int minInt;
00465 static const Int maxInt;
00467 static const UInt maxUInt;
00468
00470 static const Int64 minInt64;
00472 static const Int64 maxInt64;
00474 static const UInt64 maxUInt64;
00475
00476 private:
00477 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
00478 # ifndef JSON_VALUE_USE_INTERNAL_MAP
00479 class CZString
00480 {
00481 public:
00482 enum DuplicationPolicy
00483 {
00484 noDuplication = 0,
00485 duplicate,
00486 duplicateOnCopy
00487 };
00488 CZString( ArrayIndex index );
00489 CZString( const char *cstr, DuplicationPolicy allocate );
00490 CZString( const CZString &other );
00491 ~CZString();
00492 CZString &operator =( const CZString &other );
00493 bool operator<( const CZString &other ) const;
00494 bool operator==( const CZString &other ) const;
00495 ArrayIndex index() const;
00496 const char *c_str() const;
00497 bool isStaticString() const;
00498 private:
00499 void swap( CZString &other );
00500 const char *cstr_;
00501 ArrayIndex index_;
00502 };
00503
00504 public:
00505 # ifndef JSON_USE_CPPTL_SMALLMAP
00506 typedef std::map<CZString, Value> ObjectValues;
00507 # else
00508 typedef CppTL::SmallMap<CZString, Value> ObjectValues;
00509 # endif // ifndef JSON_USE_CPPTL_SMALLMAP
00510 # endif // ifndef JSON_VALUE_USE_INTERNAL_MAP
00511 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
00512
00513 public:
00529 Value( ValueType type = nullValue );
00530 Value( Int value );
00531 Value( UInt value );
00532 #if defined(JSON_HAS_INT64)
00533 Value( Int64 value );
00534 Value( UInt64 value );
00535 #endif // if defined(JSON_HAS_INT64)
00536 Value( double value );
00537 Value( const char *value );
00538 Value( const char *beginValue, const char *endValue );
00549 Value( const StaticString &value );
00550 Value( const std::string &value );
00551 # ifdef JSON_USE_CPPTL
00552 Value( const CppTL::ConstString &value );
00553 # endif
00554 Value( bool value );
00555 Value( const Value &other );
00556 ~Value();
00557
00558 Value &operator=( const Value &other );
00562 void swap( Value &other );
00563
00564 ValueType type() const;
00565
00566 bool operator <( const Value &other ) const;
00567 bool operator <=( const Value &other ) const;
00568 bool operator >=( const Value &other ) const;
00569 bool operator >( const Value &other ) const;
00570
00571 bool operator ==( const Value &other ) const;
00572 bool operator !=( const Value &other ) const;
00573
00574 int compare( const Value &other ) const;
00575
00576 const char *asCString() const;
00577 std::string asString() const;
00578 # ifdef JSON_USE_CPPTL
00579 CppTL::ConstString asConstString() const;
00580 # endif
00581 Int asInt() const;
00582 UInt asUInt() const;
00583 Int64 asInt64() const;
00584 UInt64 asUInt64() const;
00585 LargestInt asLargestInt() const;
00586 LargestUInt asLargestUInt() const;
00587 float asFloat() const;
00588 double asDouble() const;
00589 bool asBool() const;
00590
00591 bool isNull() const;
00592 bool isBool() const;
00593 bool isInt() const;
00594 bool isUInt() const;
00595 bool isIntegral() const;
00596 bool isDouble() const;
00597 bool isNumeric() const;
00598 bool isString() const;
00599 bool isArray() const;
00600 bool isObject() const;
00601
00602 bool isConvertibleTo( ValueType other ) const;
00603
00605 ArrayIndex size() const;
00606
00609 bool empty() const;
00610
00612 bool operator!() const;
00613
00617 void clear();
00618
00624 void resize( ArrayIndex size );
00625
00631 Value &operator[]( ArrayIndex index );
00632
00638 Value &operator[]( int index );
00639
00643 const Value &operator[]( ArrayIndex index ) const;
00644
00648 const Value &operator[]( int index ) const;
00649
00652 Value get( ArrayIndex index,
00653 const Value &defaultValue ) const;
00655 bool isValidIndex( ArrayIndex index ) const;
00659 Value &append( const Value &value );
00660
00662 Value &operator[]( const char *key );
00664 const Value &operator[]( const char *key ) const;
00666 Value &operator[]( const std::string &key );
00668 const Value &operator[]( const std::string &key ) const;
00680 Value &operator[]( const StaticString &key );
00681 # ifdef JSON_USE_CPPTL
00682
00683 Value &operator[]( const CppTL::ConstString &key );
00685 const Value &operator[]( const CppTL::ConstString &key ) const;
00686 # endif
00687
00688 Value get( const char *key,
00689 const Value &defaultValue ) const;
00691 Value get( const std::string &key,
00692 const Value &defaultValue ) const;
00693 # ifdef JSON_USE_CPPTL
00694
00695 Value get( const CppTL::ConstString &key,
00696 const Value &defaultValue ) const;
00697 # endif
00698
00699
00700
00701
00702
00703
00704 Value removeMember( const char* key );
00706 Value removeMember( const std::string &key );
00707
00709 bool isMember( const char *key ) const;
00711 bool isMember( const std::string &key ) const;
00712 # ifdef JSON_USE_CPPTL
00713
00714 bool isMember( const CppTL::ConstString &key ) const;
00715 # endif
00716
00722 Members getMemberNames() const;
00723
00724
00725
00726
00727
00728
00730 void setComment( const char *comment,
00731 CommentPlacement placement );
00733 void setComment( const std::string &comment,
00734 CommentPlacement placement );
00735 bool hasComment( CommentPlacement placement ) const;
00737 std::string getComment( CommentPlacement placement ) const;
00738
00739 std::string toStyledString() const;
00740
00741 const_iterator begin() const;
00742 const_iterator end() const;
00743
00744 iterator begin();
00745 iterator end();
00746
00747 private:
00748 Value &resolveReference( const char *key,
00749 bool isStatic );
00750
00751 # ifdef JSON_VALUE_USE_INTERNAL_MAP
00752 inline bool isItemAvailable() const
00753 {
00754 return itemIsUsed_ == 0;
00755 }
00756
00757 inline void setItemUsed( bool isUsed = true )
00758 {
00759 itemIsUsed_ = isUsed ? 1 : 0;
00760 }
00761
00762 inline bool isMemberNameStatic() const
00763 {
00764 return memberNameIsStatic_ == 0;
00765 }
00766
00767 inline void setMemberNameIsStatic( bool isStatic )
00768 {
00769 memberNameIsStatic_ = isStatic ? 1 : 0;
00770 }
00771 # endif // # ifdef JSON_VALUE_USE_INTERNAL_MAP
00772
00773 private:
00774 struct CommentInfo
00775 {
00776 CommentInfo();
00777 ~CommentInfo();
00778
00779 void setComment( const char *text );
00780
00781 char *comment_;
00782 };
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793 union ValueHolder
00794 {
00795 LargestInt int_;
00796 LargestUInt uint_;
00797 double real_;
00798 bool bool_;
00799 char *string_;
00800 # ifdef JSON_VALUE_USE_INTERNAL_MAP
00801 ValueInternalArray *array_;
00802 ValueInternalMap *map_;
00803 #else
00804 ObjectValues *map_;
00805 # endif
00806 } value_;
00807 ValueType type_ : 8;
00808 int allocated_ : 1;
00809 # ifdef JSON_VALUE_USE_INTERNAL_MAP
00810 unsigned int itemIsUsed_ : 1;
00811 int memberNameIsStatic_ : 1;
00812 # endif
00813 CommentInfo *comments_;
00814 };
00815
00816
00819 class PathArgument
00820 {
00821 public:
00822 friend class Path;
00823
00824 PathArgument();
00825 PathArgument( ArrayIndex index );
00826 PathArgument( const char *key );
00827 PathArgument( const std::string &key );
00828
00829 private:
00830 enum Kind
00831 {
00832 kindNone = 0,
00833 kindIndex,
00834 kindKey
00835 };
00836 std::string key_;
00837 ArrayIndex index_;
00838 Kind kind_;
00839 };
00840
00852 class Path
00853 {
00854 public:
00855 Path( const std::string &path,
00856 const PathArgument &a1 = PathArgument(),
00857 const PathArgument &a2 = PathArgument(),
00858 const PathArgument &a3 = PathArgument(),
00859 const PathArgument &a4 = PathArgument(),
00860 const PathArgument &a5 = PathArgument() );
00861
00862 const Value &resolve( const Value &root ) const;
00863 Value resolve( const Value &root,
00864 const Value &defaultValue ) const;
00866 Value &make( Value &root ) const;
00867
00868 private:
00869 typedef std::vector<const PathArgument *> InArgs;
00870 typedef std::vector<PathArgument> Args;
00871
00872 void makePath( const std::string &path,
00873 const InArgs &in );
00874 void addPathInArg( const std::string &path,
00875 const InArgs &in,
00876 InArgs::const_iterator &itInArg,
00877 PathArgument::Kind kind );
00878 void invalidPath( const std::string &path,
00879 int location );
00880
00881 Args args_;
00882 };
00883
00884
00885
00886 #ifdef JSON_VALUE_USE_INTERNAL_MAP
00887
00931 class JSON_API ValueMapAllocator
00932 {
00933 public:
00934 virtual ~ValueMapAllocator();
00935 virtual ValueInternalMap *newMap() = 0;
00936 virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) = 0;
00937 virtual void destructMap( ValueInternalMap *map ) = 0;
00938 virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) = 0;
00939 virtual void releaseMapBuckets( ValueInternalLink *links ) = 0;
00940 virtual ValueInternalLink *allocateMapLink() = 0;
00941 virtual void releaseMapLink( ValueInternalLink *link ) = 0;
00942 };
00943
00947 class JSON_API ValueInternalLink
00948 {
00949 public:
00950 enum { itemPerLink = 6 };
00951 enum InternalFlags {
00952 flagAvailable = 0,
00953 flagUsed = 1
00954 };
00955
00956 ValueInternalLink();
00957
00958 ~ValueInternalLink();
00959
00960 Value items_[itemPerLink];
00961 char *keys_[itemPerLink];
00962 ValueInternalLink *previous_;
00963 ValueInternalLink *next_;
00964 };
00965
00966
00979 class JSON_API ValueInternalMap
00980 {
00981 friend class ValueIteratorBase;
00982 friend class Value;
00983 public:
00984 typedef unsigned int HashKey;
00985 typedef unsigned int BucketIndex;
00986
00987 # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
00988 struct IteratorState
00989 {
00990 IteratorState()
00991 : map_(0)
00992 , link_(0)
00993 , itemIndex_(0)
00994 , bucketIndex_(0)
00995 {
00996 }
00997 ValueInternalMap *map_;
00998 ValueInternalLink *link_;
00999 BucketIndex itemIndex_;
01000 BucketIndex bucketIndex_;
01001 };
01002 # endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
01003
01004 ValueInternalMap();
01005 ValueInternalMap( const ValueInternalMap &other );
01006 ValueInternalMap &operator =( const ValueInternalMap &other );
01007 ~ValueInternalMap();
01008
01009 void swap( ValueInternalMap &other );
01010
01011 BucketIndex size() const;
01012
01013 void clear();
01014
01015 bool reserveDelta( BucketIndex growth );
01016
01017 bool reserve( BucketIndex newItemCount );
01018
01019 const Value *find( const char *key ) const;
01020
01021 Value *find( const char *key );
01022
01023 Value &resolveReference( const char *key,
01024 bool isStatic );
01025
01026 void remove( const char *key );
01027
01028 void doActualRemove( ValueInternalLink *link,
01029 BucketIndex index,
01030 BucketIndex bucketIndex );
01031
01032 ValueInternalLink *&getLastLinkInBucket( BucketIndex bucketIndex );
01033
01034 Value &setNewItem( const char *key,
01035 bool isStatic,
01036 ValueInternalLink *link,
01037 BucketIndex index );
01038
01039 Value &unsafeAdd( const char *key,
01040 bool isStatic,
01041 HashKey hashedKey );
01042
01043 HashKey hash( const char *key ) const;
01044
01045 int compare( const ValueInternalMap &other ) const;
01046
01047 private:
01048 void makeBeginIterator( IteratorState &it ) const;
01049 void makeEndIterator( IteratorState &it ) const;
01050 static bool equals( const IteratorState &x, const IteratorState &other );
01051 static void increment( IteratorState &iterator );
01052 static void incrementBucket( IteratorState &iterator );
01053 static void decrement( IteratorState &iterator );
01054 static const char *key( const IteratorState &iterator );
01055 static const char *key( const IteratorState &iterator, bool &isStatic );
01056 static Value &value( const IteratorState &iterator );
01057 static int distance( const IteratorState &x, const IteratorState &y );
01058
01059 private:
01060 ValueInternalLink *buckets_;
01061 ValueInternalLink *tailLink_;
01062 BucketIndex bucketsSize_;
01063 BucketIndex itemCount_;
01064 };
01065
01077 class JSON_API ValueInternalArray
01078 {
01079 friend class Value;
01080 friend class ValueIteratorBase;
01081 public:
01082 enum { itemsPerPage = 8 };
01083 typedef Value::ArrayIndex ArrayIndex;
01084 typedef unsigned int PageIndex;
01085
01086 # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
01087 struct IteratorState
01088 {
01089 IteratorState()
01090 : array_(0)
01091 , currentPageIndex_(0)
01092 , currentItemIndex_(0)
01093 {
01094 }
01095 ValueInternalArray *array_;
01096 Value **currentPageIndex_;
01097 unsigned int currentItemIndex_;
01098 };
01099 # endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
01100
01101 ValueInternalArray();
01102 ValueInternalArray( const ValueInternalArray &other );
01103 ValueInternalArray &operator =( const ValueInternalArray &other );
01104 ~ValueInternalArray();
01105 void swap( ValueInternalArray &other );
01106
01107 void clear();
01108 void resize( ArrayIndex newSize );
01109
01110 Value &resolveReference( ArrayIndex index );
01111
01112 Value *find( ArrayIndex index ) const;
01113
01114 ArrayIndex size() const;
01115
01116 int compare( const ValueInternalArray &other ) const;
01117
01118 private:
01119 static bool equals( const IteratorState &x, const IteratorState &other );
01120 static void increment( IteratorState &iterator );
01121 static void decrement( IteratorState &iterator );
01122 static Value &dereference( const IteratorState &iterator );
01123 static Value &unsafeDereference( const IteratorState &iterator );
01124 static int distance( const IteratorState &x, const IteratorState &y );
01125 static ArrayIndex indexOf( const IteratorState &iterator );
01126 void makeBeginIterator( IteratorState &it ) const;
01127 void makeEndIterator( IteratorState &it ) const;
01128 void makeIterator( IteratorState &it, ArrayIndex index ) const;
01129
01130 void makeIndexValid( ArrayIndex index );
01131
01132 Value **pages_;
01133 ArrayIndex size_;
01134 PageIndex pageCount_;
01135 };
01136
01196 class JSON_API ValueArrayAllocator
01197 {
01198 public:
01199 virtual ~ValueArrayAllocator();
01200 virtual ValueInternalArray *newArray() = 0;
01201 virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) = 0;
01202 virtual void destructArray( ValueInternalArray *array ) = 0;
01214 virtual void reallocateArrayPageIndex( Value **&indexes,
01215 ValueInternalArray::PageIndex &indexCount,
01216 ValueInternalArray::PageIndex minNewIndexCount ) = 0;
01217 virtual void releaseArrayPageIndex( Value **indexes,
01218 ValueInternalArray::PageIndex indexCount ) = 0;
01219 virtual Value *allocateArrayPage() = 0;
01220 virtual void releaseArrayPage( Value *value ) = 0;
01221 };
01222 #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
01223
01224
01228 class ValueIteratorBase
01229 {
01230 public:
01231 typedef unsigned int size_t;
01232 typedef int difference_type;
01233 typedef ValueIteratorBase SelfType;
01234
01235 ValueIteratorBase();
01236 #ifndef JSON_VALUE_USE_INTERNAL_MAP
01237 explicit ValueIteratorBase( const Value::ObjectValues::iterator ¤t );
01238 #else
01239 ValueIteratorBase( const ValueInternalArray::IteratorState &state );
01240 ValueIteratorBase( const ValueInternalMap::IteratorState &state );
01241 #endif
01242
01243 bool operator ==( const SelfType &other ) const
01244 {
01245 return isEqual( other );
01246 }
01247
01248 bool operator !=( const SelfType &other ) const
01249 {
01250 return !isEqual( other );
01251 }
01252
01253 difference_type operator -( const SelfType &other ) const
01254 {
01255 return computeDistance( other );
01256 }
01257
01259 Value key() const;
01260
01262 UInt index() const;
01263
01265 const char *memberName() const;
01266
01267 protected:
01268 Value &deref() const;
01269
01270 void increment();
01271
01272 void decrement();
01273
01274 difference_type computeDistance( const SelfType &other ) const;
01275
01276 bool isEqual( const SelfType &other ) const;
01277
01278 void copy( const SelfType &other );
01279
01280 private:
01281 #ifndef JSON_VALUE_USE_INTERNAL_MAP
01282 Value::ObjectValues::iterator current_;
01283
01284 bool isNull_;
01285 #else
01286 union
01287 {
01288 ValueInternalArray::IteratorState array_;
01289 ValueInternalMap::IteratorState map_;
01290 } iterator_;
01291 bool isArray_;
01292 #endif
01293 };
01294
01298 class ValueConstIterator : public ValueIteratorBase
01299 {
01300 friend class Value;
01301 public:
01302 typedef unsigned int size_t;
01303 typedef int difference_type;
01304 typedef const Value &reference;
01305 typedef const Value *pointer;
01306 typedef ValueConstIterator SelfType;
01307
01308 ValueConstIterator();
01309 private:
01312 #ifndef JSON_VALUE_USE_INTERNAL_MAP
01313 explicit ValueConstIterator( const Value::ObjectValues::iterator ¤t );
01314 #else
01315 ValueConstIterator( const ValueInternalArray::IteratorState &state );
01316 ValueConstIterator( const ValueInternalMap::IteratorState &state );
01317 #endif
01318 public:
01319 SelfType &operator =( const ValueIteratorBase &other );
01320
01321 SelfType operator++( int )
01322 {
01323 SelfType temp( *this );
01324 ++*this;
01325 return temp;
01326 }
01327
01328 SelfType operator--( int )
01329 {
01330 SelfType temp( *this );
01331 --*this;
01332 return temp;
01333 }
01334
01335 SelfType &operator--()
01336 {
01337 decrement();
01338 return *this;
01339 }
01340
01341 SelfType &operator++()
01342 {
01343 increment();
01344 return *this;
01345 }
01346
01347 reference operator *() const
01348 {
01349 return deref();
01350 }
01351 };
01352
01353
01356 class ValueIterator : public ValueIteratorBase
01357 {
01358 friend class Value;
01359 public:
01360 typedef unsigned int size_t;
01361 typedef int difference_type;
01362 typedef Value &reference;
01363 typedef Value *pointer;
01364 typedef ValueIterator SelfType;
01365
01366 ValueIterator();
01367 ValueIterator( const ValueConstIterator &other );
01368 ValueIterator( const ValueIterator &other );
01369 private:
01372 #ifndef JSON_VALUE_USE_INTERNAL_MAP
01373 explicit ValueIterator( const Value::ObjectValues::iterator ¤t );
01374 #else
01375 ValueIterator( const ValueInternalArray::IteratorState &state );
01376 ValueIterator( const ValueInternalMap::IteratorState &state );
01377 #endif
01378 public:
01379
01380 SelfType &operator =( const SelfType &other );
01381
01382 SelfType operator++( int )
01383 {
01384 SelfType temp( *this );
01385 ++*this;
01386 return temp;
01387 }
01388
01389 SelfType operator--( int )
01390 {
01391 SelfType temp( *this );
01392 --*this;
01393 return temp;
01394 }
01395
01396 SelfType &operator--()
01397 {
01398 decrement();
01399 return *this;
01400 }
01401
01402 SelfType &operator++()
01403 {
01404 increment();
01405 return *this;
01406 }
01407
01408 reference operator *() const
01409 {
01410 return deref();
01411 }
01412 };
01413
01414
01415 }
01416
01417
01418 #endif // CPPTL_JSON_H_INCLUDED
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438 #ifndef CPPTL_JSON_READER_H_INCLUDED
01439 # define CPPTL_JSON_READER_H_INCLUDED
01440
01441 #if !defined(JSON_IS_AMALGAMATION)
01442 # include "features.h"
01443 # include "value.h"
01444 #endif // if !defined(JSON_IS_AMALGAMATION)
01445 # include <deque>
01446 # include <stack>
01447 # include <string>
01448 # include <iostream>
01449
01450 namespace Json {
01451
01455 class JSON_API Reader
01456 {
01457 public:
01458 typedef char Char;
01459 typedef const Char *Location;
01460
01464 Reader();
01465
01469 Reader( const Features &features );
01470
01481 bool parse( const std::string &document,
01482 Value &root,
01483 bool collectComments = true );
01484
01497 bool parse( const char *beginDoc, const char *endDoc,
01498 Value &root,
01499 bool collectComments = true );
01500
01503 bool parse( std::istream &is,
01504 Value &root,
01505 bool collectComments = true );
01506
01513 JSONCPP_DEPRECATED("Use getFormattedErrorMessages instead")
01514 std::string getFormatedErrorMessages() const;
01515
01521 std::string getFormattedErrorMessages() const;
01522
01523 private:
01524 enum TokenType
01525 {
01526 tokenEndOfStream = 0,
01527 tokenObjectBegin,
01528 tokenObjectEnd,
01529 tokenArrayBegin,
01530 tokenArrayEnd,
01531 tokenString,
01532 tokenNumber,
01533 tokenTrue,
01534 tokenFalse,
01535 tokenNull,
01536 tokenArraySeparator,
01537 tokenMemberSeparator,
01538 tokenComment,
01539 tokenError
01540 };
01541
01542 class Token
01543 {
01544 public:
01545 TokenType type_;
01546 Location start_;
01547 Location end_;
01548 };
01549
01550 class ErrorInfo
01551 {
01552 public:
01553 Token token_;
01554 std::string message_;
01555 Location extra_;
01556 };
01557
01558 typedef std::deque<ErrorInfo> Errors;
01559
01560 bool expectToken( TokenType type, Token &token, const char *message );
01561 bool readToken( Token &token );
01562 void skipSpaces();
01563 bool match( Location pattern,
01564 int patternLength );
01565 bool readComment();
01566 bool readCStyleComment();
01567 bool readCppStyleComment();
01568 bool readString();
01569 void readNumber();
01570 bool readValue();
01571 bool readObject( Token &token );
01572 bool readArray( Token &token );
01573 bool decodeNumber( Token &token );
01574 bool decodeString( Token &token );
01575 bool decodeString( Token &token, std::string &decoded );
01576 bool decodeDouble( Token &token );
01577 bool decodeUnicodeCodePoint( Token &token,
01578 Location ¤t,
01579 Location end,
01580 unsigned int &unicode );
01581 bool decodeUnicodeEscapeSequence( Token &token,
01582 Location ¤t,
01583 Location end,
01584 unsigned int &unicode );
01585 bool addError( const std::string &message,
01586 Token &token,
01587 Location extra = 0 );
01588 bool recoverFromError( TokenType skipUntilToken );
01589 bool addErrorAndRecover( const std::string &message,
01590 Token &token,
01591 TokenType skipUntilToken );
01592 void skipUntilSpace();
01593 Value ¤tValue();
01594 Char getNextChar();
01595 void getLocationLineAndColumn( Location location,
01596 int &line,
01597 int &column ) const;
01598 std::string getLocationLineAndColumn( Location location ) const;
01599 void addComment( Location begin,
01600 Location end,
01601 CommentPlacement placement );
01602 void skipCommentTokens( Token &token );
01603
01604 typedef std::stack<Value *> Nodes;
01605 Nodes nodes_;
01606 Errors errors_;
01607 std::string document_;
01608 Location begin_;
01609 Location end_;
01610 Location current_;
01611 Location lastValueEnd_;
01612 Value *lastValue_;
01613 std::string commentsBefore_;
01614 Features features_;
01615 bool collectComments_;
01616 };
01617
01642 std::istream& operator>>( std::istream&, Value& );
01643
01644 }
01645
01646 #endif // CPPTL_JSON_READER_H_INCLUDED
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666 #ifndef JSON_WRITER_H_INCLUDED
01667 # define JSON_WRITER_H_INCLUDED
01668
01669 #if !defined(JSON_IS_AMALGAMATION)
01670 # include "value.h"
01671 #endif // if !defined(JSON_IS_AMALGAMATION)
01672 # include <vector>
01673 # include <string>
01674 # include <iostream>
01675
01676 namespace Json {
01677
01678 class Value;
01679
01682 class JSON_API Writer
01683 {
01684 public:
01685 virtual ~Writer();
01686
01687 virtual std::string write( const Value &root ) = 0;
01688 };
01689
01696 class JSON_API FastWriter : public Writer
01697 {
01698 public:
01699 FastWriter();
01700 virtual ~FastWriter(){}
01701
01702 void enableYAMLCompatibility();
01703
01704 public:
01705 virtual std::string write( const Value &root );
01706
01707 private:
01708 void writeValue( const Value &value );
01709
01710 std::string document_;
01711 bool yamlCompatiblityEnabled_;
01712 };
01713
01732 class JSON_API StyledWriter: public Writer
01733 {
01734 public:
01735 StyledWriter();
01736 virtual ~StyledWriter(){}
01737
01738 public:
01743 virtual std::string write( const Value &root );
01744
01745 private:
01746 void writeValue( const Value &value );
01747 void writeArrayValue( const Value &value );
01748 bool isMultineArray( const Value &value );
01749 void pushValue( const std::string &value );
01750 void writeIndent();
01751 void writeWithIndent( const std::string &value );
01752 void indent();
01753 void unindent();
01754 void writeCommentBeforeValue( const Value &root );
01755 void writeCommentAfterValueOnSameLine( const Value &root );
01756 bool hasCommentForValue( const Value &value );
01757 static std::string normalizeEOL( const std::string &text );
01758
01759 typedef std::vector<std::string> ChildValues;
01760
01761 ChildValues childValues_;
01762 std::string document_;
01763 std::string indentString_;
01764 int rightMargin_;
01765 int indentSize_;
01766 bool addChildValues_;
01767 };
01768
01789 class JSON_API StyledStreamWriter
01790 {
01791 public:
01792 StyledStreamWriter( std::string indentation="\t" );
01793 ~StyledStreamWriter(){}
01794
01795 public:
01801 void write( std::ostream &out, const Value &root );
01802
01803 private:
01804 void writeValue( const Value &value );
01805 void writeArrayValue( const Value &value );
01806 bool isMultineArray( const Value &value );
01807 void pushValue( const std::string &value );
01808 void writeIndent();
01809 void writeWithIndent( const std::string &value );
01810 void indent();
01811 void unindent();
01812 void writeCommentBeforeValue( const Value &root );
01813 void writeCommentAfterValueOnSameLine( const Value &root );
01814 bool hasCommentForValue( const Value &value );
01815 static std::string normalizeEOL( const std::string &text );
01816
01817 typedef std::vector<std::string> ChildValues;
01818
01819 ChildValues childValues_;
01820 std::ostream* document_;
01821 std::string indentString_;
01822 int rightMargin_;
01823 std::string indentation_;
01824 bool addChildValues_;
01825 };
01826
01827 # if defined(JSON_HAS_INT64)
01828 std::string JSON_API valueToString( Int value );
01829 std::string JSON_API valueToString( UInt value );
01830 # endif // if defined(JSON_HAS_INT64)
01831 std::string JSON_API valueToString( LargestInt value );
01832 std::string JSON_API valueToString( LargestUInt value );
01833 std::string JSON_API valueToString( double value );
01834 std::string JSON_API valueToString( bool value );
01835 std::string JSON_API valueToQuotedString( const char *value );
01836
01839 std::ostream& operator<<( std::ostream&, const Value &root );
01840
01841 }
01842
01843
01844
01845 #endif // JSON_WRITER_H_INCLUDED
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855 #endif //ifndef JSON_AMALGATED_H_INCLUDED