1
/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
* JSON Library, originally from http://jsoncpp.sourceforge.net/
5
* Copyright (C) 2011 Stewart Smith
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions are
12
* * Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
15
* * Redistributions in binary form must reproduce the above
16
* copyright notice, this list of conditions and the following disclaimer
17
* in the documentation and/or other materials provided with the
20
* * The names of its contributors may not be used to endorse or
21
* promote products derived from this software without specific prior
24
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
#ifndef CPPTL_JSON_H_INCLUDED
40
# define CPPTL_JSON_H_INCLUDED
42
# include "forwards.h"
46
# ifndef JSON_USE_CPPTL_SMALLMAP
49
# include <cpptl/smallmap.h>
51
# ifdef JSON_USE_CPPTL
52
# include <cpptl/forwards.h>
55
/** \brief JSON (JavaScript Object Notation).
59
/** \brief Type of the value held by a Value object.
63
nullValue = 0, ///< 'null' value
64
intValue, ///< signed integer value
65
uintValue, ///< unsigned integer value
66
realValue, ///< double value
67
stringValue, ///< UTF-8 string value
68
booleanValue, ///< bool value
69
arrayValue, ///< array value (ordered list)
70
objectValue ///< object value (collection of name/value pairs).
75
commentBefore = 0, ///< a comment placed on the line before a value
76
commentAfterOnSameLine, ///< a comment just after a value on the same line
77
commentAfter, ///< a comment on the line after a value (only make sense for root value)
78
numberOfCommentPlacement
81
//# ifdef JSON_USE_CPPTL
82
// typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
83
// typedef CppTL::AnyEnumerator<const Value &> EnumValues;
86
/** \brief Lightweight wrapper to tag static string.
88
* Value constructor and objectValue member assignement takes advantage of the
89
* StaticString and avoid the cost of string duplication when storing the
90
* string or the member name.
94
* Json::Value aValue( StaticString("some text") );
96
* static const StaticString code("code");
97
* object[code] = 1234;
100
class JSON_API StaticString
103
explicit StaticString( const char *czstring )
108
operator const char *() const
113
const char *c_str() const
122
/** \brief Represents a <a HREF="http://www.json.org">JSON</a> value.
124
* This class is a discriminated union wrapper that can represents a:
125
* - signed integer [range: Value::minInt - Value::maxInt]
126
* - unsigned integer (range: 0 - Value::maxUInt)
131
* - an ordered list of Value
132
* - collection of name/value pairs (javascript object)
134
* The type of the held value is represented by a #ValueType and
135
* can be obtained using type().
137
* values of an #objectValue or #arrayValue can be accessed using operator[]() methods.
138
* Non const methods will automatically create the a #nullValue element
139
* if it does not exist.
140
* The sequence of an #arrayValue will be automatically resize and initialized
141
* with #nullValue. resize() can be used to enlarge or truncate an #arrayValue.
143
* The get() methods can be used to obtanis default value in the case the required element
146
* It is possible to iterate over the list of a #objectValue values using
147
* the getMemberNames() method.
151
friend class ValueIteratorBase;
152
# ifdef JSON_VALUE_USE_INTERNAL_MAP
153
friend class ValueInternalLink;
154
friend class ValueInternalMap;
157
typedef std::vector<std::string> Members;
158
typedef ValueIterator iterator;
159
typedef ValueConstIterator const_iterator;
160
typedef Json::UInt UInt;
161
typedef Json::Int Int;
162
typedef UInt ArrayIndex;
164
static const Value null;
165
static const Int minInt;
166
static const Int maxInt;
167
static const UInt maxUInt;
170
#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
171
# ifndef JSON_VALUE_USE_INTERNAL_MAP
175
enum DuplicationPolicy
181
CZString( int index );
182
CZString( const char *cstr, DuplicationPolicy allocate );
183
CZString( const CZString &other );
185
CZString &operator =( const CZString &other );
186
bool operator<( const CZString &other ) const;
187
bool operator==( const CZString &other ) const;
189
const char *c_str() const;
190
bool isStaticString() const;
192
void swap( CZString &other );
198
# ifndef JSON_USE_CPPTL_SMALLMAP
199
typedef std::map<CZString, Value> ObjectValues;
201
typedef CppTL::SmallMap<CZString, Value> ObjectValues;
202
# endif // ifndef JSON_USE_CPPTL_SMALLMAP
203
# endif // ifndef JSON_VALUE_USE_INTERNAL_MAP
204
#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
207
/** \brief Create a default Value of the given type.
209
This is a very useful constructor.
210
To create an empty array, pass arrayValue.
211
To create an empty object, pass objectValue.
212
Another Value can then be set to this one by assignment.
213
This is useful since clear() and resize() will not alter types.
217
Json::Value null_value; // null
218
Json::Value arr_value(Json::arrayValue); // []
219
Json::Value obj_value(Json::objectValue); // {}
222
Value( ValueType type = nullValue );
225
Value( double value );
226
Value( const char *value );
227
Value( const char *beginValue, const char *endValue );
228
/** \brief Constructs a value from a static string.
230
* Like other value string constructor but do not duplicate the string for
231
* internal storage. The given string must remain alive after the call to this
235
* Json::Value aValue( StaticString("some text") );
238
Value( const StaticString &value );
239
Value( const std::string &value );
240
# ifdef JSON_USE_CPPTL
241
Value( const CppTL::ConstString &value );
244
Value( const Value &other );
247
Value &operator=( const Value &other );
249
/// \note Currently, comments are intentionally not swapped, for
250
/// both logic and efficiency.
251
void swap( Value &other );
253
ValueType type() const;
255
bool operator <( const Value &other ) const;
256
bool operator <=( const Value &other ) const;
257
bool operator >=( const Value &other ) const;
258
bool operator >( const Value &other ) const;
260
bool operator ==( const Value &other ) const;
261
bool operator !=( const Value &other ) const;
263
int compare( const Value &other );
265
const char *asCString() const;
266
std::string asString() const;
267
# ifdef JSON_USE_CPPTL
268
CppTL::ConstString asConstString() const;
272
double asDouble() const;
279
bool isIntegral() const;
280
bool isDouble() const;
281
bool isNumeric() const;
282
bool isString() const;
283
bool isArray() const;
284
bool isObject() const;
286
bool isConvertibleTo( ValueType other ) const;
288
/// Number of values in array or object
291
/// \brief Return true if empty array, empty object, or null;
292
/// otherwise, false.
296
bool operator!() const;
298
/// Remove all object members and array elements.
299
/// \pre type() is arrayValue, objectValue, or nullValue
300
/// \post type() is unchanged
303
/// Resize the array to size elements.
304
/// New elements are initialized to null.
305
/// May only be called on nullValue or arrayValue.
306
/// \pre type() is arrayValue or nullValue
307
/// \post type() is arrayValue
308
void resize( UInt size );
310
/// Access an array element (zero based index ).
311
/// If the array contains less than index element, then null value are inserted
312
/// in the array so that its size is index+1.
313
/// (You may need to say 'value[0u]' to get your compiler to distinguish
314
/// this from the operator[] which takes a string.)
315
Value &operator[]( UInt index );
316
/// Access an array element (zero based index )
317
/// (You may need to say 'value[0u]' to get your compiler to distinguish
318
/// this from the operator[] which takes a string.)
319
const Value &operator[]( UInt index ) const;
320
/// If the array contains at least index+1 elements, returns the element value,
321
/// otherwise returns defaultValue.
322
Value get( UInt index,
323
const Value &defaultValue ) const;
324
/// Return true if index < size().
325
bool isValidIndex( UInt index ) const;
326
/// \brief Append value to array at the end.
328
/// Equivalent to jsonvalue[jsonvalue.size()] = value;
329
Value &append( const Value &value );
331
/// Access an object value by name, create a null member if it does not exist.
332
Value &operator[]( const char *key );
333
/// Access an object value by name, returns null if there is no member with that name.
334
const Value &operator[]( const char *key ) const;
335
/// Access an object value by name, create a null member if it does not exist.
336
Value &operator[]( const std::string &key );
337
/// Access an object value by name, returns null if there is no member with that name.
338
const Value &operator[]( const std::string &key ) const;
339
/** \brief Access an object value by name, create a null member if it does not exist.
341
* If the object as no entry for that name, then the member name used to store
342
* the new entry is not duplicated.
345
* Json::Value object;
346
* static const StaticString code("code");
347
* object[code] = 1234;
350
Value &operator[]( const StaticString &key );
351
# ifdef JSON_USE_CPPTL
352
/// Access an object value by name, create a null member if it does not exist.
353
Value &operator[]( const CppTL::ConstString &key );
354
/// Access an object value by name, returns null if there is no member with that name.
355
const Value &operator[]( const CppTL::ConstString &key ) const;
357
/// Return the member named key if it exist, defaultValue otherwise.
358
Value get( const char *key,
359
const Value &defaultValue ) const;
360
/// Return the member named key if it exist, defaultValue otherwise.
361
Value get( const std::string &key,
362
const Value &defaultValue ) const;
363
# ifdef JSON_USE_CPPTL
364
/// Return the member named key if it exist, defaultValue otherwise.
365
Value get( const CppTL::ConstString &key,
366
const Value &defaultValue ) const;
368
/// \brief Remove and return the named member.
370
/// Do nothing if it did not exist.
371
/// \return the removed Value, or null.
372
/// \pre type() is objectValue or nullValue
373
/// \post type() is unchanged
374
Value removeMember( const char* key );
375
/// Same as removeMember(const char*)
376
Value removeMember( const std::string &key );
378
/// Return true if the object has a member named key.
379
bool isMember( const char *key ) const;
380
/// Return true if the object has a member named key.
381
bool isMember( const std::string &key ) const;
382
# ifdef JSON_USE_CPPTL
383
/// Return true if the object has a member named key.
384
bool isMember( const CppTL::ConstString &key ) const;
387
/// \brief Return a list of the member names.
389
/// If null, return an empty list.
390
/// \pre type() is objectValue or nullValue
391
/// \post if type() was nullValue, it remains nullValue
392
Members getMemberNames() const;
394
//# ifdef JSON_USE_CPPTL
395
// EnumMemberNames enumMemberNames() const;
396
// EnumValues enumValues() const;
399
/// Comments must be //... or /* ... */
400
void setComment( const char *comment,
401
CommentPlacement placement );
402
/// Comments must be //... or /* ... */
403
void setComment( const std::string &comment,
404
CommentPlacement placement );
405
bool hasComment( CommentPlacement placement ) const;
406
/// Include delimiters and embedded newlines.
407
std::string getComment( CommentPlacement placement ) const;
409
std::string toStyledString() const;
411
const_iterator begin() const;
412
const_iterator end() const;
418
Value &resolveReference( const char *key,
421
# ifdef JSON_VALUE_USE_INTERNAL_MAP
422
inline bool isItemAvailable() const
424
return itemIsUsed_ == 0;
427
inline void setItemUsed( bool isUsed = true )
429
itemIsUsed_ = isUsed ? 1 : 0;
432
inline bool isMemberNameStatic() const
434
return memberNameIsStatic_ == 0;
437
inline void setMemberNameIsStatic( bool isStatic )
439
memberNameIsStatic_ = isStatic ? 1 : 0;
441
# endif // # ifdef JSON_VALUE_USE_INTERNAL_MAP
449
void setComment( const char *text );
454
//struct MemberNamesTransform
456
// typedef const char *result_type;
457
// const char *operator()( const CZString &name ) const
459
// return name.c_str();
470
# ifdef JSON_VALUE_USE_INTERNAL_MAP
471
ValueInternalArray *array_;
472
ValueInternalMap *map_;
478
bool allocated_; // Notes: if declared as bool, bitfield is useless.
479
# ifdef JSON_VALUE_USE_INTERNAL_MAP
480
unsigned int itemIsUsed_ : 1; // used by the ValueInternalMap container.
481
int memberNameIsStatic_ : 1; // used by the ValueInternalMap container.
483
CommentInfo *comments_;
487
/** \brief Experimental and untested: represents an element of the "path" to access a node.
495
PathArgument( UInt index );
496
PathArgument( const char *key );
497
PathArgument( const std::string &key );
511
/** \brief Experimental and untested: represents a "path" to access a node.
515
* - ".[n]" => elements at index 'n' of root node (an array value)
516
* - ".name" => member named 'name' of root node (an object value)
517
* - ".name1.name2.name3"
518
* - ".[0][1][2].name1[3]"
519
* - ".%" => member name is provided as parameter
520
* - ".[%]" => index is provied as parameter
525
Path( const std::string &path,
526
const PathArgument &a1 = PathArgument(),
527
const PathArgument &a2 = PathArgument(),
528
const PathArgument &a3 = PathArgument(),
529
const PathArgument &a4 = PathArgument(),
530
const PathArgument &a5 = PathArgument() );
532
const Value &resolve( const Value &root ) const;
533
Value resolve( const Value &root,
534
const Value &defaultValue ) const;
535
/// Creates the "path" to access the specified node and returns a reference on the node.
536
Value &make( Value &root ) const;
539
typedef std::vector<const PathArgument *> InArgs;
540
typedef std::vector<PathArgument> Args;
542
void makePath( const std::string &path,
544
void addPathInArg( const std::string &path,
546
InArgs::const_iterator &itInArg,
547
PathArgument::Kind kind );
548
void invalidPath( const std::string &path,
554
/** \brief Experimental do not use: Allocator to customize member name and string value memory management done by Value.
556
* - makeMemberName() and releaseMemberName() are called to respectively duplicate and
557
* free an Json::objectValue member name.
558
* - duplicateStringValue() and releaseStringValue() are called similarly to
559
* duplicate and free a Json::stringValue value.
564
enum { unknown = (unsigned)-1 };
566
virtual ~ValueAllocator();
568
virtual char *makeMemberName( const char *memberName ) = 0;
569
virtual void releaseMemberName( char *memberName ) = 0;
570
virtual char *duplicateStringValue( const char *value,
571
unsigned int length = unknown ) = 0;
572
virtual void releaseStringValue( char *value ) = 0;
575
#ifdef JSON_VALUE_USE_INTERNAL_MAP
576
/** \brief Allocator to customize Value internal map.
577
* Below is an example of a simple implementation (default implementation actually
578
* use memory pool for speed).
580
class DefaultValueMapAllocator : public ValueMapAllocator
582
public: // overridden from ValueMapAllocator
583
virtual ValueInternalMap *newMap()
585
return new ValueInternalMap();
588
virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other )
590
return new ValueInternalMap( other );
593
virtual void destructMap( ValueInternalMap *map )
598
virtual ValueInternalLink *allocateMapBuckets( unsigned int size )
600
return new ValueInternalLink[size];
603
virtual void releaseMapBuckets( ValueInternalLink *links )
608
virtual ValueInternalLink *allocateMapLink()
610
return new ValueInternalLink();
613
virtual void releaseMapLink( ValueInternalLink *link )
620
class JSON_API ValueMapAllocator
623
virtual ~ValueMapAllocator();
624
virtual ValueInternalMap *newMap() = 0;
625
virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) = 0;
626
virtual void destructMap( ValueInternalMap *map ) = 0;
627
virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) = 0;
628
virtual void releaseMapBuckets( ValueInternalLink *links ) = 0;
629
virtual ValueInternalLink *allocateMapLink() = 0;
630
virtual void releaseMapLink( ValueInternalLink *link ) = 0;
633
/** \brief ValueInternalMap hash-map bucket chain link (for internal use only).
634
* \internal previous_ & next_ allows for bidirectional traversal.
636
class JSON_API ValueInternalLink
639
enum { itemPerLink = 6 }; // sizeof(ValueInternalLink) = 128 on 32 bits architecture.
647
~ValueInternalLink();
649
Value items_[itemPerLink];
650
char *keys_[itemPerLink];
651
ValueInternalLink *previous_;
652
ValueInternalLink *next_;
656
/** \brief A linked page based hash-table implementation used internally by Value.
657
* \internal ValueInternalMap is a tradional bucket based hash-table, with a linked
658
* list in each bucket to handle collision. There is an addional twist in that
659
* each node of the collision linked list is a page containing a fixed amount of
660
* value. This provides a better compromise between memory usage and speed.
662
* Each bucket is made up of a chained list of ValueInternalLink. The last
663
* link of a given bucket can be found in the 'previous_' field of the following bucket.
664
* The last link of the last bucket is stored in tailLink_ as it has no following bucket.
665
* Only the last link of a bucket may contains 'available' item. The last link always
666
* contains at least one element unless is it the bucket one very first link.
668
class JSON_API ValueInternalMap
670
friend class ValueIteratorBase;
673
typedef unsigned int HashKey;
674
typedef unsigned int BucketIndex;
676
# ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
686
ValueInternalMap *map_;
687
ValueInternalLink *link_;
688
BucketIndex itemIndex_;
689
BucketIndex bucketIndex_;
691
# endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
694
ValueInternalMap( const ValueInternalMap &other );
695
ValueInternalMap &operator =( const ValueInternalMap &other );
698
void swap( ValueInternalMap &other );
700
BucketIndex size() const;
704
bool reserveDelta( BucketIndex growth );
706
bool reserve( BucketIndex newItemCount );
708
const Value *find( const char *key ) const;
710
Value *find( const char *key );
712
Value &resolveReference( const char *key,
715
void remove( const char *key );
717
void doActualRemove( ValueInternalLink *link,
719
BucketIndex bucketIndex );
721
ValueInternalLink *&getLastLinkInBucket( BucketIndex bucketIndex );
723
Value &setNewItem( const char *key,
725
ValueInternalLink *link,
728
Value &unsafeAdd( const char *key,
732
HashKey hash( const char *key ) const;
734
int compare( const ValueInternalMap &other ) const;
737
void makeBeginIterator( IteratorState &it ) const;
738
void makeEndIterator( IteratorState &it ) const;
739
static bool equals( const IteratorState &x, const IteratorState &other );
740
static void increment( IteratorState &iterator );
741
static void incrementBucket( IteratorState &iterator );
742
static void decrement( IteratorState &iterator );
743
static const char *key( const IteratorState &iterator );
744
static const char *key( const IteratorState &iterator, bool &isStatic );
745
static Value &value( const IteratorState &iterator );
746
static int distance( const IteratorState &x, const IteratorState &y );
749
ValueInternalLink *buckets_;
750
ValueInternalLink *tailLink_;
751
BucketIndex bucketsSize_;
752
BucketIndex itemCount_;
755
/** \brief A simplified deque implementation used internally by Value.
757
* It is based on a list of fixed "page", each page contains a fixed number of items.
758
* Instead of using a linked-list, a array of pointer is used for fast item look-up.
759
* Look-up for an element is as follow:
760
* - compute page index: pageIndex = itemIndex / itemsPerPage
761
* - look-up item in page: pages_[pageIndex][itemIndex % itemsPerPage]
763
* Insertion is amortized constant time (only the array containing the index of pointers
764
* need to be reallocated when items are appended).
766
class JSON_API ValueInternalArray
769
friend class ValueIteratorBase;
771
enum { itemsPerPage = 8 }; // should be a power of 2 for fast divide and modulo.
772
typedef Value::ArrayIndex ArrayIndex;
773
typedef unsigned int PageIndex;
775
# ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
776
struct IteratorState // Must be a POD
780
, currentPageIndex_(0)
781
, currentItemIndex_(0)
784
ValueInternalArray *array_;
785
Value **currentPageIndex_;
786
unsigned int currentItemIndex_;
788
# endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
790
ValueInternalArray();
791
ValueInternalArray( const ValueInternalArray &other );
792
ValueInternalArray &operator =( const ValueInternalArray &other );
793
~ValueInternalArray();
794
void swap( ValueInternalArray &other );
797
void resize( ArrayIndex newSize );
799
Value &resolveReference( ArrayIndex index );
801
Value *find( ArrayIndex index ) const;
803
ArrayIndex size() const;
805
int compare( const ValueInternalArray &other ) const;
808
static bool equals( const IteratorState &x, const IteratorState &other );
809
static void increment( IteratorState &iterator );
810
static void decrement( IteratorState &iterator );
811
static Value &dereference( const IteratorState &iterator );
812
static Value &unsafeDereference( const IteratorState &iterator );
813
static int distance( const IteratorState &x, const IteratorState &y );
814
static ArrayIndex indexOf( const IteratorState &iterator );
815
void makeBeginIterator( IteratorState &it ) const;
816
void makeEndIterator( IteratorState &it ) const;
817
void makeIterator( IteratorState &it, ArrayIndex index ) const;
819
void makeIndexValid( ArrayIndex index );
823
PageIndex pageCount_;
826
/** \brief Experimental: do not use. Allocator to customize Value internal array.
827
* Below is an example of a simple implementation (actual implementation use
830
class DefaultValueArrayAllocator : public ValueArrayAllocator
832
public: // overridden from ValueArrayAllocator
833
virtual ~DefaultValueArrayAllocator()
837
virtual ValueInternalArray *newArray()
839
return new ValueInternalArray();
842
virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other )
844
return new ValueInternalArray( other );
847
virtual void destruct( ValueInternalArray *array )
852
virtual void reallocateArrayPageIndex( Value **&indexes,
853
ValueInternalArray::PageIndex &indexCount,
854
ValueInternalArray::PageIndex minNewIndexCount )
856
ValueInternalArray::PageIndex newIndexCount = (indexCount*3)/2 + 1;
857
if ( minNewIndexCount > newIndexCount )
858
newIndexCount = minNewIndexCount;
859
void *newIndexes = realloc( indexes, sizeof(Value*) * newIndexCount );
861
throw std::bad_alloc();
862
indexCount = newIndexCount;
863
indexes = static_cast<Value **>( newIndexes );
865
virtual void releaseArrayPageIndex( Value **indexes,
866
ValueInternalArray::PageIndex indexCount )
872
virtual Value *allocateArrayPage()
874
return static_cast<Value *>( malloc( sizeof(Value) * ValueInternalArray::itemsPerPage ) );
877
virtual void releaseArrayPage( Value *value )
885
class JSON_API ValueArrayAllocator
888
virtual ~ValueArrayAllocator();
889
virtual ValueInternalArray *newArray() = 0;
890
virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) = 0;
891
virtual void destructArray( ValueInternalArray *array ) = 0;
892
/** \brief Reallocate array page index.
893
* Reallocates an array of pointer on each page.
894
* \param indexes [input] pointer on the current index. May be \c NULL.
895
* [output] pointer on the new index of at least
896
* \a minNewIndexCount pages.
897
* \param indexCount [input] current number of pages in the index.
898
* [output] number of page the reallocated index can handle.
899
* \b MUST be >= \a minNewIndexCount.
900
* \param minNewIndexCount Minimum number of page the new index must be able to
903
virtual void reallocateArrayPageIndex( Value **&indexes,
904
ValueInternalArray::PageIndex &indexCount,
905
ValueInternalArray::PageIndex minNewIndexCount ) = 0;
906
virtual void releaseArrayPageIndex( Value **indexes,
907
ValueInternalArray::PageIndex indexCount ) = 0;
908
virtual Value *allocateArrayPage() = 0;
909
virtual void releaseArrayPage( Value *value ) = 0;
911
#endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
914
/** \brief base class for Value iterators.
917
class ValueIteratorBase
920
typedef unsigned int size_t;
921
typedef int difference_type;
922
typedef ValueIteratorBase SelfType;
925
#ifndef JSON_VALUE_USE_INTERNAL_MAP
926
explicit ValueIteratorBase( const Value::ObjectValues::iterator ¤t );
928
ValueIteratorBase( const ValueInternalArray::IteratorState &state );
929
ValueIteratorBase( const ValueInternalMap::IteratorState &state );
932
bool operator ==( const SelfType &other ) const
934
return isEqual( other );
937
bool operator !=( const SelfType &other ) const
939
return !isEqual( other );
942
difference_type operator -( const SelfType &other ) const
944
return computeDistance( other );
947
/// Return either the index or the member name of the referenced value as a Value.
950
/// Return the index of the referenced Value. -1 if it is not an arrayValue.
953
/// Return the member name of the referenced Value. "" if it is not an objectValue.
954
const char *memberName() const;
957
Value &deref() const;
963
difference_type computeDistance( const SelfType &other ) const;
965
bool isEqual( const SelfType &other ) const;
967
void copy( const SelfType &other );
970
#ifndef JSON_VALUE_USE_INTERNAL_MAP
971
Value::ObjectValues::iterator current_;
972
// Indicates that iterator is for a null value.
977
ValueInternalArray::IteratorState array_;
978
ValueInternalMap::IteratorState map_;
984
/** \brief const iterator for object and array value.
987
class ValueConstIterator : public ValueIteratorBase
991
typedef unsigned int size_t;
992
typedef int difference_type;
993
typedef const Value &reference;
994
typedef const Value *pointer;
995
typedef ValueConstIterator SelfType;
997
ValueConstIterator();
999
/*! \internal Use by Value to create an iterator.
1001
#ifndef JSON_VALUE_USE_INTERNAL_MAP
1002
explicit ValueConstIterator( const Value::ObjectValues::iterator ¤t );
1004
ValueConstIterator( const ValueInternalArray::IteratorState &state );
1005
ValueConstIterator( const ValueInternalMap::IteratorState &state );
1008
SelfType &operator =( const ValueIteratorBase &other );
1010
SelfType operator++( int )
1012
SelfType temp( *this );
1017
SelfType operator--( int )
1019
SelfType temp( *this );
1024
SelfType &operator--()
1030
SelfType &operator++()
1036
reference operator *() const
1043
/** \brief Iterator for object and array value.
1045
class ValueIterator : public ValueIteratorBase
1049
typedef unsigned int size_t;
1050
typedef int difference_type;
1051
typedef Value &reference;
1052
typedef Value *pointer;
1053
typedef ValueIterator SelfType;
1056
ValueIterator( const ValueConstIterator &other );
1057
ValueIterator( const ValueIterator &other );
1059
/*! \internal Use by Value to create an iterator.
1061
#ifndef JSON_VALUE_USE_INTERNAL_MAP
1062
explicit ValueIterator( const Value::ObjectValues::iterator ¤t );
1064
ValueIterator( const ValueInternalArray::IteratorState &state );
1065
ValueIterator( const ValueInternalMap::IteratorState &state );
1069
SelfType &operator =( const SelfType &other );
1071
SelfType operator++( int )
1073
SelfType temp( *this );
1078
SelfType operator--( int )
1080
SelfType temp( *this );
1085
SelfType &operator--()
1091
SelfType &operator++()
1097
reference operator *() const
1107
#endif // CPPTL_JSON_H_INCLUDED