blob: b590825cb3053bf9e1632348a9d30bf571cb489b [file] [log] [blame]
Baptiste Lepilleur7469f1d2010-04-20 21:35:19 +00001// Copyright 2007-2010 Baptiste Lepilleur
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
Christopher Dunn6d135cb2007-06-13 15:51:04 +00006#ifndef CPPTL_JSON_H_INCLUDED
Aaron Jacobs9fa4e842014-07-01 08:48:54 +10007#define CPPTL_JSON_H_INCLUDED
Christopher Dunn6d135cb2007-06-13 15:51:04 +00008
Baptiste Lepilleureadc4782011-05-02 21:09:30 +00009#if !defined(JSON_IS_AMALGAMATION)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100010#include "forwards.h"
Baptiste Lepilleureadc4782011-05-02 21:09:30 +000011#endif // if !defined(JSON_IS_AMALGAMATION)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100012#include <string>
13#include <vector>
Christopher Dunn75279cc2015-03-08 12:20:06 -050014#include <exception>
Christopher Dunn6d135cb2007-06-13 15:51:04 +000015
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100016#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
Christopher Dunn6d135cb2007-06-13 15:51:04 +000024
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100025// Disable warning C4251: <data member>: <type> needs to have dll-interface to
26// be used by...
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000027#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100028#pragma warning(push)
29#pragma warning(disable : 4251)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000030#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
31
Christopher Dunn6d135cb2007-06-13 15:51:04 +000032/** \brief JSON (JavaScript Object Notation).
33 */
34namespace Json {
35
Christopher Dunn75279cc2015-03-08 12:20:06 -050036/** Base class for all exceptions we throw.
37 */
Christopher Dunn53837942015-03-08 12:31:00 -050038class JSON_API Exception;
39/** Exceptions which the user cannot easily avoid.
40 *
41 * E.g. out-of-memory, stack-overflow, malicious input
42 */
43class JSON_API RuntimeError;
44/** Exceptions throw by JSON_ASSERT/JSON_FAIL macros.
45 *
46 * These are precondition-violations (user bugs) and internal errors (our bugs).
47 */
48class JSON_API LogicError;
49
50JSON_API void throwRuntimeError(std::string const& msg);
51JSON_API void throwLogicError(std::string const& msg);
Christopher Dunn75279cc2015-03-08 12:20:06 -050052
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100053/** \brief Type of the value held by a Value object.
54 */
55enum ValueType {
56 nullValue = 0, ///< 'null' value
57 intValue, ///< signed integer value
58 uintValue, ///< unsigned integer value
59 realValue, ///< double value
60 stringValue, ///< UTF-8 string value
61 booleanValue, ///< bool value
62 arrayValue, ///< array value (ordered list)
63 objectValue ///< object value (collection of name/value pairs).
64};
Christopher Dunn6d135cb2007-06-13 15:51:04 +000065
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100066enum CommentPlacement {
67 commentBefore = 0, ///< a comment placed on the line before a value
68 commentAfterOnSameLine, ///< a comment just after a value on the same line
69 commentAfter, ///< a comment on the line after a value (only make sense for
Aaron Jacobs3a0c4fc2014-07-01 09:20:48 +100070 /// root value)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100071 numberOfCommentPlacement
72};
Christopher Dunn6d135cb2007-06-13 15:51:04 +000073
74//# ifdef JSON_USE_CPPTL
75// typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
76// typedef CppTL::AnyEnumerator<const Value &> EnumValues;
77//# endif
78
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100079/** \brief Lightweight wrapper to tag static string.
80 *
81 * Value constructor and objectValue member assignement takes advantage of the
82 * StaticString and avoid the cost of string duplication when storing the
83 * string or the member name.
84 *
85 * Example of usage:
86 * \code
87 * Json::Value aValue( StaticString("some text") );
88 * Json::Value object;
89 * static const StaticString code("code");
90 * object[code] = 1234;
91 * \endcode
92 */
93class JSON_API StaticString {
94public:
Christopher Dunnff617522015-03-06 10:31:46 -060095 explicit StaticString(const char* czstring) : c_str_(czstring) {}
Christopher Dunn6d135cb2007-06-13 15:51:04 +000096
Christopher Dunnff617522015-03-06 10:31:46 -060097 operator const char*() const { return c_str_; }
Christopher Dunn6d135cb2007-06-13 15:51:04 +000098
Christopher Dunnff617522015-03-06 10:31:46 -060099 const char* c_str() const { return c_str_; }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000100
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000101private:
Christopher Dunnff617522015-03-06 10:31:46 -0600102 const char* c_str_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000103};
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000104
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000105/** \brief Represents a <a HREF="http://www.json.org">JSON</a> value.
106 *
107 * This class is a discriminated union wrapper that can represents a:
108 * - signed integer [range: Value::minInt - Value::maxInt]
109 * - unsigned integer (range: 0 - Value::maxUInt)
110 * - double
111 * - UTF-8 string
112 * - boolean
113 * - 'null'
114 * - an ordered list of Value
115 * - collection of name/value pairs (javascript object)
116 *
117 * The type of the held value is represented by a #ValueType and
118 * can be obtained using type().
119 *
Christopher Dunnc28610f2015-02-21 11:44:16 -0600120 * Values of an #objectValue or #arrayValue can be accessed using operator[]()
121 * methods.
122 * Non-const methods will automatically create the a #nullValue element
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000123 * if it does not exist.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600124 * The sequence of an #arrayValue will be automatically resized and initialized
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000125 * with #nullValue. resize() can be used to enlarge or truncate an #arrayValue.
126 *
Christopher Dunnc28610f2015-02-21 11:44:16 -0600127 * The get() methods can be used to obtain default value in the case the
128 * required element does not exist.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000129 *
130 * It is possible to iterate over the list of a #objectValue values using
131 * the getMemberNames() method.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600132 *
Christopher Dunnc28610f2015-02-21 11:44:16 -0600133 * \note #Value string-length fit in size_t, but keys must be < 2^30.
134 * (The reason is an implementation detail.) A #CharReader will raise an
Christopher Dunn25342ba2015-03-02 18:05:26 -0600135 * exception if a bound is exceeded to avoid security holes in your app,
136 * but the Value API does *not* check bounds. That is the responsibility
137 * of the caller.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000138 */
139class JSON_API Value {
140 friend class ValueIteratorBase;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000141public:
142 typedef std::vector<std::string> Members;
143 typedef ValueIterator iterator;
144 typedef ValueConstIterator const_iterator;
145 typedef Json::UInt UInt;
146 typedef Json::Int Int;
147#if defined(JSON_HAS_INT64)
148 typedef Json::UInt64 UInt64;
149 typedef Json::Int64 Int64;
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +0000150#endif // defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000151 typedef Json::LargestInt LargestInt;
152 typedef Json::LargestUInt LargestUInt;
153 typedef Json::ArrayIndex ArrayIndex;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000154
Christopher Dunn8a702972015-03-03 10:38:27 -0600155 static const Value& null; ///< We regret this reference to a global instance; prefer the simpler Value().
156 static const Value& nullRef; ///< just a kludge for binary-compatibility; same as null
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000157 /// Minimum signed integer value that can be stored in a Json::Value.
158 static const LargestInt minLargestInt;
159 /// Maximum signed integer value that can be stored in a Json::Value.
160 static const LargestInt maxLargestInt;
161 /// Maximum unsigned integer value that can be stored in a Json::Value.
162 static const LargestUInt maxLargestUInt;
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +0000163
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000164 /// Minimum signed int value that can be stored in a Json::Value.
165 static const Int minInt;
166 /// Maximum signed int value that can be stored in a Json::Value.
167 static const Int maxInt;
168 /// Maximum unsigned int value that can be stored in a Json::Value.
169 static const UInt maxUInt;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000170
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000171#if defined(JSON_HAS_INT64)
172 /// Minimum signed 64 bits int value that can be stored in a Json::Value.
173 static const Int64 minInt64;
174 /// Maximum signed 64 bits int value that can be stored in a Json::Value.
175 static const Int64 maxInt64;
176 /// Maximum unsigned 64 bits int value that can be stored in a Json::Value.
177 static const UInt64 maxUInt64;
Aaron Jacobsf1053e72011-05-24 03:18:02 +0000178#endif // defined(JSON_HAS_INT64)
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +0000179
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000180private:
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000181#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000182 class CZString {
183 public:
184 enum DuplicationPolicy {
185 noDuplication = 0,
186 duplicate,
187 duplicateOnCopy
188 };
189 CZString(ArrayIndex index);
Christopher Dunnc28610f2015-02-21 11:44:16 -0600190 CZString(char const* str, unsigned length, DuplicationPolicy allocate);
191 CZString(CZString const& other);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000192 ~CZString();
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000193 CZString& operator=(CZString other);
Christopher Dunnc28610f2015-02-21 11:44:16 -0600194 bool operator<(CZString const& other) const;
195 bool operator==(CZString const& other) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000196 ArrayIndex index() const;
Christopher Dunnc28610f2015-02-21 11:44:16 -0600197 //const char* c_str() const; ///< \deprecated
198 char const* data() const;
199 unsigned length() const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000200 bool isStaticString() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000201
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000202 private:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000203 void swap(CZString& other);
Christopher Dunnc28610f2015-02-21 11:44:16 -0600204
Christopher Dunn57ad0512015-03-02 12:10:35 -0600205 struct StringStorage {
206 DuplicationPolicy policy_: 2;
207 unsigned length_: 30; // 1GB max
208 };
209
Christopher Dunnc28610f2015-02-21 11:44:16 -0600210 char const* cstr_; // actually, a prefixed string, unless policy is noDup
Christopher Dunn57ad0512015-03-02 12:10:35 -0600211 union {
212 ArrayIndex index_;
213 StringStorage storage_;
214 };
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000215 };
216
217public:
218#ifndef JSON_USE_CPPTL_SMALLMAP
219 typedef std::map<CZString, Value> ObjectValues;
220#else
221 typedef CppTL::SmallMap<CZString, Value> ObjectValues;
222#endif // ifndef JSON_USE_CPPTL_SMALLMAP
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000223#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
224
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000225public:
226 /** \brief Create a default Value of the given type.
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000227
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000228 This is a very useful constructor.
229 To create an empty array, pass arrayValue.
230 To create an empty object, pass objectValue.
231 Another Value can then be set to this one by assignment.
232This is useful since clear() and resize() will not alter types.
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000233
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000234 Examples:
235\code
236Json::Value null_value; // null
237Json::Value arr_value(Json::arrayValue); // []
238Json::Value obj_value(Json::objectValue); // {}
239\endcode
240 */
241 Value(ValueType type = nullValue);
242 Value(Int value);
243 Value(UInt value);
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +0000244#if defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000245 Value(Int64 value);
246 Value(UInt64 value);
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +0000247#endif // if defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000248 Value(double value);
Christopher Dunn8a702972015-03-03 10:38:27 -0600249 Value(const char* value); ///< Copy til first 0. (NULL causes to seg-fault.)
250 Value(const char* beginValue, const char* endValue); ///< Copy all, incl zeroes.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000251 /** \brief Constructs a value from a static string.
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000252
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000253 * Like other value string constructor but do not duplicate the string for
254 * internal storage. The given string must remain alive after the call to this
255 * constructor.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600256 * \note This works only for null-terminated strings. (We cannot change the
257 * size of this class, so we have nowhere to store the length,
258 * which might be computed later for various operations.)
259 *
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000260 * Example of usage:
261 * \code
Christopher Dunnc28610f2015-02-21 11:44:16 -0600262 * static StaticString foo("some text");
263 * Json::Value aValue(foo);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000264 * \endcode
265 */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000266 Value(const StaticString& value);
Christopher Dunn8a702972015-03-03 10:38:27 -0600267 Value(const std::string& value); ///< Copy data() til size(). Embedded zeroes too.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000268#ifdef JSON_USE_CPPTL
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000269 Value(const CppTL::ConstString& value);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000270#endif
271 Value(bool value);
Christopher Dunn66eb72f2015-01-20 11:02:22 -0600272 /// Deep copy.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000273 Value(const Value& other);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000274 ~Value();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000275
Christopher Dunn7f439f42015-03-06 09:22:57 -0600276 /// Deep copy, then swap(other).
277 /// \note Over-write existing comments. To preserve comments, use #swapPayload().
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000278 Value& operator=(Value other);
Christopher Dunn66eb72f2015-01-20 11:02:22 -0600279 /// Swap everything.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000280 void swap(Value& other);
Christopher Dunn66eb72f2015-01-20 11:02:22 -0600281 /// Swap values but leave comments and source offsets in place.
282 void swapPayload(Value& other);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000283
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000284 ValueType type() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000285
Christopher Dunn66eb72f2015-01-20 11:02:22 -0600286 /// Compare payload only, not comments etc.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000287 bool operator<(const Value& other) const;
288 bool operator<=(const Value& other) const;
289 bool operator>=(const Value& other) const;
290 bool operator>(const Value& other) const;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000291 bool operator==(const Value& other) const;
292 bool operator!=(const Value& other) const;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000293 int compare(const Value& other) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000294
Christopher Dunn8a702972015-03-03 10:38:27 -0600295 const char* asCString() const; ///< Embedded zeroes could cause you trouble!
296 std::string asString() const; ///< Embedded zeroes are possible.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600297 /** Get raw char* of string-value.
298 * \return false if !string. (Seg-fault if str or end are NULL.)
299 */
300 bool getString(
301 char const** str, char const** end) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000302#ifdef JSON_USE_CPPTL
303 CppTL::ConstString asConstString() const;
304#endif
305 Int asInt() const;
306 UInt asUInt() const;
Aaron Jacobsf1053e72011-05-24 03:18:02 +0000307#if defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000308 Int64 asInt64() const;
309 UInt64 asUInt64() const;
Aaron Jacobsf1053e72011-05-24 03:18:02 +0000310#endif // if defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000311 LargestInt asLargestInt() const;
312 LargestUInt asLargestUInt() const;
313 float asFloat() const;
314 double asDouble() const;
315 bool asBool() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000316
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000317 bool isNull() const;
318 bool isBool() const;
319 bool isInt() const;
320 bool isInt64() const;
321 bool isUInt() const;
322 bool isUInt64() const;
323 bool isIntegral() const;
324 bool isDouble() const;
325 bool isNumeric() const;
326 bool isString() const;
327 bool isArray() const;
328 bool isObject() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000329
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000330 bool isConvertibleTo(ValueType other) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000331
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000332 /// Number of values in array or object
333 ArrayIndex size() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000334
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000335 /// \brief Return true if empty array, empty object, or null;
336 /// otherwise, false.
337 bool empty() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000338
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000339 /// Return isNull()
340 bool operator!() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000341
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000342 /// Remove all object members and array elements.
343 /// \pre type() is arrayValue, objectValue, or nullValue
344 /// \post type() is unchanged
345 void clear();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000346
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000347 /// Resize the array to size elements.
348 /// New elements are initialized to null.
349 /// May only be called on nullValue or arrayValue.
350 /// \pre type() is arrayValue or nullValue
351 /// \post type() is arrayValue
352 void resize(ArrayIndex size);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000353
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000354 /// Access an array element (zero based index ).
355 /// If the array contains less than index element, then null value are
356 /// inserted
357 /// in the array so that its size is index+1.
358 /// (You may need to say 'value[0u]' to get your compiler to distinguish
359 /// this from the operator[] which takes a string.)
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000360 Value& operator[](ArrayIndex index);
Baptiste Lepilleurfa130ef2010-12-24 12:47:14 +0000361
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000362 /// Access an array element (zero based index ).
363 /// If the array contains less than index element, then null value are
364 /// inserted
365 /// in the array so that its size is index+1.
366 /// (You may need to say 'value[0u]' to get your compiler to distinguish
367 /// this from the operator[] which takes a string.)
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000368 Value& operator[](int index);
Baptiste Lepilleurfa130ef2010-12-24 12:47:14 +0000369
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000370 /// Access an array element (zero based index )
371 /// (You may need to say 'value[0u]' to get your compiler to distinguish
372 /// this from the operator[] which takes a string.)
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000373 const Value& operator[](ArrayIndex index) const;
Baptiste Lepilleurfa130ef2010-12-24 12:47:14 +0000374
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000375 /// Access an array element (zero based index )
376 /// (You may need to say 'value[0u]' to get your compiler to distinguish
377 /// this from the operator[] which takes a string.)
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000378 const Value& operator[](int index) const;
Baptiste Lepilleurfa130ef2010-12-24 12:47:14 +0000379
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000380 /// If the array contains at least index+1 elements, returns the element
381 /// value,
382 /// otherwise returns defaultValue.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000383 Value get(ArrayIndex index, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000384 /// Return true if index < size().
385 bool isValidIndex(ArrayIndex index) const;
386 /// \brief Append value to array at the end.
387 ///
388 /// Equivalent to jsonvalue[jsonvalue.size()] = value;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000389 Value& append(const Value& value);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000390
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000391 /// Access an object value by name, create a null member if it does not exist.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600392 /// \note Because of our implementation, keys are limited to 2^30 -1 chars.
393 /// Exceeding that will cause an exception.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000394 Value& operator[](const char* key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000395 /// Access an object value by name, returns null if there is no member with
396 /// that name.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000397 const Value& operator[](const char* key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000398 /// Access an object value by name, create a null member if it does not exist.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600399 /// \param key may contain embedded nulls.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000400 Value& operator[](const std::string& key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000401 /// Access an object value by name, returns null if there is no member with
402 /// that name.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600403 /// \param key may contain embedded nulls.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000404 const Value& operator[](const std::string& key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000405 /** \brief Access an object value by name, create a null member if it does not
406 exist.
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000407
Christopher Dunn25342ba2015-03-02 18:05:26 -0600408 * If the object has no entry for that name, then the member name used to store
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000409 * the new entry is not duplicated.
410 * Example of use:
411 * \code
412 * Json::Value object;
413 * static const StaticString code("code");
414 * object[code] = 1234;
415 * \endcode
416 */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000417 Value& operator[](const StaticString& key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000418#ifdef JSON_USE_CPPTL
419 /// Access an object value by name, create a null member if it does not exist.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000420 Value& operator[](const CppTL::ConstString& key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000421 /// Access an object value by name, returns null if there is no member with
422 /// that name.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000423 const Value& operator[](const CppTL::ConstString& key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000424#endif
425 /// Return the member named key if it exist, defaultValue otherwise.
Christopher Dunn0fd28752015-03-05 16:38:43 -0600426 /// \note deep copy
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000427 Value get(const char* key, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000428 /// Return the member named key if it exist, defaultValue otherwise.
Christopher Dunn0fd28752015-03-05 16:38:43 -0600429 /// \note deep copy
Christopher Dunn25342ba2015-03-02 18:05:26 -0600430 /// \param key may contain embedded nulls.
431 Value get(const char* key, const char* end, const Value& defaultValue) const;
432 /// Return the member named key if it exist, defaultValue otherwise.
Christopher Dunn0fd28752015-03-05 16:38:43 -0600433 /// \note deep copy
Christopher Dunn25342ba2015-03-02 18:05:26 -0600434 /// \param key may contain embedded nulls.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000435 Value get(const std::string& key, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000436#ifdef JSON_USE_CPPTL
437 /// Return the member named key if it exist, defaultValue otherwise.
Christopher Dunn0fd28752015-03-05 16:38:43 -0600438 /// \note deep copy
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000439 Value get(const CppTL::ConstString& key, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000440#endif
Christopher Dunn25342ba2015-03-02 18:05:26 -0600441 /// Most general and efficient version of isMember()const, get()const,
442 /// and operator[]const
443 /// \note As stated elsewhere, behavior is undefined if (end-key) >= 2^30
444 Value const* find(char const* key, char const* end) const;
Christopher Dunnc28610f2015-02-21 11:44:16 -0600445 /// Most general and efficient version of object-mutators.
446 /// \note As stated elsewhere, behavior is undefined if (end-key) >= 2^30
447 /// \return non-zero, but JSON_ASSERT if this is neither object nor nullValue.
448 Value const* demand(char const* key, char const* end);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000449 /// \brief Remove and return the named member.
450 ///
451 /// Do nothing if it did not exist.
452 /// \return the removed Value, or null.
453 /// \pre type() is objectValue or nullValue
454 /// \post type() is unchanged
Christopher Dunn76746b02015-01-21 16:01:30 -0600455 /// \deprecated
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000456 Value removeMember(const char* key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000457 /// Same as removeMember(const char*)
Christopher Dunn25342ba2015-03-02 18:05:26 -0600458 /// \param key may contain embedded nulls.
Christopher Dunn76746b02015-01-21 16:01:30 -0600459 /// \deprecated
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000460 Value removeMember(const std::string& key);
Christopher Dunn25342ba2015-03-02 18:05:26 -0600461 /// Same as removeMember(const char* key, const char* end, Value* removed),
462 /// but 'key' is null-terminated.
463 bool removeMember(const char* key, Value* removed);
Christopher Dunn76746b02015-01-21 16:01:30 -0600464 /** \brief Remove the named map member.
465
466 Update 'removed' iff removed.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600467 \param key may contain embedded nulls.
Christopher Dunn76746b02015-01-21 16:01:30 -0600468 \return true iff removed (no exceptions)
469 */
Christopher Dunn25342ba2015-03-02 18:05:26 -0600470 bool removeMember(std::string const& key, Value* removed);
471 /// Same as removeMember(std::string const& key, Value* removed)
472 bool removeMember(const char* key, const char* end, Value* removed);
Christopher Dunn9de2c2d2015-01-20 16:15:40 -0600473 /** \brief Remove the indexed array element.
474
475 O(n) expensive operations.
476 Update 'removed' iff removed.
Christopher Dunne87e41c2015-01-20 16:24:11 -0600477 \return true iff removed (no exceptions)
Christopher Dunn9de2c2d2015-01-20 16:15:40 -0600478 */
479 bool removeIndex(ArrayIndex i, Value* removed);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000480
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000481 /// Return true if the object has a member named key.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600482 /// \note 'key' must be null-terminated.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000483 bool isMember(const char* key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000484 /// Return true if the object has a member named key.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600485 /// \param key may contain embedded nulls.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000486 bool isMember(const std::string& key) const;
Christopher Dunn25342ba2015-03-02 18:05:26 -0600487 /// Same as isMember(std::string const& key)const
488 bool isMember(const char* key, const char* end) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000489#ifdef JSON_USE_CPPTL
490 /// Return true if the object has a member named key.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000491 bool isMember(const CppTL::ConstString& key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000492#endif
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000493
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000494 /// \brief Return a list of the member names.
495 ///
496 /// If null, return an empty list.
497 /// \pre type() is objectValue or nullValue
498 /// \post if type() was nullValue, it remains nullValue
499 Members getMemberNames() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000500
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000501 //# ifdef JSON_USE_CPPTL
502 // EnumMemberNames enumMemberNames() const;
503 // EnumValues enumValues() const;
504 //# endif
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000505
Christopher Dunn1e3149a2015-01-25 14:16:13 -0600506 /// \deprecated Always pass len.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000507 void setComment(const char* comment, CommentPlacement placement);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000508 /// Comments must be //... or /* ... */
Christopher Dunn1e3149a2015-01-25 14:16:13 -0600509 void setComment(const char* comment, size_t len, CommentPlacement placement);
510 /// Comments must be //... or /* ... */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000511 void setComment(const std::string& comment, CommentPlacement placement);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000512 bool hasComment(CommentPlacement placement) const;
513 /// Include delimiters and embedded newlines.
514 std::string getComment(CommentPlacement placement) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000515
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000516 std::string toStyledString() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000517
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000518 const_iterator begin() const;
519 const_iterator end() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000520
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000521 iterator begin();
522 iterator end();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000523
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000524 // Accessors for the [start, limit) range of bytes within the JSON text from
525 // which this value was parsed, if any.
526 void setOffsetStart(size_t start);
527 void setOffsetLimit(size_t limit);
528 size_t getOffsetStart() const;
529 size_t getOffsetLimit() const;
Aaron Jacobs68db6552014-04-23 23:41:12 +0000530
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000531private:
Billy Donahue8eb5d892014-11-10 01:35:42 -0500532 void initBasic(ValueType type, bool allocated = false);
533
Christopher Dunnc28610f2015-02-21 11:44:16 -0600534 Value& resolveReference(const char* key);
535 Value& resolveReference(const char* key, const char* end);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000536
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000537 struct CommentInfo {
538 CommentInfo();
539 ~CommentInfo();
540
Christopher Dunn1e3149a2015-01-25 14:16:13 -0600541 void setComment(const char* text, size_t len);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000542
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000543 char* comment_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000544 };
545
546 // struct MemberNamesTransform
547 //{
548 // typedef const char *result_type;
549 // const char *operator()( const CZString &name ) const
550 // {
551 // return name.c_str();
552 // }
553 //};
554
555 union ValueHolder {
556 LargestInt int_;
557 LargestUInt uint_;
558 double real_;
559 bool bool_;
Christopher Dunnc28610f2015-02-21 11:44:16 -0600560 char* string_; // actually ptr to unsigned, followed by str, unless !allocated_
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000561 ObjectValues* map_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000562 } value_;
563 ValueType type_ : 8;
Christopher Dunn2bc61372015-01-24 13:42:37 -0600564 unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600565 // If not allocated_, string_ must be null-terminated.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000566 CommentInfo* comments_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000567
568 // [start, limit) byte offsets in the source JSON text from which this Value
569 // was extracted.
570 size_t start_;
571 size_t limit_;
572};
573
574/** \brief Experimental and untested: represents an element of the "path" to
575 * access a node.
576 */
577class JSON_API PathArgument {
578public:
579 friend class Path;
580
581 PathArgument();
582 PathArgument(ArrayIndex index);
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000583 PathArgument(const char* key);
584 PathArgument(const std::string& key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000585
586private:
587 enum Kind {
588 kindNone = 0,
589 kindIndex,
590 kindKey
591 };
592 std::string key_;
593 ArrayIndex index_;
594 Kind kind_;
595};
596
597/** \brief Experimental and untested: represents a "path" to access a node.
598 *
599 * Syntax:
600 * - "." => root node
601 * - ".[n]" => elements at index 'n' of root node (an array value)
602 * - ".name" => member named 'name' of root node (an object value)
603 * - ".name1.name2.name3"
604 * - ".[0][1][2].name1[3]"
605 * - ".%" => member name is provided as parameter
606 * - ".[%]" => index is provied as parameter
607 */
608class JSON_API Path {
609public:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000610 Path(const std::string& path,
611 const PathArgument& a1 = PathArgument(),
612 const PathArgument& a2 = PathArgument(),
613 const PathArgument& a3 = PathArgument(),
614 const PathArgument& a4 = PathArgument(),
615 const PathArgument& a5 = PathArgument());
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000616
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000617 const Value& resolve(const Value& root) const;
618 Value resolve(const Value& root, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000619 /// Creates the "path" to access the specified node and returns a reference on
620 /// the node.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000621 Value& make(Value& root) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000622
623private:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000624 typedef std::vector<const PathArgument*> InArgs;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000625 typedef std::vector<PathArgument> Args;
626
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000627 void makePath(const std::string& path, const InArgs& in);
628 void addPathInArg(const std::string& path,
629 const InArgs& in,
630 InArgs::const_iterator& itInArg,
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000631 PathArgument::Kind kind);
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000632 void invalidPath(const std::string& path, int location);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000633
634 Args args_;
635};
636
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000637/** \brief base class for Value iterators.
638 *
639 */
640class JSON_API ValueIteratorBase {
641public:
642 typedef std::bidirectional_iterator_tag iterator_category;
643 typedef unsigned int size_t;
644 typedef int difference_type;
645 typedef ValueIteratorBase SelfType;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000646
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000647 ValueIteratorBase();
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000648 explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000649
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000650 bool operator==(const SelfType& other) const { return isEqual(other); }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000651
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000652 bool operator!=(const SelfType& other) const { return !isEqual(other); }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000653
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000654 difference_type operator-(const SelfType& other) const {
Kevin Grant4c5832a2015-02-14 20:53:35 -0800655 return other.computeDistance(*this);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000656 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000657
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000658 /// Return either the index or the member name of the referenced value as a
659 /// Value.
660 Value key() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000661
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000662 /// Return the index of the referenced Value. -1 if it is not an arrayValue.
663 UInt index() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000664
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000665 /// Return the member name of the referenced Value. "" if it is not an
666 /// objectValue.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600667 /// \deprecated This cannot be used for UTF-8 strings, since there can be embedded nulls.
668 char const* memberName() const;
669 /// Return the member name of the referenced Value, or NULL if it is not an
670 /// objectValue.
671 /// Better version than memberName(). Allows embedded nulls.
672 char const* memberName(char const** end) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000673
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000674protected:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000675 Value& deref() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000676
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000677 void increment();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000678
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000679 void decrement();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000680
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000681 difference_type computeDistance(const SelfType& other) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000682
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000683 bool isEqual(const SelfType& other) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000684
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000685 void copy(const SelfType& other);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000686
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000687private:
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000688 Value::ObjectValues::iterator current_;
689 // Indicates that iterator is for a null value.
690 bool isNull_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000691};
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000692
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000693/** \brief const iterator for object and array value.
694 *
695 */
696class JSON_API ValueConstIterator : public ValueIteratorBase {
697 friend class Value;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000698
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000699public:
700 typedef const Value value_type;
Christopher Dunnc28610f2015-02-21 11:44:16 -0600701 //typedef unsigned int size_t;
702 //typedef int difference_type;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000703 typedef const Value& reference;
704 typedef const Value* pointer;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000705 typedef ValueConstIterator SelfType;
706
707 ValueConstIterator();
708
709private:
710/*! \internal Use by Value to create an iterator.
711 */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000712 explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000713public:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000714 SelfType& operator=(const ValueIteratorBase& other);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000715
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000716 SelfType operator++(int) {
717 SelfType temp(*this);
718 ++*this;
719 return temp;
720 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000721
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000722 SelfType operator--(int) {
723 SelfType temp(*this);
724 --*this;
725 return temp;
726 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000727
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000728 SelfType& operator--() {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000729 decrement();
730 return *this;
731 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000732
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000733 SelfType& operator++() {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000734 increment();
735 return *this;
736 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000737
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000738 reference operator*() const { return deref(); }
Braden McDorman540db3b2014-09-14 02:31:23 -0500739
740 pointer operator->() const { return &deref(); }
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000741};
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000742
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000743/** \brief Iterator for object and array value.
744 */
745class JSON_API ValueIterator : public ValueIteratorBase {
746 friend class Value;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000747
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000748public:
749 typedef Value value_type;
750 typedef unsigned int size_t;
751 typedef int difference_type;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000752 typedef Value& reference;
753 typedef Value* pointer;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000754 typedef ValueIterator SelfType;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000755
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000756 ValueIterator();
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000757 ValueIterator(const ValueConstIterator& other);
758 ValueIterator(const ValueIterator& other);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000759
760private:
761/*! \internal Use by Value to create an iterator.
762 */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000763 explicit ValueIterator(const Value::ObjectValues::iterator& current);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000764public:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000765 SelfType& operator=(const SelfType& other);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000766
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000767 SelfType operator++(int) {
768 SelfType temp(*this);
769 ++*this;
770 return temp;
771 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000772
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000773 SelfType operator--(int) {
774 SelfType temp(*this);
775 --*this;
776 return temp;
777 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000778
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000779 SelfType& operator--() {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000780 decrement();
781 return *this;
782 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000783
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000784 SelfType& operator++() {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000785 increment();
786 return *this;
787 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000788
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000789 reference operator*() const { return deref(); }
Braden McDorman540db3b2014-09-14 02:31:23 -0500790
791 pointer operator->() const { return &deref(); }
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000792};
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000793
794} // namespace Json
795
datadiode9454e682015-01-20 15:25:04 -0600796
797namespace std {
798/// Specialize std::swap() for Json::Value.
799template<>
800inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); }
801}
802
803
Baptiste Lepilleureafd7022013-05-08 20:21:11 +0000804#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000805#pragma warning(pop)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +0000806#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
807
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000808#endif // CPPTL_JSON_H_INCLUDED