blob: cf9703bc3eacc5e39f2f2d6d24f6b33ad6d8c672 [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 Dunn6d135cb2007-06-13 15:51:04 +000014
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100015#ifndef JSON_USE_CPPTL_SMALLMAP
16#include <map>
17#else
18#include <cpptl/smallmap.h>
19#endif
20#ifdef JSON_USE_CPPTL
21#include <cpptl/forwards.h>
22#endif
Christopher Dunn6d135cb2007-06-13 15:51:04 +000023
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100024// Disable warning C4251: <data member>: <type> needs to have dll-interface to
25// be used by...
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000026#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100027#pragma warning(push)
28#pragma warning(disable : 4251)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000029#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
30
Christopher Dunn6d135cb2007-06-13 15:51:04 +000031/** \brief JSON (JavaScript Object Notation).
32 */
33namespace Json {
34
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100035/** \brief Type of the value held by a Value object.
36 */
37enum ValueType {
38 nullValue = 0, ///< 'null' value
39 intValue, ///< signed integer value
40 uintValue, ///< unsigned integer value
41 realValue, ///< double value
42 stringValue, ///< UTF-8 string value
43 booleanValue, ///< bool value
44 arrayValue, ///< array value (ordered list)
45 objectValue ///< object value (collection of name/value pairs).
46};
Christopher Dunn6d135cb2007-06-13 15:51:04 +000047
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100048enum CommentPlacement {
49 commentBefore = 0, ///< a comment placed on the line before a value
50 commentAfterOnSameLine, ///< a comment just after a value on the same line
51 commentAfter, ///< a comment on the line after a value (only make sense for
Aaron Jacobs3a0c4fc2014-07-01 09:20:48 +100052 /// root value)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100053 numberOfCommentPlacement
54};
Christopher Dunn6d135cb2007-06-13 15:51:04 +000055
56//# ifdef JSON_USE_CPPTL
57// typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
58// typedef CppTL::AnyEnumerator<const Value &> EnumValues;
59//# endif
60
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100061/** \brief Lightweight wrapper to tag static string.
62 *
63 * Value constructor and objectValue member assignement takes advantage of the
64 * StaticString and avoid the cost of string duplication when storing the
65 * string or the member name.
66 *
67 * Example of usage:
68 * \code
69 * Json::Value aValue( StaticString("some text") );
70 * Json::Value object;
71 * static const StaticString code("code");
72 * object[code] = 1234;
73 * \endcode
74 */
75class JSON_API StaticString {
76public:
Aaron Jacobs11086dd2014-09-15 10:15:29 +100077 explicit StaticString(const char* czstring) : str_(czstring) {}
Christopher Dunn6d135cb2007-06-13 15:51:04 +000078
Aaron Jacobs11086dd2014-09-15 10:15:29 +100079 operator const char*() const { return str_; }
Christopher Dunn6d135cb2007-06-13 15:51:04 +000080
Aaron Jacobs11086dd2014-09-15 10:15:29 +100081 const char* c_str() const { return str_; }
Christopher Dunn6d135cb2007-06-13 15:51:04 +000082
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100083private:
Aaron Jacobs11086dd2014-09-15 10:15:29 +100084 const char* str_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100085};
Christopher Dunn6d135cb2007-06-13 15:51:04 +000086
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100087/** \brief Represents a <a HREF="http://www.json.org">JSON</a> value.
88 *
89 * This class is a discriminated union wrapper that can represents a:
90 * - signed integer [range: Value::minInt - Value::maxInt]
91 * - unsigned integer (range: 0 - Value::maxUInt)
92 * - double
93 * - UTF-8 string
94 * - boolean
95 * - 'null'
96 * - an ordered list of Value
97 * - collection of name/value pairs (javascript object)
98 *
99 * The type of the held value is represented by a #ValueType and
100 * can be obtained using type().
101 *
Christopher Dunnc28610f2015-02-21 11:44:16 -0600102 * Values of an #objectValue or #arrayValue can be accessed using operator[]()
103 * methods.
104 * Non-const methods will automatically create the a #nullValue element
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000105 * if it does not exist.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600106 * The sequence of an #arrayValue will be automatically resized and initialized
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000107 * with #nullValue. resize() can be used to enlarge or truncate an #arrayValue.
108 *
Christopher Dunnc28610f2015-02-21 11:44:16 -0600109 * The get() methods can be used to obtain default value in the case the
110 * required element does not exist.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000111 *
112 * It is possible to iterate over the list of a #objectValue values using
113 * the getMemberNames() method.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600114 *
Christopher Dunnc28610f2015-02-21 11:44:16 -0600115 * \note #Value string-length fit in size_t, but keys must be < 2^30.
116 * (The reason is an implementation detail.) A #CharReader will raise an
Christopher Dunn25342ba2015-03-02 18:05:26 -0600117 * exception if a bound is exceeded to avoid security holes in your app,
118 * but the Value API does *not* check bounds. That is the responsibility
119 * of the caller.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000120 */
121class JSON_API Value {
122 friend class ValueIteratorBase;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000123public:
124 typedef std::vector<std::string> Members;
125 typedef ValueIterator iterator;
126 typedef ValueConstIterator const_iterator;
127 typedef Json::UInt UInt;
128 typedef Json::Int Int;
129#if defined(JSON_HAS_INT64)
130 typedef Json::UInt64 UInt64;
131 typedef Json::Int64 Int64;
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +0000132#endif // defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000133 typedef Json::LargestInt LargestInt;
134 typedef Json::LargestUInt LargestUInt;
135 typedef Json::ArrayIndex ArrayIndex;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000136
Christopher Dunn8a702972015-03-03 10:38:27 -0600137 static const Value& null; ///< We regret this reference to a global instance; prefer the simpler Value().
138 static const Value& nullRef; ///< just a kludge for binary-compatibility; same as null
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000139 /// Minimum signed integer value that can be stored in a Json::Value.
140 static const LargestInt minLargestInt;
141 /// Maximum signed integer value that can be stored in a Json::Value.
142 static const LargestInt maxLargestInt;
143 /// Maximum unsigned integer value that can be stored in a Json::Value.
144 static const LargestUInt maxLargestUInt;
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +0000145
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000146 /// Minimum signed int value that can be stored in a Json::Value.
147 static const Int minInt;
148 /// Maximum signed int value that can be stored in a Json::Value.
149 static const Int maxInt;
150 /// Maximum unsigned int value that can be stored in a Json::Value.
151 static const UInt maxUInt;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000152
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000153#if defined(JSON_HAS_INT64)
154 /// Minimum signed 64 bits int value that can be stored in a Json::Value.
155 static const Int64 minInt64;
156 /// Maximum signed 64 bits int value that can be stored in a Json::Value.
157 static const Int64 maxInt64;
158 /// Maximum unsigned 64 bits int value that can be stored in a Json::Value.
159 static const UInt64 maxUInt64;
Aaron Jacobsf1053e72011-05-24 03:18:02 +0000160#endif // defined(JSON_HAS_INT64)
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +0000161
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000162private:
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000163#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000164 class CZString {
165 public:
166 enum DuplicationPolicy {
167 noDuplication = 0,
168 duplicate,
169 duplicateOnCopy
170 };
171 CZString(ArrayIndex index);
Christopher Dunnc28610f2015-02-21 11:44:16 -0600172 CZString(char const* str, unsigned length, DuplicationPolicy allocate);
173 CZString(CZString const& other);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000174 ~CZString();
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000175 CZString& operator=(CZString other);
Christopher Dunnc28610f2015-02-21 11:44:16 -0600176 bool operator<(CZString const& other) const;
177 bool operator==(CZString const& other) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000178 ArrayIndex index() const;
Christopher Dunnc28610f2015-02-21 11:44:16 -0600179 //const char* c_str() const; ///< \deprecated
180 char const* data() const;
181 unsigned length() const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000182 bool isStaticString() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000183
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000184 private:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000185 void swap(CZString& other);
Christopher Dunnc28610f2015-02-21 11:44:16 -0600186
Christopher Dunn57ad0512015-03-02 12:10:35 -0600187 struct StringStorage {
188 DuplicationPolicy policy_: 2;
189 unsigned length_: 30; // 1GB max
190 };
191
Christopher Dunnc28610f2015-02-21 11:44:16 -0600192 char const* cstr_; // actually, a prefixed string, unless policy is noDup
Christopher Dunn57ad0512015-03-02 12:10:35 -0600193 union {
194 ArrayIndex index_;
195 StringStorage storage_;
196 };
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000197 };
198
199public:
200#ifndef JSON_USE_CPPTL_SMALLMAP
201 typedef std::map<CZString, Value> ObjectValues;
202#else
203 typedef CppTL::SmallMap<CZString, Value> ObjectValues;
204#endif // ifndef JSON_USE_CPPTL_SMALLMAP
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000205#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
206
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000207public:
208 /** \brief Create a default Value of the given type.
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000209
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000210 This is a very useful constructor.
211 To create an empty array, pass arrayValue.
212 To create an empty object, pass objectValue.
213 Another Value can then be set to this one by assignment.
214This is useful since clear() and resize() will not alter types.
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000215
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000216 Examples:
217\code
218Json::Value null_value; // null
219Json::Value arr_value(Json::arrayValue); // []
220Json::Value obj_value(Json::objectValue); // {}
221\endcode
222 */
223 Value(ValueType type = nullValue);
224 Value(Int value);
225 Value(UInt value);
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +0000226#if defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000227 Value(Int64 value);
228 Value(UInt64 value);
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +0000229#endif // if defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000230 Value(double value);
Christopher Dunn8a702972015-03-03 10:38:27 -0600231 Value(const char* value); ///< Copy til first 0. (NULL causes to seg-fault.)
232 Value(const char* beginValue, const char* endValue); ///< Copy all, incl zeroes.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000233 /** \brief Constructs a value from a static string.
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000234
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000235 * Like other value string constructor but do not duplicate the string for
236 * internal storage. The given string must remain alive after the call to this
237 * constructor.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600238 * \note This works only for null-terminated strings. (We cannot change the
239 * size of this class, so we have nowhere to store the length,
240 * which might be computed later for various operations.)
241 *
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000242 * Example of usage:
243 * \code
Christopher Dunnc28610f2015-02-21 11:44:16 -0600244 * static StaticString foo("some text");
245 * Json::Value aValue(foo);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000246 * \endcode
247 */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000248 Value(const StaticString& value);
Christopher Dunn8a702972015-03-03 10:38:27 -0600249 Value(const std::string& value); ///< Copy data() til size(). Embedded zeroes too.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000250#ifdef JSON_USE_CPPTL
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000251 Value(const CppTL::ConstString& value);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000252#endif
253 Value(bool value);
Christopher Dunn66eb72f2015-01-20 11:02:22 -0600254 /// Deep copy.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000255 Value(const Value& other);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000256 ~Value();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000257
Christopher Dunn66eb72f2015-01-20 11:02:22 -0600258 // Deep copy, then swap(other).
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000259 Value& operator=(Value other);
Christopher Dunn66eb72f2015-01-20 11:02:22 -0600260 /// Swap everything.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000261 void swap(Value& other);
Christopher Dunn66eb72f2015-01-20 11:02:22 -0600262 /// Swap values but leave comments and source offsets in place.
263 void swapPayload(Value& other);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000264
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000265 ValueType type() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000266
Christopher Dunn66eb72f2015-01-20 11:02:22 -0600267 /// Compare payload only, not comments etc.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000268 bool operator<(const Value& other) const;
269 bool operator<=(const Value& other) const;
270 bool operator>=(const Value& other) const;
271 bool operator>(const Value& other) const;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000272 bool operator==(const Value& other) const;
273 bool operator!=(const Value& other) const;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000274 int compare(const Value& other) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000275
Christopher Dunn8a702972015-03-03 10:38:27 -0600276 const char* asCString() const; ///< Embedded zeroes could cause you trouble!
277 std::string asString() const; ///< Embedded zeroes are possible.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600278 /** Get raw char* of string-value.
279 * \return false if !string. (Seg-fault if str or end are NULL.)
280 */
281 bool getString(
282 char const** str, char const** end) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000283#ifdef JSON_USE_CPPTL
284 CppTL::ConstString asConstString() const;
285#endif
286 Int asInt() const;
287 UInt asUInt() const;
Aaron Jacobsf1053e72011-05-24 03:18:02 +0000288#if defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000289 Int64 asInt64() const;
290 UInt64 asUInt64() const;
Aaron Jacobsf1053e72011-05-24 03:18:02 +0000291#endif // if defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000292 LargestInt asLargestInt() const;
293 LargestUInt asLargestUInt() const;
294 float asFloat() const;
295 double asDouble() const;
296 bool asBool() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000297
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000298 bool isNull() const;
299 bool isBool() const;
300 bool isInt() const;
301 bool isInt64() const;
302 bool isUInt() const;
303 bool isUInt64() const;
304 bool isIntegral() const;
305 bool isDouble() const;
306 bool isNumeric() const;
307 bool isString() const;
308 bool isArray() const;
309 bool isObject() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000310
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000311 bool isConvertibleTo(ValueType other) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000312
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000313 /// Number of values in array or object
314 ArrayIndex size() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000315
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000316 /// \brief Return true if empty array, empty object, or null;
317 /// otherwise, false.
318 bool empty() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000319
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000320 /// Return isNull()
321 bool operator!() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000322
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000323 /// Remove all object members and array elements.
324 /// \pre type() is arrayValue, objectValue, or nullValue
325 /// \post type() is unchanged
326 void clear();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000327
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000328 /// Resize the array to size elements.
329 /// New elements are initialized to null.
330 /// May only be called on nullValue or arrayValue.
331 /// \pre type() is arrayValue or nullValue
332 /// \post type() is arrayValue
333 void resize(ArrayIndex size);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000334
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000335 /// Access an array element (zero based index ).
336 /// If the array contains less than index element, then null value are
337 /// inserted
338 /// in the array so that its size is index+1.
339 /// (You may need to say 'value[0u]' to get your compiler to distinguish
340 /// this from the operator[] which takes a string.)
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000341 Value& operator[](ArrayIndex index);
Baptiste Lepilleurfa130ef2010-12-24 12:47:14 +0000342
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000343 /// Access an array element (zero based index ).
344 /// If the array contains less than index element, then null value are
345 /// inserted
346 /// in the array so that its size is index+1.
347 /// (You may need to say 'value[0u]' to get your compiler to distinguish
348 /// this from the operator[] which takes a string.)
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000349 Value& operator[](int index);
Baptiste Lepilleurfa130ef2010-12-24 12:47:14 +0000350
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000351 /// Access an array element (zero based index )
352 /// (You may need to say 'value[0u]' to get your compiler to distinguish
353 /// this from the operator[] which takes a string.)
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000354 const Value& operator[](ArrayIndex index) const;
Baptiste Lepilleurfa130ef2010-12-24 12:47:14 +0000355
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000356 /// Access an array element (zero based index )
357 /// (You may need to say 'value[0u]' to get your compiler to distinguish
358 /// this from the operator[] which takes a string.)
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000359 const Value& operator[](int index) const;
Baptiste Lepilleurfa130ef2010-12-24 12:47:14 +0000360
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000361 /// If the array contains at least index+1 elements, returns the element
362 /// value,
363 /// otherwise returns defaultValue.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000364 Value get(ArrayIndex index, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000365 /// Return true if index < size().
366 bool isValidIndex(ArrayIndex index) const;
367 /// \brief Append value to array at the end.
368 ///
369 /// Equivalent to jsonvalue[jsonvalue.size()] = value;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000370 Value& append(const Value& value);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000371
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000372 /// Access an object value by name, create a null member if it does not exist.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600373 /// \note Because of our implementation, keys are limited to 2^30 -1 chars.
374 /// Exceeding that will cause an exception.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000375 Value& operator[](const char* key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000376 /// Access an object value by name, returns null if there is no member with
377 /// that name.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000378 const Value& operator[](const char* key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000379 /// Access an object value by name, create a null member if it does not exist.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600380 /// \param key may contain embedded nulls.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000381 Value& operator[](const std::string& key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000382 /// Access an object value by name, returns null if there is no member with
383 /// that name.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600384 /// \param key may contain embedded nulls.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000385 const Value& operator[](const std::string& key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000386 /** \brief Access an object value by name, create a null member if it does not
387 exist.
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000388
Christopher Dunn25342ba2015-03-02 18:05:26 -0600389 * If the object has no entry for that name, then the member name used to store
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000390 * the new entry is not duplicated.
391 * Example of use:
392 * \code
393 * Json::Value object;
394 * static const StaticString code("code");
395 * object[code] = 1234;
396 * \endcode
397 */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000398 Value& operator[](const StaticString& key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000399#ifdef JSON_USE_CPPTL
400 /// Access an object value by name, create a null member if it does not exist.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000401 Value& operator[](const CppTL::ConstString& key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000402 /// Access an object value by name, returns null if there is no member with
403 /// that name.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000404 const Value& operator[](const CppTL::ConstString& key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000405#endif
406 /// Return the member named key if it exist, defaultValue otherwise.
Christopher Dunn0fd28752015-03-05 16:38:43 -0600407 /// \note deep copy
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000408 Value get(const char* key, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000409 /// Return the member named key if it exist, defaultValue otherwise.
Christopher Dunn0fd28752015-03-05 16:38:43 -0600410 /// \note deep copy
Christopher Dunn25342ba2015-03-02 18:05:26 -0600411 /// \param key may contain embedded nulls.
412 Value get(const char* key, const char* end, const Value& defaultValue) const;
413 /// Return the member named key if it exist, defaultValue otherwise.
Christopher Dunn0fd28752015-03-05 16:38:43 -0600414 /// \note deep copy
Christopher Dunn25342ba2015-03-02 18:05:26 -0600415 /// \param key may contain embedded nulls.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000416 Value get(const std::string& key, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000417#ifdef JSON_USE_CPPTL
418 /// Return the member named key if it exist, defaultValue otherwise.
Christopher Dunn0fd28752015-03-05 16:38:43 -0600419 /// \note deep copy
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000420 Value get(const CppTL::ConstString& key, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000421#endif
Christopher Dunn25342ba2015-03-02 18:05:26 -0600422 /// Most general and efficient version of isMember()const, get()const,
423 /// and operator[]const
424 /// \note As stated elsewhere, behavior is undefined if (end-key) >= 2^30
425 Value const* find(char const* key, char const* end) const;
Christopher Dunnc28610f2015-02-21 11:44:16 -0600426 /// Most general and efficient version of object-mutators.
427 /// \note As stated elsewhere, behavior is undefined if (end-key) >= 2^30
428 /// \return non-zero, but JSON_ASSERT if this is neither object nor nullValue.
429 Value const* demand(char const* key, char const* end);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000430 /// \brief Remove and return the named member.
431 ///
432 /// Do nothing if it did not exist.
433 /// \return the removed Value, or null.
434 /// \pre type() is objectValue or nullValue
435 /// \post type() is unchanged
Christopher Dunn76746b02015-01-21 16:01:30 -0600436 /// \deprecated
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000437 Value removeMember(const char* key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000438 /// Same as removeMember(const char*)
Christopher Dunn25342ba2015-03-02 18:05:26 -0600439 /// \param key may contain embedded nulls.
Christopher Dunn76746b02015-01-21 16:01:30 -0600440 /// \deprecated
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000441 Value removeMember(const std::string& key);
Christopher Dunn25342ba2015-03-02 18:05:26 -0600442 /// Same as removeMember(const char* key, const char* end, Value* removed),
443 /// but 'key' is null-terminated.
444 bool removeMember(const char* key, Value* removed);
Christopher Dunn76746b02015-01-21 16:01:30 -0600445 /** \brief Remove the named map member.
446
447 Update 'removed' iff removed.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600448 \param key may contain embedded nulls.
Christopher Dunn76746b02015-01-21 16:01:30 -0600449 \return true iff removed (no exceptions)
450 */
Christopher Dunn25342ba2015-03-02 18:05:26 -0600451 bool removeMember(std::string const& key, Value* removed);
452 /// Same as removeMember(std::string const& key, Value* removed)
453 bool removeMember(const char* key, const char* end, Value* removed);
Christopher Dunn9de2c2d2015-01-20 16:15:40 -0600454 /** \brief Remove the indexed array element.
455
456 O(n) expensive operations.
457 Update 'removed' iff removed.
Christopher Dunne87e41c2015-01-20 16:24:11 -0600458 \return true iff removed (no exceptions)
Christopher Dunn9de2c2d2015-01-20 16:15:40 -0600459 */
460 bool removeIndex(ArrayIndex i, Value* removed);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000461
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000462 /// Return true if the object has a member named key.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600463 /// \note 'key' must be null-terminated.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000464 bool isMember(const char* key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000465 /// Return true if the object has a member named key.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600466 /// \param key may contain embedded nulls.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000467 bool isMember(const std::string& key) const;
Christopher Dunn25342ba2015-03-02 18:05:26 -0600468 /// Same as isMember(std::string const& key)const
469 bool isMember(const char* key, const char* end) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000470#ifdef JSON_USE_CPPTL
471 /// Return true if the object has a member named key.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000472 bool isMember(const CppTL::ConstString& key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000473#endif
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000474
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000475 /// \brief Return a list of the member names.
476 ///
477 /// If null, return an empty list.
478 /// \pre type() is objectValue or nullValue
479 /// \post if type() was nullValue, it remains nullValue
480 Members getMemberNames() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000481
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000482 //# ifdef JSON_USE_CPPTL
483 // EnumMemberNames enumMemberNames() const;
484 // EnumValues enumValues() const;
485 //# endif
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000486
Christopher Dunn1e3149a2015-01-25 14:16:13 -0600487 /// \deprecated Always pass len.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000488 void setComment(const char* comment, CommentPlacement placement);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000489 /// Comments must be //... or /* ... */
Christopher Dunn1e3149a2015-01-25 14:16:13 -0600490 void setComment(const char* comment, size_t len, CommentPlacement placement);
491 /// Comments must be //... or /* ... */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000492 void setComment(const std::string& comment, CommentPlacement placement);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000493 bool hasComment(CommentPlacement placement) const;
494 /// Include delimiters and embedded newlines.
495 std::string getComment(CommentPlacement placement) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000496
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000497 std::string toStyledString() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000498
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000499 const_iterator begin() const;
500 const_iterator end() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000501
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000502 iterator begin();
503 iterator end();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000504
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000505 // Accessors for the [start, limit) range of bytes within the JSON text from
506 // which this value was parsed, if any.
507 void setOffsetStart(size_t start);
508 void setOffsetLimit(size_t limit);
509 size_t getOffsetStart() const;
510 size_t getOffsetLimit() const;
Aaron Jacobs68db6552014-04-23 23:41:12 +0000511
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000512private:
Billy Donahue8eb5d892014-11-10 01:35:42 -0500513 void initBasic(ValueType type, bool allocated = false);
514
Christopher Dunnc28610f2015-02-21 11:44:16 -0600515 Value& resolveReference(const char* key);
516 Value& resolveReference(const char* key, const char* end);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000517
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000518 struct CommentInfo {
519 CommentInfo();
520 ~CommentInfo();
521
Christopher Dunn1e3149a2015-01-25 14:16:13 -0600522 void setComment(const char* text, size_t len);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000523
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000524 char* comment_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000525 };
526
527 // struct MemberNamesTransform
528 //{
529 // typedef const char *result_type;
530 // const char *operator()( const CZString &name ) const
531 // {
532 // return name.c_str();
533 // }
534 //};
535
536 union ValueHolder {
537 LargestInt int_;
538 LargestUInt uint_;
539 double real_;
540 bool bool_;
Christopher Dunnc28610f2015-02-21 11:44:16 -0600541 char* string_; // actually ptr to unsigned, followed by str, unless !allocated_
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000542 ObjectValues* map_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000543 } value_;
544 ValueType type_ : 8;
Christopher Dunn2bc61372015-01-24 13:42:37 -0600545 unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600546 // If not allocated_, string_ must be null-terminated.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000547 CommentInfo* comments_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000548
549 // [start, limit) byte offsets in the source JSON text from which this Value
550 // was extracted.
551 size_t start_;
552 size_t limit_;
553};
554
555/** \brief Experimental and untested: represents an element of the "path" to
556 * access a node.
557 */
558class JSON_API PathArgument {
559public:
560 friend class Path;
561
562 PathArgument();
563 PathArgument(ArrayIndex index);
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000564 PathArgument(const char* key);
565 PathArgument(const std::string& key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000566
567private:
568 enum Kind {
569 kindNone = 0,
570 kindIndex,
571 kindKey
572 };
573 std::string key_;
574 ArrayIndex index_;
575 Kind kind_;
576};
577
578/** \brief Experimental and untested: represents a "path" to access a node.
579 *
580 * Syntax:
581 * - "." => root node
582 * - ".[n]" => elements at index 'n' of root node (an array value)
583 * - ".name" => member named 'name' of root node (an object value)
584 * - ".name1.name2.name3"
585 * - ".[0][1][2].name1[3]"
586 * - ".%" => member name is provided as parameter
587 * - ".[%]" => index is provied as parameter
588 */
589class JSON_API Path {
590public:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000591 Path(const std::string& path,
592 const PathArgument& a1 = PathArgument(),
593 const PathArgument& a2 = PathArgument(),
594 const PathArgument& a3 = PathArgument(),
595 const PathArgument& a4 = PathArgument(),
596 const PathArgument& a5 = PathArgument());
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000597
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000598 const Value& resolve(const Value& root) const;
599 Value resolve(const Value& root, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000600 /// Creates the "path" to access the specified node and returns a reference on
601 /// the node.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000602 Value& make(Value& root) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000603
604private:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000605 typedef std::vector<const PathArgument*> InArgs;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000606 typedef std::vector<PathArgument> Args;
607
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000608 void makePath(const std::string& path, const InArgs& in);
609 void addPathInArg(const std::string& path,
610 const InArgs& in,
611 InArgs::const_iterator& itInArg,
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000612 PathArgument::Kind kind);
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000613 void invalidPath(const std::string& path, int location);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000614
615 Args args_;
616};
617
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000618/** \brief base class for Value iterators.
619 *
620 */
621class JSON_API ValueIteratorBase {
622public:
623 typedef std::bidirectional_iterator_tag iterator_category;
624 typedef unsigned int size_t;
625 typedef int difference_type;
626 typedef ValueIteratorBase SelfType;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000627
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000628 ValueIteratorBase();
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000629 explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000630
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000631 bool operator==(const SelfType& other) const { return isEqual(other); }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000632
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000633 bool operator!=(const SelfType& other) const { return !isEqual(other); }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000634
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000635 difference_type operator-(const SelfType& other) const {
Kevin Grant4c5832a2015-02-14 20:53:35 -0800636 return other.computeDistance(*this);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000637 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000638
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000639 /// Return either the index or the member name of the referenced value as a
640 /// Value.
641 Value key() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000642
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000643 /// Return the index of the referenced Value. -1 if it is not an arrayValue.
644 UInt index() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000645
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000646 /// Return the member name of the referenced Value. "" if it is not an
647 /// objectValue.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600648 /// \deprecated This cannot be used for UTF-8 strings, since there can be embedded nulls.
649 char const* memberName() const;
650 /// Return the member name of the referenced Value, or NULL if it is not an
651 /// objectValue.
652 /// Better version than memberName(). Allows embedded nulls.
653 char const* memberName(char const** end) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000654
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000655protected:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000656 Value& deref() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000657
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000658 void increment();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000659
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000660 void decrement();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000661
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000662 difference_type computeDistance(const SelfType& other) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000663
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000664 bool isEqual(const SelfType& other) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000665
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000666 void copy(const SelfType& other);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000667
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000668private:
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000669 Value::ObjectValues::iterator current_;
670 // Indicates that iterator is for a null value.
671 bool isNull_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000672};
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000673
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000674/** \brief const iterator for object and array value.
675 *
676 */
677class JSON_API ValueConstIterator : public ValueIteratorBase {
678 friend class Value;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000679
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000680public:
681 typedef const Value value_type;
Christopher Dunnc28610f2015-02-21 11:44:16 -0600682 //typedef unsigned int size_t;
683 //typedef int difference_type;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000684 typedef const Value& reference;
685 typedef const Value* pointer;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000686 typedef ValueConstIterator SelfType;
687
688 ValueConstIterator();
689
690private:
691/*! \internal Use by Value to create an iterator.
692 */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000693 explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000694public:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000695 SelfType& operator=(const ValueIteratorBase& other);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000696
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000697 SelfType operator++(int) {
698 SelfType temp(*this);
699 ++*this;
700 return temp;
701 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000702
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000703 SelfType operator--(int) {
704 SelfType temp(*this);
705 --*this;
706 return temp;
707 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000708
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000709 SelfType& operator--() {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000710 decrement();
711 return *this;
712 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000713
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000714 SelfType& operator++() {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000715 increment();
716 return *this;
717 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000718
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000719 reference operator*() const { return deref(); }
Braden McDorman540db3b2014-09-14 02:31:23 -0500720
721 pointer operator->() const { return &deref(); }
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000722};
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000723
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000724/** \brief Iterator for object and array value.
725 */
726class JSON_API ValueIterator : public ValueIteratorBase {
727 friend class Value;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000728
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000729public:
730 typedef Value value_type;
731 typedef unsigned int size_t;
732 typedef int difference_type;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000733 typedef Value& reference;
734 typedef Value* pointer;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000735 typedef ValueIterator SelfType;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000736
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000737 ValueIterator();
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000738 ValueIterator(const ValueConstIterator& other);
739 ValueIterator(const ValueIterator& other);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000740
741private:
742/*! \internal Use by Value to create an iterator.
743 */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000744 explicit ValueIterator(const Value::ObjectValues::iterator& current);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000745public:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000746 SelfType& operator=(const SelfType& other);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000747
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000748 SelfType operator++(int) {
749 SelfType temp(*this);
750 ++*this;
751 return temp;
752 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000753
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000754 SelfType operator--(int) {
755 SelfType temp(*this);
756 --*this;
757 return temp;
758 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000759
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000760 SelfType& operator--() {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000761 decrement();
762 return *this;
763 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000764
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000765 SelfType& operator++() {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000766 increment();
767 return *this;
768 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000769
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000770 reference operator*() const { return deref(); }
Braden McDorman540db3b2014-09-14 02:31:23 -0500771
772 pointer operator->() const { return &deref(); }
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000773};
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000774
775} // namespace Json
776
datadiode9454e682015-01-20 15:25:04 -0600777
778namespace std {
779/// Specialize std::swap() for Json::Value.
780template<>
781inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); }
782}
783
784
Baptiste Lepilleureafd7022013-05-08 20:21:11 +0000785#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000786#pragma warning(pop)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +0000787#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
788
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000789#endif // CPPTL_JSON_H_INCLUDED