1 #ifndef CPPTL_JSON_H_INCLUDED
2 #define CPPTL_JSON_H_INCLUDED
8 #ifndef JSON_USE_CPPTL_SMALLMAP
11 #include <cpptl/smallmap.h>
14 #include <cpptl/forwards.h>
64 operator const char *()
const {
return str_; }
66 const char *
c_str()
const {
return str_; }
101 #ifdef JSON_VALUE_USE_INTERNAL_MAP
102 friend class ValueInternalLink;
103 friend class ValueInternalMap;
119 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
120 #ifndef JSON_VALUE_USE_INTERNAL_MAP
125 CZString(
const char *cstr, DuplicationPolicy allocate);
132 const char *c_str()
const;
133 bool isStaticString()
const;
142 #ifndef JSON_USE_CPPTL_SMALLMAP
146 #endif // ifndef JSON_USE_CPPTL_SMALLMAP
147 #endif // ifndef JSON_VALUE_USE_INTERNAL_MAP
148 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
171 Value(
const char *beginValue,
const char *endValue);
184 #ifdef JSON_USE_CPPTL
209 const char *asCString()
const;
211 #ifdef JSON_USE_CPPTL
212 CppTL::ConstString asConstString()
const;
216 double asDouble()
const;
223 bool isIntegral()
const;
224 bool isDouble()
const;
225 bool isNumeric()
const;
226 bool isString()
const;
227 bool isArray()
const;
228 bool isObject()
const;
240 bool operator!()
const;
294 #ifdef JSON_USE_CPPTL
304 #ifdef JSON_USE_CPPTL
308 Value removeMember(
const char *
key);
319 bool isMember(
const char *
key)
const;
322 #ifdef JSON_USE_CPPTL
323 bool isMember(
const CppTL::ConstString &
key)
const;
332 Members getMemberNames()
const;
356 Value &resolveReference(
const char *
key,
bool isStatic);
358 #ifdef JSON_VALUE_USE_INTERNAL_MAP
359 inline bool isItemAvailable()
const {
return itemIsUsed_ == 0; }
361 inline void setItemUsed(
bool isUsed =
true) { itemIsUsed_ = isUsed ? 1 : 0; }
363 inline bool isMemberNameStatic()
const {
return memberNameIsStatic_ == 0; }
365 inline void setMemberNameIsStatic(
bool isStatic) { memberNameIsStatic_ = isStatic ? 1 : 0; }
366 #endif // # ifdef JSON_VALUE_USE_INTERNAL_MAP
373 void setComment(
const char *
text);
393 #ifdef JSON_VALUE_USE_INTERNAL_MAP
394 ValueInternalArray *array_;
395 ValueInternalMap *map_;
402 #ifdef JSON_VALUE_USE_INTERNAL_MAP
403 unsigned int itemIsUsed_ : 1;
404 int memberNameIsStatic_ : 1;
453 typedef std::vector<const PathArgument *>
InArgs;
454 typedef std::vector<PathArgument>
Args;
459 InArgs::const_iterator &itInArg,
485 #ifdef JSON_VALUE_USE_INTERNAL_MAP
532 virtual ~ValueMapAllocator();
533 virtual ValueInternalMap *newMap() = 0;
534 virtual ValueInternalMap *newMapCopy(
const ValueInternalMap &
other) = 0;
535 virtual void destructMap(ValueInternalMap *
map) = 0;
536 virtual ValueInternalLink *allocateMapBuckets(
unsigned int size) = 0;
537 virtual void releaseMapBuckets(ValueInternalLink *
links) = 0;
538 virtual ValueInternalLink *allocateMapLink() = 0;
539 virtual void releaseMapLink(ValueInternalLink *
link) = 0;
547 enum { itemPerLink = 6 };
548 enum InternalFlags { flagAvailable = 0, flagUsed = 1 };
552 ~ValueInternalLink();
554 Value items_[itemPerLink];
555 char *keys_[itemPerLink];
556 ValueInternalLink *previous_;
557 ValueInternalLink *next_;
573 friend class ValueIteratorBase;
577 typedef unsigned int HashKey;
578 typedef unsigned int BucketIndex;
580 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
581 struct IteratorState {
582 IteratorState() : map_(0), link_(0), itemIndex_(0), bucketIndex_(0) {}
583 ValueInternalMap *map_;
584 ValueInternalLink *link_;
585 BucketIndex itemIndex_;
586 BucketIndex bucketIndex_;
588 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
591 ValueInternalMap(
const ValueInternalMap &
other);
592 ValueInternalMap &operator=(
const ValueInternalMap &
other);
597 BucketIndex
size()
const;
601 bool reserveDelta(BucketIndex growth);
603 bool reserve(BucketIndex newItemCount);
609 Value &resolveReference(
const char *
key,
bool isStatic);
613 void doActualRemove(ValueInternalLink *
link, BucketIndex
index, BucketIndex bucketIndex);
615 ValueInternalLink *&getLastLinkInBucket(BucketIndex bucketIndex);
617 Value &setNewItem(
const char *
key,
bool isStatic, ValueInternalLink *
link, BucketIndex
index);
619 Value &unsafeAdd(
const char *
key,
bool isStatic, HashKey hashedKey);
621 HashKey
hash(
const char *
key)
const;
626 void makeBeginIterator(IteratorState &it)
const;
627 void makeEndIterator(IteratorState &it)
const;
628 static bool equals(
const IteratorState &x,
const IteratorState &
other);
629 static void increment(IteratorState &iterator);
630 static void incrementBucket(IteratorState &iterator);
631 static void decrement(IteratorState &iterator);
632 static const char *
key(
const IteratorState &iterator);
633 static const char *
key(
const IteratorState &iterator,
bool &isStatic);
634 static Value &
value(
const IteratorState &iterator);
635 static int distance(
const IteratorState &x,
const IteratorState &y);
638 ValueInternalLink *buckets_;
639 ValueInternalLink *tailLink_;
640 BucketIndex bucketsSize_;
641 BucketIndex itemCount_;
657 friend class ValueIteratorBase;
660 enum { itemsPerPage = 8 };
662 typedef unsigned int PageIndex;
664 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
667 IteratorState() : array_(0), currentPageIndex_(0), currentItemIndex_(0) {}
668 ValueInternalArray *array_;
669 Value **currentPageIndex_;
670 unsigned int currentItemIndex_;
672 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
674 ValueInternalArray();
675 ValueInternalArray(
const ValueInternalArray &
other);
676 ValueInternalArray &operator=(
const ValueInternalArray &
other);
677 ~ValueInternalArray();
681 void resize(ArrayIndex newSize);
687 ArrayIndex
size()
const;
692 static bool equals(
const IteratorState &x,
const IteratorState &
other);
693 static void increment(IteratorState &iterator);
694 static void decrement(IteratorState &iterator);
695 static Value &dereference(
const IteratorState &iterator);
696 static Value &unsafeDereference(
const IteratorState &iterator);
697 static int distance(
const IteratorState &x,
const IteratorState &y);
698 static ArrayIndex indexOf(
const IteratorState &iterator);
699 void makeBeginIterator(IteratorState &it)
const;
700 void makeEndIterator(IteratorState &it)
const;
701 void makeIterator(IteratorState &it, ArrayIndex
index)
const;
703 void makeIndexValid(ArrayIndex
index);
707 PageIndex pageCount_;
769 class JSON_API ValueArrayAllocator {
771 virtual ~ValueArrayAllocator();
772 virtual ValueInternalArray *newArray() = 0;
773 virtual ValueInternalArray *newArrayCopy(
const ValueInternalArray &
other) = 0;
774 virtual void destructArray(ValueInternalArray *
array) = 0;
786 virtual void reallocateArrayPageIndex(
Value **&indexes,
787 ValueInternalArray::PageIndex &indexCount,
788 ValueInternalArray::PageIndex minNewIndexCount) = 0;
789 virtual void releaseArrayPageIndex(
Value **indexes, ValueInternalArray::PageIndex indexCount) = 0;
790 virtual Value *allocateArrayPage() = 0;
791 virtual void releaseArrayPage(
Value *
value) = 0;
793 #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
805 #ifndef JSON_VALUE_USE_INTERNAL_MAP
841 #ifndef JSON_VALUE_USE_INTERNAL_MAP
847 ValueInternalArray::IteratorState array_;
848 ValueInternalMap::IteratorState map_;
872 #ifndef JSON_VALUE_USE_INTERNAL_MAP
925 #ifndef JSON_VALUE_USE_INTERNAL_MAP
926 explicit ValueIterator(
const Value::ObjectValues::iterator ¤t);
961 #endif // CPPTL_JSON_H_INCLUDED