blob: a5bada90707f5cc802134bf442ce9d681a4d35d4 [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 Dunn7f439f42015-03-06 09:22:57 -0600258 /// Deep copy, then swap(other).
259 /// \note Over-write existing comments. To preserve comments, use #swapPayload().
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000260 Value& operator=(Value other);
Christopher Dunn66eb72f2015-01-20 11:02:22 -0600261 /// Swap everything.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000262 void swap(Value& other);
Christopher Dunn66eb72f2015-01-20 11:02:22 -0600263 /// Swap values but leave comments and source offsets in place.
264 void swapPayload(Value& other);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000265
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000266 ValueType type() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000267
Christopher Dunn66eb72f2015-01-20 11:02:22 -0600268 /// Compare payload only, not comments etc.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000269 bool operator<(const Value& other) const;
270 bool operator<=(const Value& other) const;
271 bool operator>=(const Value& other) const;
272 bool operator>(const Value& other) const;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000273 bool operator==(const Value& other) const;
274 bool operator!=(const Value& other) const;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000275 int compare(const Value& other) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000276
Christopher Dunn8a702972015-03-03 10:38:27 -0600277 const char* asCString() const; ///< Embedded zeroes could cause you trouble!
278 std::string asString() const; ///< Embedded zeroes are possible.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600279 /** Get raw char* of string-value.
280 * \return false if !string. (Seg-fault if str or end are NULL.)
281 */
282 bool getString(
283 char const** str, char const** end) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000284#ifdef JSON_USE_CPPTL
285 CppTL::ConstString asConstString() const;
286#endif
287 Int asInt() const;
288 UInt asUInt() const;
Aaron Jacobsf1053e72011-05-24 03:18:02 +0000289#if defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000290 Int64 asInt64() const;
291 UInt64 asUInt64() const;
Aaron Jacobsf1053e72011-05-24 03:18:02 +0000292#endif // if defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000293 LargestInt asLargestInt() const;
294 LargestUInt asLargestUInt() const;
295 float asFloat() const;
296 double asDouble() const;
297 bool asBool() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000298
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000299 bool isNull() const;
300 bool isBool() const;
301 bool isInt() const;
302 bool isInt64() const;
303 bool isUInt() const;
304 bool isUInt64() const;
305 bool isIntegral() const;
306 bool isDouble() const;
307 bool isNumeric() const;
308 bool isString() const;
309 bool isArray() const;
310 bool isObject() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000311
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000312 bool isConvertibleTo(ValueType other) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000313
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000314 /// Number of values in array or object
315 ArrayIndex size() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000316
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000317 /// \brief Return true if empty array, empty object, or null;
318 /// otherwise, false.
319 bool empty() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000320
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000321 /// Return isNull()
322 bool operator!() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000323
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000324 /// Remove all object members and array elements.
325 /// \pre type() is arrayValue, objectValue, or nullValue
326 /// \post type() is unchanged
327 void clear();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000328
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000329 /// Resize the array to size elements.
330 /// New elements are initialized to null.
331 /// May only be called on nullValue or arrayValue.
332 /// \pre type() is arrayValue or nullValue
333 /// \post type() is arrayValue
334 void resize(ArrayIndex size);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000335
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000336 /// Access an array element (zero based index ).
337 /// If the array contains less than index element, then null value are
338 /// inserted
339 /// in the array so that its size is index+1.
340 /// (You may need to say 'value[0u]' to get your compiler to distinguish
341 /// this from the operator[] which takes a string.)
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000342 Value& operator[](ArrayIndex index);
Baptiste Lepilleurfa130ef2010-12-24 12:47:14 +0000343
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000344 /// Access an array element (zero based index ).
345 /// If the array contains less than index element, then null value are
346 /// inserted
347 /// in the array so that its size is index+1.
348 /// (You may need to say 'value[0u]' to get your compiler to distinguish
349 /// this from the operator[] which takes a string.)
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000350 Value& operator[](int index);
Baptiste Lepilleurfa130ef2010-12-24 12:47:14 +0000351
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000352 /// Access an array element (zero based index )
353 /// (You may need to say 'value[0u]' to get your compiler to distinguish
354 /// this from the operator[] which takes a string.)
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000355 const Value& operator[](ArrayIndex index) const;
Baptiste Lepilleurfa130ef2010-12-24 12:47:14 +0000356
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000357 /// Access an array element (zero based index )
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 const Value& operator[](int index) const;
Baptiste Lepilleurfa130ef2010-12-24 12:47:14 +0000361
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000362 /// If the array contains at least index+1 elements, returns the element
363 /// value,
364 /// otherwise returns defaultValue.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000365 Value get(ArrayIndex index, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000366 /// Return true if index < size().
367 bool isValidIndex(ArrayIndex index) const;
368 /// \brief Append value to array at the end.
369 ///
370 /// Equivalent to jsonvalue[jsonvalue.size()] = value;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000371 Value& append(const Value& value);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000372
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000373 /// Access an object value by name, create a null member if it does not exist.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600374 /// \note Because of our implementation, keys are limited to 2^30 -1 chars.
375 /// Exceeding that will cause an exception.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000376 Value& operator[](const char* key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000377 /// Access an object value by name, returns null if there is no member with
378 /// that name.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000379 const Value& operator[](const char* key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000380 /// Access an object value by name, create a null member if it does not exist.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600381 /// \param key may contain embedded nulls.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000382 Value& operator[](const std::string& key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000383 /// Access an object value by name, returns null if there is no member with
384 /// that name.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600385 /// \param key may contain embedded nulls.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000386 const Value& operator[](const std::string& key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000387 /** \brief Access an object value by name, create a null member if it does not
388 exist.
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000389
Christopher Dunn25342ba2015-03-02 18:05:26 -0600390 * If the object has no entry for that name, then the member name used to store
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000391 * the new entry is not duplicated.
392 * Example of use:
393 * \code
394 * Json::Value object;
395 * static const StaticString code("code");
396 * object[code] = 1234;
397 * \endcode
398 */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000399 Value& operator[](const StaticString& key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000400#ifdef JSON_USE_CPPTL
401 /// Access an object value by name, create a null member if it does not exist.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000402 Value& operator[](const CppTL::ConstString& key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000403 /// Access an object value by name, returns null if there is no member with
404 /// that name.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000405 const Value& operator[](const CppTL::ConstString& key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000406#endif
407 /// Return the member named key if it exist, defaultValue otherwise.
Christopher Dunn0fd28752015-03-05 16:38:43 -0600408 /// \note deep copy
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000409 Value get(const char* key, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000410 /// Return the member named key if it exist, defaultValue otherwise.
Christopher Dunn0fd28752015-03-05 16:38:43 -0600411 /// \note deep copy
Christopher Dunn25342ba2015-03-02 18:05:26 -0600412 /// \param key may contain embedded nulls.
413 Value get(const char* key, const char* end, const Value& defaultValue) const;
414 /// Return the member named key if it exist, defaultValue otherwise.
Christopher Dunn0fd28752015-03-05 16:38:43 -0600415 /// \note deep copy
Christopher Dunn25342ba2015-03-02 18:05:26 -0600416 /// \param key may contain embedded nulls.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000417 Value get(const std::string& key, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000418#ifdef JSON_USE_CPPTL
419 /// Return the member named key if it exist, defaultValue otherwise.
Christopher Dunn0fd28752015-03-05 16:38:43 -0600420 /// \note deep copy
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000421 Value get(const CppTL::ConstString& key, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000422#endif
Christopher Dunn25342ba2015-03-02 18:05:26 -0600423 /// Most general and efficient version of isMember()const, get()const,
424 /// and operator[]const
425 /// \note As stated elsewhere, behavior is undefined if (end-key) >= 2^30
426 Value const* find(char const* key, char const* end) const;
Christopher Dunnc28610f2015-02-21 11:44:16 -0600427 /// Most general and efficient version of object-mutators.
428 /// \note As stated elsewhere, behavior is undefined if (end-key) >= 2^30
429 /// \return non-zero, but JSON_ASSERT if this is neither object nor nullValue.
430 Value const* demand(char const* key, char const* end);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000431 /// \brief Remove and return the named member.
432 ///
433 /// Do nothing if it did not exist.
434 /// \return the removed Value, or null.
435 /// \pre type() is objectValue or nullValue
436 /// \post type() is unchanged
Christopher Dunn76746b02015-01-21 16:01:30 -0600437 /// \deprecated
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000438 Value removeMember(const char* key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000439 /// Same as removeMember(const char*)
Christopher Dunn25342ba2015-03-02 18:05:26 -0600440 /// \param key may contain embedded nulls.
Christopher Dunn76746b02015-01-21 16:01:30 -0600441 /// \deprecated
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000442 Value removeMember(const std::string& key);
Christopher Dunn25342ba2015-03-02 18:05:26 -0600443 /// Same as removeMember(const char* key, const char* end, Value* removed),
444 /// but 'key' is null-terminated.
445 bool removeMember(const char* key, Value* removed);
Christopher Dunn76746b02015-01-21 16:01:30 -0600446 /** \brief Remove the named map member.
447
448 Update 'removed' iff removed.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600449 \param key may contain embedded nulls.
Christopher Dunn76746b02015-01-21 16:01:30 -0600450 \return true iff removed (no exceptions)
451 */
Christopher Dunn25342ba2015-03-02 18:05:26 -0600452 bool removeMember(std::string const& key, Value* removed);
453 /// Same as removeMember(std::string const& key, Value* removed)
454 bool removeMember(const char* key, const char* end, Value* removed);
Christopher Dunn9de2c2d2015-01-20 16:15:40 -0600455 /** \brief Remove the indexed array element.
456
457 O(n) expensive operations.
458 Update 'removed' iff removed.
Christopher Dunne87e41c2015-01-20 16:24:11 -0600459 \return true iff removed (no exceptions)
Christopher Dunn9de2c2d2015-01-20 16:15:40 -0600460 */
461 bool removeIndex(ArrayIndex i, Value* removed);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000462
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000463 /// Return true if the object has a member named key.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600464 /// \note 'key' must be null-terminated.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000465 bool isMember(const char* key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000466 /// Return true if the object has a member named key.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600467 /// \param key may contain embedded nulls.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000468 bool isMember(const std::string& key) const;
Christopher Dunn25342ba2015-03-02 18:05:26 -0600469 /// Same as isMember(std::string const& key)const
470 bool isMember(const char* key, const char* end) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000471#ifdef JSON_USE_CPPTL
472 /// Return true if the object has a member named key.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000473 bool isMember(const CppTL::ConstString& key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000474#endif
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000475
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000476 /// \brief Return a list of the member names.
477 ///
478 /// If null, return an empty list.
479 /// \pre type() is objectValue or nullValue
480 /// \post if type() was nullValue, it remains nullValue
481 Members getMemberNames() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000482
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000483 //# ifdef JSON_USE_CPPTL
484 // EnumMemberNames enumMemberNames() const;
485 // EnumValues enumValues() const;
486 //# endif
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000487
Christopher Dunn1e3149a2015-01-25 14:16:13 -0600488 /// \deprecated Always pass len.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000489 void setComment(const char* comment, CommentPlacement placement);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000490 /// Comments must be //... or /* ... */
Christopher Dunn1e3149a2015-01-25 14:16:13 -0600491 void setComment(const char* comment, size_t len, CommentPlacement placement);
492 /// Comments must be //... or /* ... */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000493 void setComment(const std::string& comment, CommentPlacement placement);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000494 bool hasComment(CommentPlacement placement) const;
495 /// Include delimiters and embedded newlines.
496 std::string getComment(CommentPlacement placement) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000497
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000498 std::string toStyledString() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000499
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000500 const_iterator begin() const;
501 const_iterator end() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000502
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000503 iterator begin();
504 iterator end();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000505
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000506 // Accessors for the [start, limit) range of bytes within the JSON text from
507 // which this value was parsed, if any.
508 void setOffsetStart(size_t start);
509 void setOffsetLimit(size_t limit);
510 size_t getOffsetStart() const;
511 size_t getOffsetLimit() const;
Aaron Jacobs68db6552014-04-23 23:41:12 +0000512
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000513private:
Billy Donahue8eb5d892014-11-10 01:35:42 -0500514 void initBasic(ValueType type, bool allocated = false);
515
Christopher Dunnc28610f2015-02-21 11:44:16 -0600516 Value& resolveReference(const char* key);
517 Value& resolveReference(const char* key, const char* end);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000518
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000519 struct CommentInfo {
520 CommentInfo();
521 ~CommentInfo();
522
Christopher Dunn1e3149a2015-01-25 14:16:13 -0600523 void setComment(const char* text, size_t len);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000524
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000525 char* comment_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000526 };
527
528 // struct MemberNamesTransform
529 //{
530 // typedef const char *result_type;
531 // const char *operator()( const CZString &name ) const
532 // {
533 // return name.c_str();
534 // }
535 //};
536
537 union ValueHolder {
538 LargestInt int_;
539 LargestUInt uint_;
540 double real_;
541 bool bool_;
Christopher Dunnc28610f2015-02-21 11:44:16 -0600542 char* string_; // actually ptr to unsigned, followed by str, unless !allocated_
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000543 ObjectValues* map_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000544 } value_;
545 ValueType type_ : 8;
Christopher Dunn2bc61372015-01-24 13:42:37 -0600546 unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600547 // If not allocated_, string_ must be null-terminated.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000548 CommentInfo* comments_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000549
550 // [start, limit) byte offsets in the source JSON text from which this Value
551 // was extracted.
552 size_t start_;
553 size_t limit_;
554};
555
556/** \brief Experimental and untested: represents an element of the "path" to
557 * access a node.
558 */
559class JSON_API PathArgument {
560public:
561 friend class Path;
562
563 PathArgument();
564 PathArgument(ArrayIndex index);
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000565 PathArgument(const char* key);
566 PathArgument(const std::string& key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000567
568private:
569 enum Kind {
570 kindNone = 0,
571 kindIndex,
572 kindKey
573 };
574 std::string key_;
575 ArrayIndex index_;
576 Kind kind_;
577};
578
579/** \brief Experimental and untested: represents a "path" to access a node.
580 *
581 * Syntax:
582 * - "." => root node
583 * - ".[n]" => elements at index 'n' of root node (an array value)
584 * - ".name" => member named 'name' of root node (an object value)
585 * - ".name1.name2.name3"
586 * - ".[0][1][2].name1[3]"
587 * - ".%" => member name is provided as parameter
588 * - ".[%]" => index is provied as parameter
589 */
590class JSON_API Path {
591public:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000592 Path(const std::string& path,
593 const PathArgument& a1 = PathArgument(),
594 const PathArgument& a2 = PathArgument(),
595 const PathArgument& a3 = PathArgument(),
596 const PathArgument& a4 = PathArgument(),
597 const PathArgument& a5 = PathArgument());
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000598
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000599 const Value& resolve(const Value& root) const;
600 Value resolve(const Value& root, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000601 /// Creates the "path" to access the specified node and returns a reference on
602 /// the node.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000603 Value& make(Value& root) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000604
605private:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000606 typedef std::vector<const PathArgument*> InArgs;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000607 typedef std::vector<PathArgument> Args;
608
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000609 void makePath(const std::string& path, const InArgs& in);
610 void addPathInArg(const std::string& path,
611 const InArgs& in,
612 InArgs::const_iterator& itInArg,
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000613 PathArgument::Kind kind);
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000614 void invalidPath(const std::string& path, int location);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000615
616 Args args_;
617};
618
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000619/** \brief base class for Value iterators.
620 *
621 */
622class JSON_API ValueIteratorBase {
623public:
624 typedef std::bidirectional_iterator_tag iterator_category;
625 typedef unsigned int size_t;
626 typedef int difference_type;
627 typedef ValueIteratorBase SelfType;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000628
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000629 ValueIteratorBase();
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000630 explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000631
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000632 bool operator==(const SelfType& other) const { return isEqual(other); }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000633
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000634 bool operator!=(const SelfType& other) const { return !isEqual(other); }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000635
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000636 difference_type operator-(const SelfType& other) const {
Kevin Grant4c5832a2015-02-14 20:53:35 -0800637 return other.computeDistance(*this);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000638 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000639
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000640 /// Return either the index or the member name of the referenced value as a
641 /// Value.
642 Value key() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000643
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000644 /// Return the index of the referenced Value. -1 if it is not an arrayValue.
645 UInt index() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000646
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000647 /// Return the member name of the referenced Value. "" if it is not an
648 /// objectValue.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600649 /// \deprecated This cannot be used for UTF-8 strings, since there can be embedded nulls.
650 char const* memberName() const;
651 /// Return the member name of the referenced Value, or NULL if it is not an
652 /// objectValue.
653 /// Better version than memberName(). Allows embedded nulls.
654 char const* memberName(char const** end) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000655
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000656protected:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000657 Value& deref() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000658
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000659 void increment();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000660
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000661 void decrement();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000662
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000663 difference_type computeDistance(const SelfType& other) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000664
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000665 bool isEqual(const SelfType& other) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000666
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000667 void copy(const SelfType& other);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000668
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000669private:
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000670 Value::ObjectValues::iterator current_;
671 // Indicates that iterator is for a null value.
672 bool isNull_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000673};
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000674
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000675/** \brief const iterator for object and array value.
676 *
677 */
678class JSON_API ValueConstIterator : public ValueIteratorBase {
679 friend class Value;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000680
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000681public:
682 typedef const Value value_type;
Christopher Dunnc28610f2015-02-21 11:44:16 -0600683 //typedef unsigned int size_t;
684 //typedef int difference_type;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000685 typedef const Value& reference;
686 typedef const Value* pointer;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000687 typedef ValueConstIterator SelfType;
688
689 ValueConstIterator();
690
691private:
692/*! \internal Use by Value to create an iterator.
693 */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000694 explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000695public:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000696 SelfType& operator=(const ValueIteratorBase& other);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000697
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000698 SelfType operator++(int) {
699 SelfType temp(*this);
700 ++*this;
701 return temp;
702 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000703
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000704 SelfType operator--(int) {
705 SelfType temp(*this);
706 --*this;
707 return temp;
708 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000709
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000710 SelfType& operator--() {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000711 decrement();
712 return *this;
713 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000714
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000715 SelfType& operator++() {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000716 increment();
717 return *this;
718 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000719
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000720 reference operator*() const { return deref(); }
Braden McDorman540db3b2014-09-14 02:31:23 -0500721
722 pointer operator->() const { return &deref(); }
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000723};
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000724
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000725/** \brief Iterator for object and array value.
726 */
727class JSON_API ValueIterator : public ValueIteratorBase {
728 friend class Value;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000729
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000730public:
731 typedef Value value_type;
732 typedef unsigned int size_t;
733 typedef int difference_type;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000734 typedef Value& reference;
735 typedef Value* pointer;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000736 typedef ValueIterator SelfType;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000737
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000738 ValueIterator();
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000739 ValueIterator(const ValueConstIterator& other);
740 ValueIterator(const ValueIterator& other);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000741
742private:
743/*! \internal Use by Value to create an iterator.
744 */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000745 explicit ValueIterator(const Value::ObjectValues::iterator& current);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000746public:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000747 SelfType& operator=(const SelfType& other);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000748
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000749 SelfType operator++(int) {
750 SelfType temp(*this);
751 ++*this;
752 return temp;
753 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000754
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000755 SelfType operator--(int) {
756 SelfType temp(*this);
757 --*this;
758 return temp;
759 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000760
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000761 SelfType& operator--() {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000762 decrement();
763 return *this;
764 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000765
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000766 SelfType& operator++() {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000767 increment();
768 return *this;
769 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000770
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000771 reference operator*() const { return deref(); }
Braden McDorman540db3b2014-09-14 02:31:23 -0500772
773 pointer operator->() const { return &deref(); }
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000774};
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000775
776} // namespace Json
777
datadiode9454e682015-01-20 15:25:04 -0600778
779namespace std {
780/// Specialize std::swap() for Json::Value.
781template<>
782inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); }
783}
784
785
Baptiste Lepilleureafd7022013-05-08 20:21:11 +0000786#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000787#pragma warning(pop)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +0000788#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
789
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000790#endif // CPPTL_JSON_H_INCLUDED