6 #ifndef CPPTL_JSON_H_INCLUDED 7 #define CPPTL_JSON_H_INCLUDED 9 #if !defined(JSON_IS_AMALGAMATION) 11 #endif // if !defined(JSON_IS_AMALGAMATION) 15 #ifndef JSON_USE_CPPTL_SMALLMAP 18 #include <cpptl/smallmap.h> 21 #include <cpptl/forwards.h> 26 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 28 #pragma warning(disable : 4251) 29 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 79 operator const char *()
const {
return str_; }
81 const char *
c_str()
const {
return str_; }
118 #ifdef JSON_VALUE_USE_INTERNAL_MAP 128 #if defined(JSON_HAS_INT64) 131 #endif // defined(JSON_HAS_INT64) 151 #if defined(JSON_HAS_INT64) 152 static const Int64 minInt64;
158 #endif // defined(JSON_HAS_INT64) 161 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION 162 #ifndef JSON_VALUE_USE_INTERNAL_MAP 165 enum DuplicationPolicy {
170 CZString(ArrayIndex index);
171 CZString(
const char *cstr, DuplicationPolicy allocate);
172 CZString(
const CZString &other);
174 CZString &operator=(
const CZString &other);
175 bool operator<(
const CZString &other)
const;
176 bool operator==(
const CZString &other)
const;
177 ArrayIndex index()
const;
178 const char *c_str()
const;
179 bool isStaticString()
const;
182 void swap(CZString &other);
188 #ifndef JSON_USE_CPPTL_SMALLMAP 189 typedef std::map<CZString, Value> ObjectValues;
191 typedef CppTL::SmallMap<CZString, Value> ObjectValues;
192 #endif // ifndef JSON_USE_CPPTL_SMALLMAP 193 #endif // ifndef JSON_VALUE_USE_INTERNAL_MAP 194 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION 215 #if defined(JSON_HAS_INT64) 218 #endif // if defined(JSON_HAS_INT64) 220 Value(
const char *value);
221 Value(
const char *beginValue,
const char *endValue);
233 Value(
const std::string &value);
234 #ifdef JSON_USE_CPPTL 235 Value(
const CppTL::ConstString &value);
245 void swap(
Value &other);
249 bool operator<(
const Value &other)
const;
250 bool operator<=(
const Value &other)
const;
251 bool operator>=(
const Value &other)
const;
252 bool operator>(
const Value &other)
const;
254 bool operator==(
const Value &other)
const;
255 bool operator!=(
const Value &other)
const;
257 int compare(
const Value &other)
const;
259 const char *asCString()
const;
260 std::string asString()
const;
261 #ifdef JSON_USE_CPPTL 262 CppTL::ConstString asConstString()
const;
266 #if defined(JSON_HAS_INT64) 267 Int64 asInt64()
const;
268 UInt64 asUInt64()
const;
269 #endif // if defined(JSON_HAS_INT64) 270 LargestInt asLargestInt()
const;
271 LargestUInt asLargestUInt()
const;
272 float asFloat()
const;
273 double asDouble()
const;
279 bool isInt64()
const;
281 bool isUInt64()
const;
282 bool isIntegral()
const;
283 bool isDouble()
const;
284 bool isNumeric()
const;
285 bool isString()
const;
286 bool isArray()
const;
287 bool isObject()
const;
289 bool isConvertibleTo(
ValueType other)
const;
292 ArrayIndex size()
const;
299 bool operator!()
const;
311 void resize(ArrayIndex size);
319 Value &operator[](ArrayIndex index);
327 Value &operator[](
int index);
332 const Value &operator[](ArrayIndex index)
const;
337 const Value &operator[](
int index)
const;
342 Value get(ArrayIndex index,
const Value &defaultValue)
const;
344 bool isValidIndex(ArrayIndex index)
const;
351 Value &operator[](
const char *key);
354 const Value &operator[](
const char *key)
const;
356 Value &operator[](
const std::string &key);
359 const Value &operator[](
const std::string &key)
const;
373 #ifdef JSON_USE_CPPTL 374 Value &operator[](
const CppTL::ConstString &key);
378 const Value &operator[](
const CppTL::ConstString &key)
const;
380 Value get(
const char *key,
const Value &defaultValue)
const;
383 Value get(
const std::string &key,
const Value &defaultValue)
const;
384 #ifdef JSON_USE_CPPTL 385 Value get(
const CppTL::ConstString &key,
const Value &defaultValue)
const;
388 Value removeMember(
const char *key);
396 Value removeMember(
const std::string &key);
399 bool isMember(
const char *key)
const;
401 bool isMember(
const std::string &key)
const;
402 #ifdef JSON_USE_CPPTL 403 bool isMember(
const CppTL::ConstString &key)
const;
412 Members getMemberNames()
const;
427 std::string toStyledString()
const;
429 const_iterator begin()
const;
430 const_iterator end()
const;
437 void setOffsetStart(
size_t start);
438 void setOffsetLimit(
size_t limit);
439 size_t getOffsetStart()
const;
440 size_t getOffsetLimit()
const;
443 Value &resolveReference(
const char *key,
bool isStatic);
445 #ifdef JSON_VALUE_USE_INTERNAL_MAP 446 inline bool isItemAvailable()
const {
return itemIsUsed_ == 0; }
448 inline void setItemUsed(
bool isUsed =
true) { itemIsUsed_ = isUsed ? 1 : 0; }
450 inline bool isMemberNameStatic()
const {
return memberNameIsStatic_ == 0; }
452 inline void setMemberNameIsStatic(
bool isStatic) {
453 memberNameIsStatic_ = isStatic ? 1 : 0;
455 #endif // # ifdef JSON_VALUE_USE_INTERNAL_MAP 462 void setComment(
const char *text);
482 #ifdef JSON_VALUE_USE_INTERNAL_MAP 491 #ifdef JSON_VALUE_USE_INTERNAL_MAP 492 unsigned int itemIsUsed_ : 1;
493 int memberNameIsStatic_ : 1;
495 CommentInfo *comments_;
539 Path(
const std::string &path,
546 const Value &resolve(
const Value &root)
const;
553 typedef std::vector<const PathArgument *> InArgs;
554 typedef std::vector<PathArgument> Args;
556 void makePath(
const std::string &path,
const InArgs &
in);
557 void addPathInArg(
const std::string &path,
559 InArgs::const_iterator &itInArg,
560 PathArgument::Kind kind);
561 void invalidPath(
const std::string &path,
int location);
566 #ifdef JSON_VALUE_USE_INTERNAL_MAP 642 char *keys_[itemPerLink];
672 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION 673 struct IteratorState {
674 IteratorState() : map_(0), link_(0), itemIndex_(0), bucketIndex_(0) {}
677 BucketIndex itemIndex_;
678 BucketIndex bucketIndex_;
680 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION 689 BucketIndex size()
const;
693 bool reserveDelta(BucketIndex growth);
695 bool reserve(BucketIndex newItemCount);
697 const Value *find(
const char *key)
const;
699 Value *find(
const char *key);
701 Value &resolveReference(
const char *key,
bool isStatic);
703 void remove(
const char *key);
707 BucketIndex bucketIndex);
711 Value &setNewItem(
const char *key,
716 Value &unsafeAdd(
const char *key,
bool isStatic, HashKey hashedKey);
718 HashKey hash(
const char *key)
const;
723 void makeBeginIterator(IteratorState &it)
const;
724 void makeEndIterator(IteratorState &it)
const;
725 static bool equals(
const IteratorState &x,
const IteratorState &other);
726 static void increment(IteratorState &iterator);
727 static void incrementBucket(IteratorState &iterator);
728 static void decrement(IteratorState &iterator);
729 static const char *key(
const IteratorState &iterator);
730 static const char *key(
const IteratorState &iterator,
bool &isStatic);
731 static Value &value(
const IteratorState &iterator);
732 static int distance(
const IteratorState &x,
const IteratorState &y);
737 BucketIndex bucketsSize_;
738 BucketIndex itemCount_;
766 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION 769 IteratorState() : array_(0), currentPageIndex_(0), currentItemIndex_(0) {}
771 Value **currentPageIndex_;
772 unsigned int currentItemIndex_;
774 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION 783 void resize(ArrayIndex newSize);
785 Value &resolveReference(ArrayIndex index);
787 Value *find(ArrayIndex index)
const;
789 ArrayIndex size()
const;
794 static bool equals(
const IteratorState &x,
const IteratorState &other);
795 static void increment(IteratorState &iterator);
796 static void decrement(IteratorState &iterator);
797 static Value &dereference(
const IteratorState &iterator);
798 static Value &unsafeDereference(
const IteratorState &iterator);
799 static int distance(
const IteratorState &x,
const IteratorState &y);
800 static ArrayIndex indexOf(
const IteratorState &iterator);
801 void makeBeginIterator(IteratorState &it)
const;
802 void makeEndIterator(IteratorState &it)
const;
803 void makeIterator(IteratorState &it, ArrayIndex index)
const;
805 void makeIndexValid(ArrayIndex index);
809 PageIndex pageCount_;
894 reallocateArrayPageIndex(
Value **&indexes,
898 releaseArrayPageIndex(
Value **indexes,
900 virtual Value *allocateArrayPage() = 0;
901 virtual void releaseArrayPage(
Value *value) = 0;
903 #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP 916 #ifndef JSON_VALUE_USE_INTERNAL_MAP 923 bool operator==(
const SelfType &other)
const {
return isEqual(other); }
925 bool operator!=(
const SelfType &other)
const {
return !isEqual(other); }
927 difference_type
operator-(
const SelfType &other)
const {
928 return computeDistance(other);
940 const char *memberName()
const;
943 Value &deref()
const;
949 difference_type computeDistance(
const SelfType &other)
const;
951 bool isEqual(
const SelfType &other)
const;
953 void copy(
const SelfType &other);
956 #ifndef JSON_VALUE_USE_INTERNAL_MAP 957 Value::ObjectValues::iterator current_;
962 ValueInternalArray::IteratorState
array_;
963 ValueInternalMap::IteratorState
map_;
988 #ifndef JSON_VALUE_USE_INTERNAL_MAP 998 SelfType temp(*
this);
1004 SelfType temp(*
this);
1042 #ifndef JSON_VALUE_USE_INTERNAL_MAP 1043 explicit ValueIterator(
const Value::ObjectValues::iterator ¤t);
1045 ValueIterator(
const ValueInternalArray::IteratorState &state);
1046 ValueIterator(
const ValueInternalMap::IteratorState &state);
1049 SelfType &operator=(
const SelfType &other);
1052 SelfType temp(*
this);
1058 SelfType temp(*
this);
1078 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 1079 #pragma warning(pop) 1080 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 1082 #endif // CPPTL_JSON_H_INCLUDED
Experimental: do not use.
#define JSON_API
If defined, indicates that the source file is amalgated to prevent private header inclusion...
static const Int64 maxInt64
Maximum signed 64 bits int value that can be stored in a Json::Value.
static const Value & null
reference operator*() const
std::vector< std::string > Members
base class for Value iterators.
array value (ordered list)
Json::ArrayIndex ArrayIndex
object value (collection of name/value pairs).
Value::ArrayIndex ArrayIndex
ValueInternalLink * previous_
static const Int maxInt
Maximum signed int value that can be stored in a Json::Value.
Lightweight wrapper to tag static string.
ValueInternalMap::IteratorState map_
static const UInt maxUInt
Maximum unsigned int value that can be stored in a Json::Value.
Json::LargestUInt LargestUInt
bool operator!=(const SelfType &other) const
const iterator for object and array value.
Experimental and untested: represents an element of the "path" to access a node.
static const LargestInt minLargestInt
Minimum signed integer value that can be stored in a Json::Value.
StaticString(const char *czstring)
ValueConstIterator SelfType
ValueInternalMap hash-map bucket chain link (for internal use only).
ValueConstIterator const_iterator
Allocator to customize Value internal map.
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
JSON (JavaScript Object Notation).
ValueIteratorBase SelfType
Experimental and untested: represents a "path" to access a node.
Json::LargestInt LargestInt
const char * c_str() const
static const UInt64 maxUInt64
Maximum unsigned 64 bits int value that can be stored in a Json::Value.
A simplified deque implementation used internally by Value.
ValueInternalLink * next_
std::bidirectional_iterator_tag iterator_category
difference_type operator-(const SelfType &other) const
static const Int minInt
Minimum signed int value that can be stored in a Json::Value.
reference operator*() const
a comment on the line after a value (only make sense for
Iterator for object and array value.
A linked page based hash-table implementation used internally by Value.
ValueType
Type of the value held by a Value object.
a comment placed on the line before a value
ValueInternalArray::IteratorState array_
a comment just after a value on the same line
bool operator==(const SelfType &other) const
static const LargestInt maxLargestInt
Maximum signed integer value that can be stored in a Json::Value.
static const LargestUInt maxLargestUInt
Maximum unsigned integer value that can be stored in a Json::Value.