JsonCpp project page Classes Namespace JsonCpp home page

value.h
Go to the documentation of this file.
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 JSON_VALUE_H_INCLUDED
7 #define JSON_VALUE_H_INCLUDED
8 
9 #if !defined(JSON_IS_AMALGAMATION)
10 #include "forwards.h"
11 #endif // if !defined(JSON_IS_AMALGAMATION)
12 
13 // Conditional NORETURN attribute on the throw functions would:
14 // a) suppress false positives from static code analysis
15 // b) possibly improve optimization opportunities.
16 #if !defined(JSONCPP_NORETURN)
17 #if defined(_MSC_VER) && _MSC_VER == 1800
18 #define JSONCPP_NORETURN __declspec(noreturn)
19 #else
20 #define JSONCPP_NORETURN [[noreturn]]
21 #endif
22 #endif
23 
24 // Support for '= delete' with template declarations was a late addition
25 // to the c++11 standard and is rejected by clang 3.8 and Apple clang 8.2
26 // even though these declare themselves to be c++11 compilers.
27 #if !defined(JSONCPP_TEMPLATE_DELETE)
28 #if defined(__clang__) && defined(__apple_build_version__)
29 #if __apple_build_version__ <= 8000042
30 #define JSONCPP_TEMPLATE_DELETE
31 #endif
32 #elif defined(__clang__)
33 #if __clang_major__ == 3 && __clang_minor__ <= 8
34 #define JSONCPP_TEMPLATE_DELETE
35 #endif
36 #endif
37 #if !defined(JSONCPP_TEMPLATE_DELETE)
38 #define JSONCPP_TEMPLATE_DELETE = delete
39 #endif
40 #endif
41 
42 #ifndef JSONCPP_HAS_STRING_VIEW
43 #if __cplusplus >= 201703L
44 #define JSONCPP_HAS_STRING_VIEW 1
45 #endif
46 #endif
47 
48 #include <array>
49 #include <exception>
50 #include <map>
51 #include <memory>
52 #include <string>
53 #include <vector>
54 
55 // Forward declaration for testing.
56 struct ValueTest;
57 
58 #ifdef JSONCPP_HAS_STRING_VIEW
59 #include <string_view>
60 #endif
61 
62 // Disable warning C4251: <data member>: <type> needs to have dll-interface to
63 // be used by...
64 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
65 #pragma warning(push)
66 #pragma warning(disable : 4251 4275)
67 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
68 
69 #pragma pack(push)
70 #pragma pack()
71 
74 namespace Json {
75 
76 #if JSON_USE_EXCEPTION
77 
81 class JSON_API Exception : public std::exception {
82 public:
83  Exception(String msg);
84  ~Exception() noexcept override;
85  char const* what() const noexcept override;
86 
87 protected:
89 };
90 
98 public:
99  RuntimeError(String const& msg);
100 };
101 
108 class JSON_API LogicError : public Exception {
109 public:
110  LogicError(String const& msg);
111 };
112 #endif
113 
115 JSONCPP_NORETURN void throwRuntimeError(String const& msg);
117 JSONCPP_NORETURN void throwLogicError(String const& msg);
118 
121 enum ValueType {
122  nullValue = 0,
130 };
131 
138 };
139 
145 };
146 
162 public:
163  explicit StaticString(const char* czstring) : c_str_(czstring) {}
164 
165  operator const char*() const { return c_str_; }
166 
167  const char* c_str() const { return c_str_; }
168 
169 private:
170  const char* c_str_;
171 };
172 
208  friend class ValueIteratorBase;
209  friend struct ::ValueTest;
210 
211 public:
212  using Members = std::vector<String>;
215  using UInt = Json::UInt;
216  using Int = Json::Int;
217 #if defined(JSON_HAS_INT64)
220 #endif // defined(JSON_HAS_INT64)
224 
225  // Required for boost integration, e. g. BOOST_TEST
226  using value_type = std::string;
227 
228 #if JSON_USE_NULLREF
229  // Binary compatibility kludges, do not use.
230  static const Value& null;
231  static const Value& nullRef;
232 #endif
233 
234  // null and nullRef are deprecated, use this instead.
235  static Value const& nullSingleton();
236 
238  static constexpr LargestInt minLargestInt =
239  LargestInt(~(LargestUInt(-1) / 2));
241  static constexpr LargestInt maxLargestInt = LargestInt(LargestUInt(-1) / 2);
243  static constexpr LargestUInt maxLargestUInt = LargestUInt(-1);
244 
246  static constexpr Int minInt = Int(~(UInt(-1) / 2));
248  static constexpr Int maxInt = Int(UInt(-1) / 2);
250  static constexpr UInt maxUInt = UInt(-1);
251 
252 #if defined(JSON_HAS_INT64)
253  static constexpr Int64 minInt64 = Int64(~(UInt64(-1) / 2));
256  static constexpr Int64 maxInt64 = Int64(UInt64(-1) / 2);
258  static constexpr UInt64 maxUInt64 = UInt64(-1);
259 #endif // defined(JSON_HAS_INT64)
260  static constexpr UInt defaultRealPrecision = 17;
262  // The constant is hard-coded because some compiler have trouble
263  // converting Value::maxUInt64 to a double correctly (AIX/xlC).
264  // Assumes that UInt64 is a 64 bits integer.
265  static constexpr double maxUInt64AsDouble = 18446744073709551615.0;
266 // Workaround for bug in the NVIDIAs CUDA 9.1 nvcc compiler
267 // when using gcc and clang backend compilers. CZString
268 // cannot be defined as private. See issue #486
269 #ifdef __NVCC__
270 public:
271 #else
272 private:
273 #endif
274 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
275  class JSON_API CZString {
276  public:
277  enum DuplicationPolicy { noDuplication = 0, duplicate, duplicateOnCopy };
278  CZString(ArrayIndex index);
279  CZString(char const* str, unsigned length, DuplicationPolicy allocate);
280  CZString(CZString const& other);
281  CZString(CZString&& other) noexcept;
282  ~CZString();
283  CZString& operator=(const CZString& other);
284  CZString& operator=(CZString&& other) noexcept;
285 
286  bool operator<(CZString const& other) const;
287  bool operator==(CZString const& other) const;
288  ArrayIndex index() const;
289  // const char* c_str() const; ///< \deprecated
290  char const* data() const;
291  unsigned length() const;
292  bool isStaticString() const;
293 
294  private:
295  void swap(CZString& other);
296 
297  struct StringStorage {
298  unsigned policy_ : 2;
299  unsigned length_ : 30; // 1GB max
300  };
301 
302  char const* cstr_; // actually, a prefixed string, unless policy is noDup
303  union {
304  ArrayIndex index_;
305  StringStorage storage_;
306  };
307  };
308 
309 public:
310  typedef std::map<CZString, Value> ObjectValues;
311 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
312 
313 public:
330  Value(ValueType type = nullValue);
331  Value(Int value);
332  Value(UInt value);
333 #if defined(JSON_HAS_INT64)
334  Value(Int64 value);
335  Value(UInt64 value);
336 #endif // if defined(JSON_HAS_INT64)
337  Value(double value);
338  Value(const char* value);
339  Value(const char* begin, const char* end);
340 
357  Value(const StaticString& value);
358  Value(const String& value);
359 #ifdef JSONCPP_HAS_STRING_VIEW
360  inline Value(std::string_view value)
361  : Value(value.data(), value.data() + value.length()) {}
362 #endif
363  Value(bool value);
364  Value(std::nullptr_t ptr) = delete;
365  Value(const Value& other);
366  Value(Value&& other) noexcept;
367  ~Value();
368 
371  Value& operator=(const Value& other);
372  Value& operator=(Value&& other) noexcept;
373 
375  void swap(Value& other);
377  void swapPayload(Value& other);
378 
380  void copy(const Value& other);
382  void copyPayload(const Value& other);
383 
384  ValueType type() const;
385 
387  bool operator<(const Value& other) const;
388  bool operator<=(const Value& other) const;
389  bool operator>=(const Value& other) const;
390  bool operator>(const Value& other) const;
391  bool operator==(const Value& other) const;
392  bool operator!=(const Value& other) const;
393  int compare(const Value& other) const;
394 
395  const char* asCString() const;
396 #if JSONCPP_USE_SECURE_MEMORY
397  unsigned getCStringLength() const; // Allows you to understand the length of
398  // the CString
399 #endif
400  String asString() const;
401 
404  bool getString(char const** begin, char const** end) const;
405 #ifdef JSONCPP_HAS_STRING_VIEW
406 
409  inline bool getString(std::string_view* str) const {
410  char const* begin;
411  char const* end;
412  if (!getString(&begin, &end))
413  return false;
414  *str = std::string_view(begin, static_cast<size_t>(end - begin));
415  return true;
416  }
417 #endif
418  Int asInt() const;
419  UInt asUInt() const;
420 #if defined(JSON_HAS_INT64)
421  Int64 asInt64() const;
422  UInt64 asUInt64() const;
423 #endif // if defined(JSON_HAS_INT64)
424  LargestInt asLargestInt() const;
425  LargestUInt asLargestUInt() const;
426  float asFloat() const;
427  double asDouble() const;
428  bool asBool() const;
429 
430  bool isNull() const;
431  bool isBool() const;
432  bool isInt() const;
433  bool isInt64() const;
434  bool isUInt() const;
435  bool isUInt64() const;
436  bool isIntegral() const;
437  bool isDouble() const;
438  bool isNumeric() const;
439  bool isString() const;
440  bool isArray() const;
441  bool isObject() const;
442 
444  template <typename T> T as() const JSONCPP_TEMPLATE_DELETE;
445  template <typename T> bool is() const JSONCPP_TEMPLATE_DELETE;
446 
447  bool isConvertibleTo(ValueType other) const;
448 
450  ArrayIndex size() const;
451 
454  bool empty() const;
455 
457  explicit operator bool() const;
458 
462  void clear();
463 
469  void resize(ArrayIndex newSize);
470 
477  Value& operator[](ArrayIndex index);
478  Value& operator[](int index);
480 
485  const Value& operator[](ArrayIndex index) const;
486  const Value& operator[](int index) const;
488 
491  Value get(ArrayIndex index, const Value& defaultValue) const;
493  bool isValidIndex(ArrayIndex index) const;
497  Value& append(const Value& value);
498  Value& append(Value&& value);
499 
501  bool insert(ArrayIndex index, const Value& newValue);
502  bool insert(ArrayIndex index, Value&& newValue);
503 
504 #ifdef JSONCPP_HAS_STRING_VIEW
505  inline Value& operator[](std::string_view key) {
508  return resolveReference(key.data(), key.data() + key.length());
509  }
513  inline const Value& operator[](std::string_view key) const {
514  Value const* found = find(key.data(), key.data() + key.length());
515  if (!found)
516  return nullSingleton();
517  return *found;
518  }
519 #endif
520  Value& operator[](const char* key);
526  const Value& operator[](const char* key) const;
529  Value& operator[](const String& key);
533  const Value& operator[](const String& key) const;
546  Value& operator[](const StaticString& key);
547 #ifdef JSONCPP_HAS_STRING_VIEW
548  inline Value get(std::string_view key, const Value& defaultValue) const {
551  return get(key.data(), key.data() + key.length(), defaultValue);
552  }
553 #endif
554  Value get(const char* key, const Value& defaultValue) const;
560  Value get(const String& key, const Value& defaultValue) const;
564  Value get(const char* begin, const char* end,
565  const Value& defaultValue) const;
569  Value const* find(char const* begin, char const* end) const;
572  Value const* find(const String& key) const;
573 
575  template <typename T, bool (T::*TMemFn)() const>
576  Value const* findValue(const String& key) const {
577  Value const* found = find(key);
578  if (!found || !(found->*TMemFn)())
579  return nullptr;
580  return found;
581  }
582 
583  Value const* findNull(const String& key) const;
584  Value const* findBool(const String& key) const;
585  Value const* findInt(const String& key) const;
586  Value const* findInt64(const String& key) const;
587  Value const* findUInt(const String& key) const;
588  Value const* findUInt64(const String& key) const;
589  Value const* findIntegral(const String& key) const;
590  Value const* findDouble(const String& key) const;
591  Value const* findNumeric(const String& key) const;
592  Value const* findString(const String& key) const;
593  Value const* findArray(const String& key) const;
594  Value const* findObject(const String& key) const;
595 
599  Value* demand(char const* begin, char const* end);
605 #if JSONCPP_HAS_STRING_VIEW
606  inline void removeMember(std::string_view key) {
607  removeMember(key.data(), key.data() + key.length(), nullptr);
608  }
609 #endif
610  void removeMember(const char* key);
613  void removeMember(const String& key);
620 #if JSONCPP_HAS_STRING_VIEW
621  inline bool removeMember(std::string_view key, Value* removed) {
622  return removeMember(key.data(), key.data() + key.length(), removed);
623  }
624 #endif
625  bool removeMember(String const& key, Value* removed);
628  bool removeMember(const char* key, Value* removed);
630  bool removeMember(const char* begin, const char* end, Value* removed);
637  bool removeIndex(ArrayIndex index, Value* removed);
638 
639 #ifdef JSONCPP_HAS_STRING_VIEW
640  inline bool isMember(std::string_view key) const {
643  return isMember(key.data(), key.data() + key.length());
644  }
645 #endif
646  bool isMember(const char* key) const;
651  bool isMember(const String& key) const;
653  bool isMember(const char* begin, const char* end) const;
654 
660  Members getMemberNames() const;
661 
663  JSONCPP_DEPRECATED("Use setComment(String const&) instead.")
664  void setComment(const char* comment, CommentPlacement placement) {
665  setComment(String(comment, strlen(comment)), placement);
666  }
668  void setComment(const char* comment, size_t len, CommentPlacement placement) {
669  setComment(String(comment, len), placement);
670  }
672  void setComment(String comment, CommentPlacement placement);
673  bool hasComment(CommentPlacement placement) const;
675  String getComment(CommentPlacement placement) const;
676 
677  String toStyledString() const;
678 
679  const_iterator begin() const;
680  const_iterator end() const;
681 
682  iterator begin();
683  iterator end();
684 
685  // \brief Returns a view of member pairs for range-based for loops.
686  ValueMembersView members();
687  // \brief Returns a view of member pairs for range-based for loops.
688  ValueConstMembersView members() const;
689 
693  const Value& front() const;
694 
698  Value& front();
699 
703  const Value& back() const;
704 
708  Value& back();
709 
710  // Accessors for the [start, limit) range of bytes within the JSON text from
711  // which this value was parsed, if any.
712  void setOffsetStart(ptrdiff_t start);
713  void setOffsetLimit(ptrdiff_t limit);
714  ptrdiff_t getOffsetStart() const;
715  ptrdiff_t getOffsetLimit() const;
716 
717 private:
718  void setType(ValueType v) {
719  bits_.value_type_ = static_cast<unsigned char>(v);
720  }
721  bool isAllocated() const { return bits_.allocated_; }
722  void setIsAllocated(bool v) { bits_.allocated_ = v; }
723 
724  void initBasic(ValueType type, bool allocated = false);
725  void dupPayload(const Value& other);
726  void releasePayload();
727  void dupMeta(const Value& other);
728 
729  Value& resolveReference(const char* key);
730  Value& resolveReference(const char* key, const char* end);
731 
732  // struct MemberNamesTransform
733  //{
734  // typedef const char *result_type;
735  // const char *operator()( const CZString &name ) const
736  // {
737  // return name.c_str();
738  // }
739  //};
740 
741  union ValueHolder {
742  LargestInt int_;
743  LargestUInt uint_;
744  double real_;
745  bool bool_;
746  char* string_; // if allocated_, ptr to { unsigned, char[] }.
747  ObjectValues* map_;
748  } value_;
749 
750  struct {
751  // Really a ValueType, but types should agree for bitfield packing.
752  unsigned int value_type_ : 8;
753  // Unless allocated_, string_ must be null-terminated.
754  unsigned int allocated_ : 1;
755  } bits_;
756 
757  class Comments {
758  public:
759  Comments() = default;
760  Comments(const Comments& that);
761  Comments(Comments&& that) noexcept;
762  Comments& operator=(const Comments& that);
763  Comments& operator=(Comments&& that) noexcept;
764  bool has(CommentPlacement slot) const;
765  String get(CommentPlacement slot) const;
766  void set(CommentPlacement slot, String comment);
767 
768  private:
769  using Array = std::array<String, numberOfCommentPlacement>;
770  std::unique_ptr<Array> ptr_;
771  };
772  Comments comments_;
773 
774  // [start, limit) byte offsets in the source JSON text from which this Value
775  // was extracted.
776  ptrdiff_t start_;
777  ptrdiff_t limit_;
778 };
779 
780 template <> inline bool Value::as<bool>() const { return asBool(); }
781 template <> inline bool Value::is<bool>() const { return isBool(); }
782 
783 template <> inline Int Value::as<Int>() const { return asInt(); }
784 template <> inline bool Value::is<Int>() const { return isInt(); }
785 
786 template <> inline UInt Value::as<UInt>() const { return asUInt(); }
787 template <> inline bool Value::is<UInt>() const { return isUInt(); }
788 
789 #if defined(JSON_HAS_INT64)
790 template <> inline Int64 Value::as<Int64>() const { return asInt64(); }
791 template <> inline bool Value::is<Int64>() const { return isInt64(); }
792 
793 template <> inline UInt64 Value::as<UInt64>() const { return asUInt64(); }
794 template <> inline bool Value::is<UInt64>() const { return isUInt64(); }
795 #endif
796 
797 template <> inline double Value::as<double>() const { return asDouble(); }
798 template <> inline bool Value::is<double>() const { return isDouble(); }
799 
800 template <> inline String Value::as<String>() const { return asString(); }
801 template <> inline bool Value::is<String>() const { return isString(); }
802 
805 template <> inline float Value::as<float>() const { return asFloat(); }
806 template <> inline const char* Value::as<const char*>() const {
807  return asCString();
808 }
809 
814 public:
815  friend class Path;
816 
817  PathArgument();
818  PathArgument(ArrayIndex index);
819  PathArgument(const char* key);
820  PathArgument(String key);
821 
822 private:
823  enum Kind { kindNone = 0, kindIndex, kindKey };
824  String key_;
825  ArrayIndex index_{};
826  Kind kind_{kindNone};
827 };
828 
840 class JSON_API Path {
841 public:
842  Path(const String& path, const PathArgument& a1 = PathArgument(),
843  const PathArgument& a2 = PathArgument(),
844  const PathArgument& a3 = PathArgument(),
845  const PathArgument& a4 = PathArgument(),
846  const PathArgument& a5 = PathArgument());
847 
848  const Value& resolve(const Value& root) const;
849  Value resolve(const Value& root, const Value& defaultValue) const;
852  Value& make(Value& root) const;
853 
854 private:
855  using InArgs = std::vector<const PathArgument*>;
856  using Args = std::vector<PathArgument>;
857 
858  void makePath(const String& path, const InArgs& in);
859  void addPathInArg(const String& path, const InArgs& in,
860  InArgs::const_iterator& itInArg, PathArgument::Kind kind);
861  static void invalidPath(const String& path, int location);
862 
863  Args args_;
864 };
865 
870 public:
871  using iterator_category = std::bidirectional_iterator_tag;
872  using size_t = unsigned int;
873  using difference_type = int;
875 
876  bool operator==(const SelfType& other) const { return isEqual(other); }
877 
878  bool operator!=(const SelfType& other) const { return !isEqual(other); }
879 
880  difference_type operator-(const SelfType& other) const {
881  return other.computeDistance(*this);
882  }
883 
886  Value key() const;
887 
890  UInt index() const;
891 
895  String name() const;
896 
901  JSONCPP_DEPRECATED("Use `key = name();` instead.")
902  char const* memberName() const;
906  char const* memberName(char const** end) const;
907 
908 protected:
915  const Value& deref() const;
916  Value& deref();
917 
918  void increment();
919 
920  void decrement();
921 
922  difference_type computeDistance(const SelfType& other) const;
923 
924  bool isEqual(const SelfType& other) const;
925 
926  void copy(const SelfType& other);
927 
928 private:
929  Value::ObjectValues::iterator current_;
930  // Indicates that iterator is for a null value.
931  bool isNull_{true};
932 
933 public:
934  // For some reason, BORLAND needs these at the end, rather
935  // than earlier. No idea why.
936  ValueIteratorBase();
937  explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
938 };
939 
944  friend class Value;
945 
946 public:
947  using value_type = const Value;
948  // typedef unsigned int size_t;
949  // typedef int difference_type;
950  using reference = const Value&;
951  using pointer = const Value*;
953 
955  ValueConstIterator(ValueIterator const& other);
956 
957 private:
960  explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
961 
962 public:
963  SelfType& operator=(const ValueIteratorBase& other);
964 
966  SelfType temp(*this);
967  ++*this;
968  return temp;
969  }
970 
972  SelfType temp(*this);
973  --*this;
974  return temp;
975  }
976 
978  decrement();
979  return *this;
980  }
981 
983  increment();
984  return *this;
985  }
986 
987  reference operator*() const { return deref(); }
988 
989  pointer operator->() const { return &deref(); }
990 };
991 
995  friend class Value;
996 
997 public:
998  using value_type = Value;
999  using size_t = unsigned int;
1000  using difference_type = int;
1001  using reference = Value&;
1002  using pointer = Value*;
1004 
1005  ValueIterator();
1006  explicit ValueIterator(const ValueConstIterator& other);
1007  ValueIterator(const ValueIterator& other);
1008 
1009 private:
1012  explicit ValueIterator(const Value::ObjectValues::iterator& current);
1013 
1014 public:
1015  SelfType& operator=(const SelfType& other);
1016 
1018  SelfType temp(*this);
1019  ++*this;
1020  return temp;
1021  }
1022 
1024  SelfType temp(*this);
1025  --*this;
1026  return temp;
1027  }
1028 
1030  decrement();
1031  return *this;
1032  }
1033 
1035  increment();
1036  return *this;
1037  }
1038 
1044  reference operator*() const { return const_cast<reference>(deref()); }
1045  pointer operator->() const { return const_cast<pointer>(&deref()); }
1046 };
1047 
1050 struct MemberProxy {
1051  const String name;
1053 };
1054 
1059  const String name;
1060  const Value& value;
1061 };
1062 
1066 public:
1067  using iterator_category = std::forward_iterator_tag;
1069  using difference_type = int;
1072 
1073  ValueMembersIterator() = default;
1074  explicit ValueMembersIterator(ValueIterator const& iter) : it_(iter) {}
1075 
1077  ++it_;
1078  return *this;
1079  }
1081  ValueMembersIterator temp(*this);
1082  ++*this;
1083  return temp;
1084  }
1085  bool operator==(ValueMembersIterator const& other) const {
1086  return it_ == other.it_;
1087  }
1088  bool operator!=(ValueMembersIterator const& other) const {
1089  return it_ != other.it_;
1090  }
1091  MemberProxy operator*() const { return MemberProxy{it_.name(), *it_}; }
1092 
1093 private:
1094  ValueIterator it_;
1095 };
1096 
1100 public:
1101  using iterator_category = std::forward_iterator_tag;
1103  using difference_type = int;
1106 
1107  ValueConstMembersIterator() = default;
1109  : it_(iter) {}
1110 
1112  ++it_;
1113  return *this;
1114  }
1116  ValueConstMembersIterator temp(*this);
1117  ++*this;
1118  return temp;
1119  }
1120  bool operator==(ValueConstMembersIterator const& other) const {
1121  return it_ == other.it_;
1122  }
1123  bool operator!=(ValueConstMembersIterator const& other) const {
1124  return it_ != other.it_;
1125  }
1127  return ConstMemberProxy{it_.name(), *it_};
1128  }
1129 
1130 private:
1131  ValueConstIterator it_;
1132 };
1133 
1137 public:
1139  : begin_(begin), end_(end) {}
1142 
1143 private:
1144  ValueIterator begin_;
1145  ValueIterator end_;
1146 };
1147 
1151 public:
1153  : begin_(begin), end_(end) {}
1155  return ValueConstMembersIterator(begin_);
1156  }
1158  return ValueConstMembersIterator(end_);
1159  }
1160 
1161 private:
1162  ValueConstIterator begin_;
1163  ValueConstIterator end_;
1164 };
1165 
1167  return ValueMembersView(begin(), end());
1168 }
1170  return ValueConstMembersView(begin(), end());
1171 }
1172 
1173 inline void swap(Value& a, Value& b) { a.swap(b); }
1174 
1175 inline const Value& Value::front() const { return *begin(); }
1176 
1177 inline Value& Value::front() { return *begin(); }
1178 
1179 inline const Value& Value::back() const { return *(--end()); }
1180 
1181 inline Value& Value::back() { return *(--end()); }
1182 
1183 } // namespace Json
1184 
1185 #pragma pack(pop)
1186 
1187 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1188 #pragma warning(pop)
1189 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
1190 
1191 #endif // JSON_H_INCLUDED
Proxy struct to enable range-based for loops over const object members.
Definition: value.h:1058
Json::Int Int
Definition: value.h:216
Json::UInt64 UInt64
Definition: value.h:218
#define JSONCPP_DEPRECATED(message)
Definition: config.h:89
pointer operator->() const
Definition: value.h:1045
const Value & front() const
Returns a reference to the first element in the Value.
Definition: value.h:1175
Value & value
Definition: value.h:1052
bool operator==(ValueMembersIterator const &other) const
Definition: value.h:1085
#define JSON_API
If defined, indicates that the source file is amalgamated to prevent private header inclusion...
Definition: config.h:50
reference operator*() const
Definition: value.h:987
std::forward_iterator_tag iterator_category
Definition: value.h:1067
PrecisionType
Type of precision for formatting of real values.
Definition: value.h:142
base class for Value iterators.
Definition: value.h:869
bool operator==(ValueConstMembersIterator const &other) const
Definition: value.h:1120
array value (ordered list)
Definition: value.h:128
Json::Int64 Int64
Definition: value.h:219
#define JSONCPP_TEMPLATE_DELETE
Definition: value.h:38
ValueConstMembersIterator(ValueConstIterator const &iter)
Definition: value.h:1108
std::forward_iterator_tag iterator_category
Definition: value.h:1101
Json::LargestUInt LargestUInt
Definition: value.h:222
Proxy struct to enable range-based for loops over object members.
Definition: value.h:1050
Iterator adapter for range-based for loops.
Definition: value.h:1099
unsigned integer value
Definition: value.h:124
Json::UInt UInt
Definition: value.h:215
Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
Definition: value.h:108
void setComment(const char *comment, size_t len, CommentPlacement placement)
Comments must be //... or /* ... */.
Definition: value.h:668
object value (collection of name/value pairs).
Definition: value.h:129
Iterator adapter for range-based for loops.
Definition: value.h:1065
std::bidirectional_iterator_tag iterator_category
Definition: value.h:871
ValueMembersIterator begin() const
Definition: value.h:1140
ValueMembersView members()
Definition: value.h:1166
Lightweight wrapper to tag static string.
Definition: value.h:161
std::basic_string< char, std::char_traits< char >, Allocator< char >> String
Definition: config.h:135
ValueMembersIterator end() const
Definition: value.h:1141
difference_type computeDistance(const SelfType &other) const
ValueMembersView(ValueIterator begin, ValueIterator end)
Definition: value.h:1138
bool operator!=(const SelfType &other) const
Definition: value.h:878
const iterator for object and array value.
Definition: value.h:943
Value const * findValue(const String &key) const
Calls find and only returns a valid pointer if the type is found.
Definition: value.h:576
int Int
Definition: config.h:109
Int64 LargestInt
Definition: config.h:124
bool operator!=(ValueConstMembersIterator const &other) const
Definition: value.h:1123
MemberProxy operator*() const
Definition: value.h:1091
#define JSONCPP_NORETURN
Definition: value.h:18
Experimental and untested: represents an element of the "path" to access a node.
Definition: value.h:813
unsigned int ArrayIndex
Definition: forwards.h:32
SelfType & operator--()
Definition: value.h:977
ValueMembersIterator operator++(int)
Definition: value.h:1080
'null' value
Definition: value.h:122
CommentPlacement
Definition: value.h:132
SelfType & operator--()
Definition: value.h:1029
String name() const
Return the member name of the referenced Value, or "" if it is not an objectValue.
StaticString(const char *czstring)
Definition: value.h:163
bool operator!=(ValueMembersIterator const &other) const
Definition: value.h:1088
Range-based for loop adapter for object members.
Definition: value.h:1136
std::vector< String > Members
Definition: value.h:212
void swap(Value &a, Value &b)
Definition: value.h:1173
ValueConstMembersIterator operator++(int)
Definition: value.h:1115
Range-based for loop adapter for object members.
Definition: value.h:1150
ValueMembersIterator(ValueIterator const &iter)
Definition: value.h:1074
JSON (JavaScript Object Notation).
Definition: allocator.h:16
const String name
Definition: value.h:1059
bool operator==(const SecureAllocator< T > &, const SecureAllocator< U > &)
Definition: allocator.h:87
we set max number of digits after "." in string
Definition: value.h:144
void swap(Value &other)
Swap everything.
Definition: json_value.cpp:511
Experimental and untested: represents a "path" to access a node.
Definition: value.h:840
SelfType operator--(int)
Definition: value.h:971
const char * c_str() const
Definition: value.h:167
double value
Definition: value.h:125
SelfType operator--(int)
Definition: value.h:1023
const Value & value
Definition: value.h:1060
ValueMembersIterator & operator++()
Definition: value.h:1076
SelfType & operator++()
Definition: value.h:1034
Json::LargestInt LargestInt
Definition: value.h:221
unsigned int UInt
Definition: config.h:110
static const Value & nullRef
Definition: value.h:231
Represents a JSON value.
Definition: value.h:207
__int64 Int64
Definition: config.h:118
difference_type operator-(const SelfType &other) const
Definition: value.h:880
unsigned __int64 UInt64
Definition: config.h:119
reference operator*() const
Definition: value.h:1044
Exceptions which the user cannot easily avoid.
Definition: value.h:97
a comment on the line after a value (only make sense for
Definition: value.h:135
ValueConstMembersView(ValueConstIterator begin, ValueConstIterator end)
Definition: value.h:1152
we set max number of significant digits in string
Definition: value.h:143
Iterator for object and array value.
Definition: value.h:994
SelfType & operator++()
Definition: value.h:982
SelfType operator++(int)
Definition: value.h:965
ValueType
Type of the value held by a Value object.
Definition: value.h:121
bool value
Definition: value.h:127
UInt64 LargestUInt
Definition: config.h:125
ValueConstMembersIterator begin() const
Definition: value.h:1154
signed integer value
Definition: value.h:123
Json::ArrayIndex ArrayIndex
Definition: value.h:223
const String name
Definition: value.h:1051
String msg_
Definition: value.h:88
SelfType operator++(int)
Definition: value.h:1017
ConstMemberProxy operator*() const
Definition: value.h:1126
static const Value & null
Definition: value.h:230
a comment placed on the line before a value
Definition: value.h:133
UTF-8 string value.
Definition: value.h:126
a comment just after a value on the same line
Definition: value.h:134
std::string value_type
Definition: value.h:226
const_iterator begin() const
Base class for all exceptions we throw.
Definition: value.h:81
ValueConstMembersIterator & operator++()
Definition: value.h:1111
ValueConstMembersIterator end() const
Definition: value.h:1157
bool operator==(const SelfType &other) const
Definition: value.h:876
pointer operator->() const
Definition: value.h:989
const Value & back() const
Returns a reference to the last element in the Value.
Definition: value.h:1179
const_iterator end() const