1 #ifndef CPPTL_JSON_H_INCLUDED
2 # define CPPTL_JSON_H_INCLUDED
8 # ifndef JSON_USE_CPPTL_SMALLMAP
11 # include <cpptl/smallmap.h>
13 # ifdef JSON_USE_CPPTL
14 # include <cpptl/forwards.h>
70 operator const char *()
const
75 const char *c_str()
const
114 # ifdef JSON_VALUE_USE_INTERNAL_MAP
132 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
133 # ifndef JSON_VALUE_USE_INTERNAL_MAP
137 enum DuplicationPolicy
143 CZString(
int index );
144 CZString(
const char *cstr, DuplicationPolicy allocate );
145 CZString(
const CZString &other );
147 CZString &operator =(
const CZString &other );
148 bool operator<(
const CZString &other )
const;
149 bool operator==(
const CZString &other )
const;
151 const char *c_str()
const;
152 bool isStaticString()
const;
154 void swap( CZString &other );
160 # ifndef JSON_USE_CPPTL_SMALLMAP
161 typedef std::map<CZString, Value> ObjectValues;
163 typedef CppTL::SmallMap<CZString, Value> ObjectValues;
164 # endif // ifndef JSON_USE_CPPTL_SMALLMAP
165 # endif // ifndef JSON_VALUE_USE_INTERNAL_MAP
166 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
187 Value(
double value );
188 Value(
const char *value );
189 Value(
const char *beginValue,
const char *endValue );
201 Value(
const std::string &value );
202 # ifdef JSON_USE_CPPTL
203 Value(
const CppTL::ConstString &value );
213 void swap(
Value &other );
217 bool operator <(
const Value &other )
const;
218 bool operator <=(
const Value &other )
const;
219 bool operator >=(
const Value &other )
const;
220 bool operator >(
const Value &other )
const;
222 bool operator ==(
const Value &other )
const;
223 bool operator !=(
const Value &other )
const;
225 int compare(
const Value &other );
227 const char *asCString()
const;
228 std::string asString()
const;
229 # ifdef JSON_USE_CPPTL
230 CppTL::ConstString asConstString()
const;
234 double asDouble()
const;
241 bool isIntegral()
const;
242 bool isDouble()
const;
243 bool isNumeric()
const;
244 bool isString()
const;
245 bool isArray()
const;
246 bool isObject()
const;
248 bool isConvertibleTo(
ValueType other )
const;
258 bool operator!()
const;
270 void resize(
UInt size );
281 const Value &operator[](
UInt index )
const;
285 const Value &defaultValue )
const;
287 bool isValidIndex(
UInt index )
const;
294 Value &operator[](
const char *key );
296 const Value &operator[](
const char *key )
const;
298 Value &operator[](
const std::string &key );
300 const Value &operator[](
const std::string &key )
const;
313 # ifdef JSON_USE_CPPTL
315 Value &operator[](
const CppTL::ConstString &key );
317 const Value &operator[](
const CppTL::ConstString &key )
const;
320 Value get(
const char *key,
321 const Value &defaultValue )
const;
323 Value get(
const std::string &key,
324 const Value &defaultValue )
const;
325 # ifdef JSON_USE_CPPTL
327 Value get(
const CppTL::ConstString &key,
328 const Value &defaultValue )
const;
336 Value removeMember(
const char* key );
338 Value removeMember(
const std::string &key );
341 bool isMember(
const char *key )
const;
343 bool isMember(
const std::string &key )
const;
344 # ifdef JSON_USE_CPPTL
346 bool isMember(
const CppTL::ConstString &key )
const;
354 Members getMemberNames()
const;
362 void setComment(
const char *comment,
365 void setComment(
const std::string &comment,
371 std::string toStyledString()
const;
373 const_iterator begin()
const;
374 const_iterator end()
const;
380 Value &resolveReference(
const char *key,
383 # ifdef JSON_VALUE_USE_INTERNAL_MAP
384 inline bool isItemAvailable()
const
386 return itemIsUsed_ == 0;
389 inline void setItemUsed(
bool isUsed =
true )
391 itemIsUsed_ = isUsed ? 1 : 0;
394 inline bool isMemberNameStatic()
const
396 return memberNameIsStatic_ == 0;
399 inline void setMemberNameIsStatic(
bool isStatic )
401 memberNameIsStatic_ = isStatic ? 1 : 0;
403 # endif // # ifdef JSON_VALUE_USE_INTERNAL_MAP
411 void setComment(
const char *text );
432 # ifdef JSON_VALUE_USE_INTERNAL_MAP
433 ValueInternalArray *array_;
434 ValueInternalMap *map_;
441 # ifdef JSON_VALUE_USE_INTERNAL_MAP
442 unsigned int itemIsUsed_ : 1;
443 int memberNameIsStatic_ : 1;
445 CommentInfo *comments_;
487 Path(
const std::string &path,
496 const Value &defaultValue )
const;
501 typedef std::vector<const PathArgument *> InArgs;
502 typedef std::vector<PathArgument> Args;
504 void makePath(
const std::string &path,
506 void addPathInArg(
const std::string &path,
508 InArgs::const_iterator &itInArg,
509 PathArgument::Kind kind );
510 void invalidPath(
const std::string &path,
533 unsigned int length =
unknown ) = 0;
537 #ifdef JSON_VALUE_USE_INTERNAL_MAP
601 enum { itemPerLink = 6 };
612 char *keys_[itemPerLink];
638 # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
653 # endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
662 BucketIndex size()
const;
666 bool reserveDelta( BucketIndex growth );
668 bool reserve( BucketIndex newItemCount );
670 const Value *find(
const char *key )
const;
672 Value *find(
const char *key );
674 Value &resolveReference(
const char *key,
677 void remove(
const char *key );
681 BucketIndex bucketIndex );
685 Value &setNewItem(
const char *key,
690 Value &unsafeAdd(
const char *key,
694 HashKey hash(
const char *key )
const;
699 void makeBeginIterator( IteratorState &it )
const;
700 void makeEndIterator( IteratorState &it )
const;
701 static bool equals(
const IteratorState &x,
const IteratorState &other );
702 static void increment( IteratorState &iterator );
703 static void incrementBucket( IteratorState &iterator );
704 static void decrement( IteratorState &iterator );
705 static const char *key(
const IteratorState &iterator );
706 static const char *key(
const IteratorState &iterator,
bool &isStatic );
707 static Value &value(
const IteratorState &iterator );
708 static int distance(
const IteratorState &x,
const IteratorState &y );
713 BucketIndex bucketsSize_;
714 BucketIndex itemCount_;
733 enum { itemsPerPage = 8 };
737 # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
742 , currentPageIndex_(0)
743 , currentItemIndex_(0)
747 Value **currentPageIndex_;
748 unsigned int currentItemIndex_;
750 # endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
759 void resize( ArrayIndex newSize );
761 Value &resolveReference( ArrayIndex index );
763 Value *find( ArrayIndex index )
const;
765 ArrayIndex size()
const;
770 static bool equals(
const IteratorState &x,
const IteratorState &other );
771 static void increment( IteratorState &iterator );
772 static void decrement( IteratorState &iterator );
773 static Value &dereference(
const IteratorState &iterator );
774 static Value &unsafeDereference(
const IteratorState &iterator );
775 static int distance(
const IteratorState &x,
const IteratorState &y );
776 static ArrayIndex indexOf(
const IteratorState &iterator );
777 void makeBeginIterator( IteratorState &it )
const;
778 void makeEndIterator( IteratorState &it )
const;
779 void makeIterator( IteratorState &it, ArrayIndex index )
const;
781 void makeIndexValid( ArrayIndex index );
785 PageIndex pageCount_;
865 virtual void reallocateArrayPageIndex(
Value **&indexes,
868 virtual void releaseArrayPageIndex(
Value **indexes,
870 virtual Value *allocateArrayPage() = 0;
871 virtual void releaseArrayPage(
Value *value ) = 0;
873 #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
887 #ifndef JSON_VALUE_USE_INTERNAL_MAP
896 return isEqual( other );
901 return !isEqual( other );
906 return computeDistance( other );
916 const char *memberName()
const;
919 Value &deref()
const;
925 difference_type computeDistance(
const SelfType &other )
const;
927 bool isEqual(
const SelfType &other )
const;
929 void copy(
const SelfType &other );
932 #ifndef JSON_VALUE_USE_INTERNAL_MAP
933 Value::ObjectValues::iterator current_;
939 ValueInternalArray::IteratorState
array_;
940 ValueInternalMap::IteratorState
map_;
963 #ifndef JSON_VALUE_USE_INTERNAL_MAP
1023 #ifndef JSON_VALUE_USE_INTERNAL_MAP
1024 explicit ValueIterator(
const Value::ObjectValues::iterator ¤t );
1026 ValueIterator(
const ValueInternalArray::IteratorState &state );
1027 ValueIterator(
const ValueInternalMap::IteratorState &state );
1069 #endif // CPPTL_JSON_H_INCLUDED