ADTF  3.18.2
value.h
1 // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
2 // Distributed under MIT license, or public domain if desired and
3 // recognized in your jurisdiction.
4 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
5 
6 #ifndef CPPTL_JSON_H_INCLUDED
7 #define CPPTL_JSON_H_INCLUDED
8 
9 #if !defined(JSON_IS_AMALGAMATION)
10 #include "forwards.h"
11 #endif // if !defined(JSON_IS_AMALGAMATION)
12 #include <string>
13 #include <vector>
14 #include <exception>
15 
16 #ifndef JSON_USE_CPPTL_SMALLMAP
17 #include <map>
18 #else
19 #include <cpptl/smallmap.h>
20 #endif
21 #ifdef JSON_USE_CPPTL
22 #include <cpptl/forwards.h>
23 #endif
24 
25 //Conditional NORETURN attribute on the throw functions would:
26 // a) suppress false positives from static code analysis
27 // b) possibly improve optimization opportunities.
28 #if !defined(JSONCPP_NORETURN)
29 # if defined(_MSC_VER)
30 # define JSONCPP_NORETURN __declspec(noreturn)
31 # elif defined(__GNUC__)
32 # define JSONCPP_NORETURN __attribute__ ((__noreturn__))
33 # else
34 # define JSONCPP_NORETURN
35 # endif
36 #endif
37 
38 // Disable warning C4251: <data member>: <type> needs to have dll-interface to
39 // be used by...
40 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
41 #pragma warning(push)
42 #pragma warning(disable : 4251)
43 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
44 
45 #pragma pack(push, 8)
46 
49 namespace Json {
50 
55 class JSON_API Exception : public std::exception {
56 public:
57  Exception(JSONCPP_STRING const& msg);
58  ~Exception() JSONCPP_NOEXCEPT JSONCPP_OVERRIDE;
59  char const* what() const JSONCPP_NOEXCEPT JSONCPP_OVERRIDE;
60 protected:
61  JSONCPP_STRING msg_;
62 };
63 
70 class JSON_API RuntimeError : public Exception {
71 public:
72  RuntimeError(JSONCPP_STRING const& msg);
73 };
74 
81 class JSON_API LogicError : public Exception {
82 public:
83  LogicError(JSONCPP_STRING const& msg);
84 };
85 
87 JSONCPP_NORETURN void throwRuntimeError(JSONCPP_STRING const& msg);
89 JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const& msg);
90 
93 enum ValueType {
94  nullValue = 0,
101  objectValue
102 };
103 
110 };
111 
112 //# ifdef JSON_USE_CPPTL
113 // typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
114 // typedef CppTL::AnyEnumerator<const Value &> EnumValues;
115 //# endif
116 
131 class JSON_API StaticString {
132 public:
133  explicit StaticString(const char* czstring) : c_str_(czstring) {}
134 
135  operator const char*() const { return c_str_; }
136 
137  const char* c_str() const { return c_str_; }
138 
139 private:
140  const char* c_str_;
141 };
142 
177 class JSON_API Value {
178  friend class ValueIteratorBase;
179 public:
180  typedef std::vector<JSONCPP_STRING> Members;
181  typedef ValueIterator iterator;
183  typedef Json::UInt UInt;
184  typedef Json::Int Int;
185 #if defined(JSON_HAS_INT64)
186  typedef Json::UInt64 UInt64;
187  typedef Json::Int64 Int64;
188 #endif // defined(JSON_HAS_INT64)
189  typedef Json::LargestInt LargestInt;
190  typedef Json::LargestUInt LargestUInt;
191  typedef Json::ArrayIndex ArrayIndex;
192 
193  // Required for boost integration, e. g. BOOST_TEST
194  typedef std::string value_type;
195 
196  static const Value& null;
197  static const Value& nullRef;
198  static Value const& nullSingleton();
199 
201  static const LargestInt minLargestInt;
203  static const LargestInt maxLargestInt;
205  static const LargestUInt maxLargestUInt;
206 
208  static const Int minInt;
210  static const Int maxInt;
212  static const UInt maxUInt;
213 
214 #if defined(JSON_HAS_INT64)
216  static const Int64 minInt64;
218  static const Int64 maxInt64;
220  static const UInt64 maxUInt64;
221 #endif // defined(JSON_HAS_INT64)
222 
223 private:
224 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
225  class CZString {
226  public:
227  enum DuplicationPolicy {
228  noDuplication = 0,
229  duplicate,
230  duplicateOnCopy
231  };
232  CZString(ArrayIndex index);
233  CZString(char const* str, unsigned length, DuplicationPolicy allocate);
234  CZString(CZString const& other);
235 #if JSON_HAS_RVALUE_REFERENCES
236  CZString(CZString&& other);
237 #endif
238  ~CZString();
239  CZString& operator=(const CZString& other);
240 
241 #if JSON_HAS_RVALUE_REFERENCES
242  CZString& operator=(CZString&& other);
243 #endif
244 
245  bool operator<(CZString const& other) const;
246  bool operator==(CZString const& other) const;
247  ArrayIndex index() const;
248  //const char* c_str() const; ///< \deprecated
249  char const* data() const;
250  unsigned length() const;
251  bool isStaticString() const;
252 
253  private:
254  void swap(CZString& other);
255 
256  struct StringStorage {
257  unsigned policy_: 2;
258  unsigned length_: 30; // 1GB max
259  };
260 
261  char const* cstr_; // actually, a prefixed string, unless policy is noDup
262  union {
263  ArrayIndex index_;
264  StringStorage storage_;
265  };
266  };
267 
268 public:
269 #ifndef JSON_USE_CPPTL_SMALLMAP
270  typedef std::map<CZString, Value> ObjectValues;
271 #else
272  typedef CppTL::SmallMap<CZString, Value> ObjectValues;
273 #endif // ifndef JSON_USE_CPPTL_SMALLMAP
274 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
275 
276 public:
293  Value(Int value);
294  Value(UInt value);
295 #if defined(JSON_HAS_INT64)
296  Value(Int64 value);
297  Value(UInt64 value);
298 #endif // if defined(JSON_HAS_INT64)
299  Value(double value);
300  Value(const char* value);
301  Value(const char* begin, const char* end);
317  Value(const StaticString& value);
318  Value(const JSONCPP_STRING& value);
319 #ifdef JSON_USE_CPPTL
320  Value(const CppTL::ConstString& value);
321 #endif
322  Value(bool value);
324  Value(const Value& other);
325 #if JSON_HAS_RVALUE_REFERENCES
327  Value(Value&& other);
328 #endif
329  ~Value();
330 
334 
336  void swap(Value& other);
338  void swapPayload(Value& other);
339 
341  void copy(const Value& other);
343  void copyPayload(const Value& other);
344 
345  ValueType type() const;
346 
348  bool operator<(const Value& other) const;
349  bool operator<=(const Value& other) const;
350  bool operator>=(const Value& other) const;
351  bool operator>(const Value& other) const;
352  bool operator==(const Value& other) const;
353  bool operator!=(const Value& other) const;
354  int compare(const Value& other) const;
355 
356  const char* asCString() const;
357 #if JSONCPP_USING_SECURE_MEMORY
358  unsigned getCStringLength() const; //Allows you to understand the length of the CString
359 #endif
360  JSONCPP_STRING asString() const;
364  bool getString(
365  char const** begin, char const** end) const;
366 #ifdef JSON_USE_CPPTL
367  CppTL::ConstString asConstString() const;
368 #endif
369  Int asInt() const;
370  UInt asUInt() const;
371 #if defined(JSON_HAS_INT64)
372  Int64 asInt64() const;
373  UInt64 asUInt64() const;
374 #endif // if defined(JSON_HAS_INT64)
375  LargestInt asLargestInt() const;
376  LargestUInt asLargestUInt() const;
377  float asFloat() const;
378  double asDouble() const;
379  bool asBool() const;
380 
381  bool isNull() const;
382  bool isBool() const;
383  bool isInt() const;
384  bool isInt64() const;
385  bool isUInt() const;
386  bool isUInt64() const;
387  bool isIntegral() const;
388  bool isDouble() const;
389  bool isNumeric() const;
390  bool isString() const;
391  bool isArray() const;
392  bool isObject() const;
393 
394  bool isConvertibleTo(ValueType other) const;
395 
397  ArrayIndex size() const;
398 
401  bool empty() const;
402 
404  explicit operator bool() const;
405 
409  void clear();
410 
416  void resize(ArrayIndex size);
417 
424  Value& operator[](ArrayIndex index);
425 
432  Value& operator[](int index);
433 
437  const Value& operator[](ArrayIndex index) const;
438 
442  const Value& operator[](int index) const;
443 
447  Value get(ArrayIndex index, const Value& defaultValue) const;
449  bool isValidIndex(ArrayIndex index) const;
453  Value& append(const Value& value);
454 
455 #if JSON_HAS_RVALUE_REFERENCES
456  Value& append(Value&& value);
457 #endif
458 
462  Value& operator[](const char* key);
465  const Value& operator[](const char* key) const;
468  Value& operator[](const JSONCPP_STRING& key);
472  const Value& operator[](const JSONCPP_STRING& key) const;
486 #ifdef JSON_USE_CPPTL
488  Value& operator[](const CppTL::ConstString& key);
491  const Value& operator[](const CppTL::ConstString& key) const;
492 #endif
495  Value get(const char* key, const Value& defaultValue) const;
499  Value get(const char* begin, const char* end, const Value& defaultValue) const;
503  Value get(const JSONCPP_STRING& key, const Value& defaultValue) const;
504 #ifdef JSON_USE_CPPTL
507  Value get(const CppTL::ConstString& key, const Value& defaultValue) const;
508 #endif
512  Value const* find(char const* begin, char const* end) const;
516  Value const* demand(char const* begin, char const* end);
524  void removeMember(const char* key);
528  void removeMember(const JSONCPP_STRING& key);
531  bool removeMember(const char* key, Value* removed);
538  bool removeMember(JSONCPP_STRING const& key, Value* removed);
540  bool removeMember(const char* begin, const char* end, Value* removed);
547  bool removeIndex(ArrayIndex i, Value* removed);
548 
551  bool isMember(const char* key) const;
554  bool isMember(const JSONCPP_STRING& key) const;
556  bool isMember(const char* begin, const char* end) const;
557 #ifdef JSON_USE_CPPTL
559  bool isMember(const CppTL::ConstString& key) const;
560 #endif
561 
567  Members getMemberNames() const;
568 
569  //# ifdef JSON_USE_CPPTL
570  // EnumMemberNames enumMemberNames() const;
571  // EnumValues enumValues() const;
572  //# endif
573 
575  JSONCPP_DEPRECATED("Use setComment(JSONCPP_STRING const&) instead.")
576  void setComment(const char* comment, CommentPlacement placement);
578  void setComment(const char* comment, size_t len, CommentPlacement placement);
580  void setComment(const JSONCPP_STRING& comment, CommentPlacement placement);
581  bool hasComment(CommentPlacement placement) const;
583  JSONCPP_STRING getComment(CommentPlacement placement) const;
584 
585  JSONCPP_STRING toStyledString() const;
586 
587  const_iterator begin() const;
588  const_iterator end() const;
589 
590  iterator begin();
591  iterator end();
592 
593  // Accessors for the [start, limit) range of bytes within the JSON text from
594  // which this value was parsed, if any.
595  void setOffsetStart(ptrdiff_t start);
596  void setOffsetLimit(ptrdiff_t limit);
597  ptrdiff_t getOffsetStart() const;
598  ptrdiff_t getOffsetLimit() const;
599 
600 private:
601  void initBasic(ValueType type, bool allocated = false);
602 
603  Value& resolveReference(const char* key);
604  Value& resolveReference(const char* key, const char* end);
605 
606  struct CommentInfo {
607  CommentInfo();
608  ~CommentInfo();
609 
610  void setComment(const char* text, size_t len);
611 
612  char* comment_;
613  };
614 
615  // struct MemberNamesTransform
616  //{
617  // typedef const char *result_type;
618  // const char *operator()( const CZString &name ) const
619  // {
620  // return name.c_str();
621  // }
622  //};
623 
624  union ValueHolder {
625  LargestInt int_;
626  LargestUInt uint_;
627  double real_;
628  bool bool_;
629  char* string_; // actually ptr to unsigned, followed by str, unless !allocated_
630  ObjectValues* map_;
631  } value_;
632  ValueType type_ : 8;
633  unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
634  // If not allocated_, string_ must be null-terminated.
635  CommentInfo* comments_;
636 
637  // [start, limit) byte offsets in the source JSON text from which this Value
638  // was extracted.
639  ptrdiff_t start_;
640  ptrdiff_t limit_;
641 };
642 
646 class JSON_API PathArgument {
647 public:
648  friend class Path;
649 
650  PathArgument();
651  PathArgument(ArrayIndex index);
652  PathArgument(const char* key);
653  PathArgument(const JSONCPP_STRING& key);
654 
655 private:
656  enum Kind {
657  kindNone = 0,
658  kindIndex,
659  kindKey
660  };
661  JSONCPP_STRING key_;
662  ArrayIndex index_;
663  Kind kind_;
664 };
665 
677 class JSON_API Path {
678 public:
679  Path(const JSONCPP_STRING& path,
680  const PathArgument& a1 = PathArgument(),
681  const PathArgument& a2 = PathArgument(),
682  const PathArgument& a3 = PathArgument(),
683  const PathArgument& a4 = PathArgument(),
684  const PathArgument& a5 = PathArgument());
685 
686  const Value& resolve(const Value& root) const;
687  Value resolve(const Value& root, const Value& defaultValue) const;
690  Value& make(Value& root) const;
691 
692 private:
693  typedef std::vector<const PathArgument*> InArgs;
694  typedef std::vector<PathArgument> Args;
695 
696  void makePath(const JSONCPP_STRING& path, const InArgs& in);
697  void addPathInArg(const JSONCPP_STRING& path,
698  const InArgs& in,
699  InArgs::const_iterator& itInArg,
700  PathArgument::Kind kind);
701  void invalidPath(const JSONCPP_STRING& path, int location);
702 
703  Args args_;
704 };
705 
709 class JSON_API ValueIteratorBase {
710 public:
711  typedef std::bidirectional_iterator_tag iterator_category;
712  typedef unsigned int size_t;
713  typedef int difference_type;
714  typedef ValueIteratorBase SelfType;
715 
716  bool operator==(const SelfType& other) const { return isEqual(other); }
717 
718  bool operator!=(const SelfType& other) const { return !isEqual(other); }
719 
720  difference_type operator-(const SelfType& other) const {
721  return other.computeDistance(*this);
722  }
723 
726  Value key() const;
727 
729  UInt index() const;
730 
734  JSONCPP_STRING name() const;
735 
739  JSONCPP_DEPRECATED("Use `key = name();` instead.")
740  char const* memberName() const;
744  char const* memberName(char const** end) const;
745 
746 protected:
747  Value& deref() const;
748 
749  void increment();
750 
751  void decrement();
752 
753  difference_type computeDistance(const SelfType& other) const;
754 
755  bool isEqual(const SelfType& other) const;
756 
757  void copy(const SelfType& other);
758 
759 private:
760  Value::ObjectValues::iterator current_;
761  // Indicates that iterator is for a null value.
762  bool isNull_;
763 
764 public:
765  // For some reason, BORLAND needs these at the end, rather
766  // than earlier. No idea why.
768  explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
769 };
770 
774 class JSON_API ValueConstIterator : public ValueIteratorBase {
775  friend class Value;
776 
777 public:
778  typedef const Value value_type;
779  //typedef unsigned int size_t;
780  //typedef int difference_type;
781  typedef const Value& reference;
782  typedef const Value* pointer;
784 
786  ValueConstIterator(ValueIterator const& other);
787 
788 private:
791  explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
792 public:
793  SelfType& operator=(const ValueIteratorBase& other);
794 
795  SelfType operator++(int) {
796  SelfType temp(*this);
797  ++*this;
798  return temp;
799  }
800 
801  SelfType operator--(int) {
802  SelfType temp(*this);
803  --*this;
804  return temp;
805  }
806 
807  SelfType& operator--() {
808  decrement();
809  return *this;
810  }
811 
812  SelfType& operator++() {
813  increment();
814  return *this;
815  }
816 
817  reference operator*() const { return deref(); }
818 
819  pointer operator->() const { return &deref(); }
820 };
821 
824 class JSON_API ValueIterator : public ValueIteratorBase {
825  friend class Value;
826 
827 public:
828  typedef Value value_type;
829  typedef unsigned int size_t;
830  typedef int difference_type;
831  typedef Value& reference;
832  typedef Value* pointer;
833  typedef ValueIterator SelfType;
834 
835  ValueIterator();
836  explicit ValueIterator(const ValueConstIterator& other);
837  ValueIterator(const ValueIterator& other);
838 
839 private:
842  explicit ValueIterator(const Value::ObjectValues::iterator& current);
843 public:
844  SelfType& operator=(const SelfType& other);
845 
846  SelfType operator++(int) {
847  SelfType temp(*this);
848  ++*this;
849  return temp;
850  }
851 
852  SelfType operator--(int) {
853  SelfType temp(*this);
854  --*this;
855  return temp;
856  }
857 
858  SelfType& operator--() {
859  decrement();
860  return *this;
861  }
862 
863  SelfType& operator++() {
864  increment();
865  return *this;
866  }
867 
868  reference operator*() const { return deref(); }
869 
870  pointer operator->() const { return &deref(); }
871 };
872 
873 } // namespace Json
874 
875 
876 namespace std {
878 template<>
879 inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); }
880 }
881 
882 #pragma pack(pop)
883 
884 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
885 #pragma warning(pop)
886 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
887 
888 #endif // CPPTL_JSON_H_INCLUDED
tBool operator<(const tErrorCode &lhs, const tErrorCode &rhs)
Less-than operator for POD error type.
tBool operator<=(const tErrorCode &lhs, const tErrorCode &rhs)
Less-than-or-equal operator for POD error type.
tBool operator>(const tErrorCode &lhs, const tErrorCode &rhs)
Greater-than operator for POD error type.
tBool operator!=(const tErrorCode &lhs, const tErrorCode &rhs)
Compare two POD error code types for inequality.
tBool operator==(const tErrorCode &lhs, const tErrorCode &rhs)
Compare two POD error code types for equality.
tBool operator>=(const tErrorCode &lhs, const tErrorCode &rhs)
Greater-than-or-equal operator for POD error type.
Base class for all exceptions we throw.
Definition: value.h:55
Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
Definition: value.h:81
Experimental and untested: represents an element of the "path" to access a node.
Definition: value.h:646
Experimental and untested: represents a "path" to access a node.
Definition: value.h:677
Value & make(Value &root) const
Creates the "path" to access the specified node and returns a reference on the node.
Exceptions which the user cannot easily avoid.
Definition: value.h:70
Lightweight wrapper to tag static string.
Definition: value.h:131
const iterator for object and array value.
Definition: value.h:774
Represents a JSON value.
Definition: value.h:177
Value(const StaticString &value)
Constructs a value from a static string.
static const Int64 minInt64
Minimum signed 64 bits int value that can be stored in a Json::Value.
Definition: value.h:216
Value & append(const Value &value)
Append value to array at the end.
static const Value & nullRef
just a kludge for binary-compatibility; same as null
Definition: value.h:197
Value & operator[](const JSONCPP_STRING &key)
Access an object value by name, create a null member if it does not exist.
static const LargestInt maxLargestInt
Maximum signed integer value that can be stored in a Json::Value.
Definition: value.h:203
bool removeIndex(ArrayIndex i, Value *removed)
Remove the indexed array element.
Value get(ArrayIndex index, const Value &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
static const LargestUInt maxLargestUInt
Maximum unsigned integer value that can be stored in a Json::Value.
Definition: value.h:205
Value(const Value &other)
Deep copy.
const char * asCString() const
Embedded zeroes could cause you trouble!
ArrayIndex size() const
Number of values in array or object.
const Value & operator[](const JSONCPP_STRING &key) const
Access an object value by name, returns null if there is no member with that name.
Value(const char *begin, const char *end)
Copy all, incl zeroes.
Value const * find(char const *begin, char const *end) const
Most general and efficient version of isMember()const, get()const, and operator[]const.
const Value & operator[](int index) const
Access an array element (zero based index ) (You may need to say 'value[0u]' to get your compiler to ...
static const Int minInt
Minimum signed int value that can be stored in a Json::Value.
Definition: value.h:208
bool empty() const
Return true if empty array, empty object, or null; otherwise, false.
static Value const & nullSingleton()
Prefer this to null or nullRef.
Value(ValueType type=nullValue)
Create a default Value of the given type.
void resize(ArrayIndex size)
Resize the array to size elements.
void copyPayload(const Value &other)
copy values but leave comments and source offsets in place.
Value(const JSONCPP_STRING &value)
Copy data() til size(). Embedded zeroes too.
Value(const char *value)
Copy til first 0. (NULL causes to seg-fault.)
bool isMember(const JSONCPP_STRING &key) const
Return true if the object has a member named key.
void copy(const Value &other)
copy everything.
Value & operator[](const StaticString &key)
Access an object value by name, create a null member if it does not exist.
static const UInt maxUInt
Maximum unsigned int value that can be stored in a Json::Value.
Definition: value.h:212
Value const * demand(char const *begin, char const *end)
Most general and efficient version of object-mutators.
bool getString(char const **begin, char const **end) const
Get raw char* of string-value.
static const LargestInt minLargestInt
Minimum signed integer value that can be stored in a Json::Value.
Definition: value.h:201
bool isMember(const char *begin, const char *end) const
Same as isMember(JSONCPP_STRING const& key)const.
Value get(const char *key, const Value &defaultValue) const
Return the member named key if it exist, defaultValue otherwise.
bool isValidIndex(ArrayIndex index) const
Return true if index < size().
Value get(const JSONCPP_STRING &key, const Value &defaultValue) const
Return the member named key if it exist, defaultValue otherwise.
Value get(const char *begin, const char *end, const Value &defaultValue) const
Return the member named key if it exist, defaultValue otherwise.
Members getMemberNames() const
Return a list of the member names.
Value & operator[](ArrayIndex index)
Access an array element (zero based index ).
Value & operator[](const char *key)
Access an object value by name, create a null member if it does not exist.
bool removeMember(const char *begin, const char *end, Value *removed)
Same as removeMember(JSONCPP_STRING const& key, Value* removed)
void removeMember(const JSONCPP_STRING &key)
Same as removeMember(const char*)
Value & operator=(Value other)
Deep copy, then swap(other).
static const UInt64 maxUInt64
Maximum unsigned 64 bits int value that can be stored in a Json::Value.
Definition: value.h:220
const Value & operator[](ArrayIndex index) const
Access an array element (zero based index ) (You may need to say 'value[0u]' to get your compiler to ...
static const Int64 maxInt64
Maximum signed 64 bits int value that can be stored in a Json::Value.
Definition: value.h:218
void swap(Value &other)
Swap everything.
void clear()
Remove all object members and array elements.
void swapPayload(Value &other)
Swap values but leave comments and source offsets in place.
bool operator<(const Value &other) const
Compare payload only, not comments etc.
JSONCPP_STRING asString() const
Embedded zeroes are possible.
bool removeMember(JSONCPP_STRING const &key, Value *removed)
Remove the named map member.
void removeMember(const char *key)
Remove and return the named member.
bool isMember(const char *key) const
Return true if the object has a member named key.
const Value & operator[](const char *key) const
Access an object value by name, returns null if there is no member with that name.
static const Int maxInt
Maximum signed int value that can be stored in a Json::Value.
Definition: value.h:210
bool removeMember(const char *key, Value *removed)
Same as removeMember(const char* begin, const char* end, Value* removed), but 'key' is null-terminate...
Value & operator[](int index)
Access an array element (zero based index ).
base class for Value iterators.
Definition: value.h:709
UInt index() const
Return the index of the referenced Value, or -1 if it is not an arrayValue.
Value key() const
Return either the index or the member name of the referenced value as a Value.
JSONCPP_STRING name() const
Return the member name of the referenced Value, or "" if it is not an objectValue.
Iterator for object and array value.
Definition: value.h:824
simple_pointer_iterator< T >::difference_type operator-(const simple_pointer_iterator< T > &r1, const simple_pointer_iterator< T > &r2)
Define arithmetic - operation between iterators.
JSON (JavaScript Object Notation).
Definition: allocator.h:14
JSONCPP_NORETURN void throwRuntimeError(JSONCPP_STRING const &msg)
used internally
JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const &msg)
used internally
class JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead") JSON_API Reader
Unserialize a JSON document into a Value.
CommentPlacement
Definition: value.h:104
@ commentAfterOnSameLine
a comment just after a value on the same line
Definition: value.h:106
@ commentBefore
a comment placed on the line before a value
Definition: value.h:105
@ numberOfCommentPlacement
root value)
Definition: value.h:109
@ commentAfter
a comment on the line after a value (only make sense for
Definition: value.h:107
ValueType
Type of the value held by a Value object.
Definition: value.h:93
@ booleanValue
bool value
Definition: value.h:99
@ realValue
double value
Definition: value.h:97
@ stringValue
UTF-8 string value.
Definition: value.h:98
@ intValue
signed integer value
Definition: value.h:95
@ arrayValue
array value (ordered list)
Definition: value.h:100
@ nullValue
'null' value
Definition: value.h:94
@ uintValue
unsigned integer value
Definition: value.h:96
@ objectValue
object value (collection of name/value pairs).
Definition: value.h:101
int compare(const void *buf1, std::size_t buf1_size, const void *buf2, std::size_t buf2_size)
Portable safe memcmp.
bool copy(void *dest, std::size_t dest_size, const void *source, std::size_t bytes_to_copy)
Portable safe memcopy.
bool isInt64(const std::string &str)
Check whether a string can be converted to a value of the given numeric type.
bool isNumeric(const char *str)
Check whether a string is convertible to a value of type Numeric for generic programming.
bool isEqual(const char *left, const char *right)
Compares two 0-terminated C-strings for equality.
bool isBool(const std::string &str)
Check whether a string can be converted to a boolean type.
bool isDouble(const std::string &str)
Check whether a string can be converted to a value of the given numeric type.
bool isUInt64(const std::string &str)
Check whether a string can be converted to a value of the given numeric type.