blob: 1cd62912cdecbf8c66525ad21d9ac10b3c10c443 [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 */
38class Exception : public std::exception {
39public:
40 Exception(std::string const& msg);
41 virtual ~Exception() throw();
42 virtual char const* what() const throw();
43protected:
44 std::string const& msg_;
45 void* future_use_;
46};
47
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100048/** \brief Type of the value held by a Value object.
49 */
50enum ValueType {
51 nullValue = 0, ///< 'null' value
52 intValue, ///< signed integer value
53 uintValue, ///< unsigned integer value
54 realValue, ///< double value
55 stringValue, ///< UTF-8 string value
56 booleanValue, ///< bool value
57 arrayValue, ///< array value (ordered list)
58 objectValue ///< object value (collection of name/value pairs).
59};
Christopher Dunn6d135cb2007-06-13 15:51:04 +000060
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100061enum CommentPlacement {
62 commentBefore = 0, ///< a comment placed on the line before a value
63 commentAfterOnSameLine, ///< a comment just after a value on the same line
64 commentAfter, ///< a comment on the line after a value (only make sense for
Aaron Jacobs3a0c4fc2014-07-01 09:20:48 +100065 /// root value)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100066 numberOfCommentPlacement
67};
Christopher Dunn6d135cb2007-06-13 15:51:04 +000068
69//# ifdef JSON_USE_CPPTL
70// typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
71// typedef CppTL::AnyEnumerator<const Value &> EnumValues;
72//# endif
73
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100074/** \brief Lightweight wrapper to tag static string.
75 *
76 * Value constructor and objectValue member assignement takes advantage of the
77 * StaticString and avoid the cost of string duplication when storing the
78 * string or the member name.
79 *
80 * Example of usage:
81 * \code
82 * Json::Value aValue( StaticString("some text") );
83 * Json::Value object;
84 * static const StaticString code("code");
85 * object[code] = 1234;
86 * \endcode
87 */
88class JSON_API StaticString {
89public:
Christopher Dunnff617522015-03-06 10:31:46 -060090 explicit StaticString(const char* czstring) : c_str_(czstring) {}
Christopher Dunn6d135cb2007-06-13 15:51:04 +000091
Christopher Dunnff617522015-03-06 10:31:46 -060092 operator const char*() const { return c_str_; }
Christopher Dunn6d135cb2007-06-13 15:51:04 +000093
Christopher Dunnff617522015-03-06 10:31:46 -060094 const char* c_str() const { return c_str_; }
Christopher Dunn6d135cb2007-06-13 15:51:04 +000095
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100096private:
Christopher Dunnff617522015-03-06 10:31:46 -060097 const char* c_str_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100098};
Christopher Dunn6d135cb2007-06-13 15:51:04 +000099
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000100/** \brief Represents a <a HREF="http://www.json.org">JSON</a> value.
101 *
102 * This class is a discriminated union wrapper that can represents a:
103 * - signed integer [range: Value::minInt - Value::maxInt]
104 * - unsigned integer (range: 0 - Value::maxUInt)
105 * - double
106 * - UTF-8 string
107 * - boolean
108 * - 'null'
109 * - an ordered list of Value
110 * - collection of name/value pairs (javascript object)
111 *
112 * The type of the held value is represented by a #ValueType and
113 * can be obtained using type().
114 *
Christopher Dunnc28610f2015-02-21 11:44:16 -0600115 * Values of an #objectValue or #arrayValue can be accessed using operator[]()
116 * methods.
117 * Non-const methods will automatically create the a #nullValue element
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000118 * if it does not exist.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600119 * The sequence of an #arrayValue will be automatically resized and initialized
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000120 * with #nullValue. resize() can be used to enlarge or truncate an #arrayValue.
121 *
Christopher Dunnc28610f2015-02-21 11:44:16 -0600122 * The get() methods can be used to obtain default value in the case the
123 * required element does not exist.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000124 *
125 * It is possible to iterate over the list of a #objectValue values using
126 * the getMemberNames() method.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600127 *
Christopher Dunnc28610f2015-02-21 11:44:16 -0600128 * \note #Value string-length fit in size_t, but keys must be < 2^30.
129 * (The reason is an implementation detail.) A #CharReader will raise an
Christopher Dunn25342ba2015-03-02 18:05:26 -0600130 * exception if a bound is exceeded to avoid security holes in your app,
131 * but the Value API does *not* check bounds. That is the responsibility
132 * of the caller.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000133 */
134class JSON_API Value {
135 friend class ValueIteratorBase;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000136public:
137 typedef std::vector<std::string> Members;
138 typedef ValueIterator iterator;
139 typedef ValueConstIterator const_iterator;
140 typedef Json::UInt UInt;
141 typedef Json::Int Int;
142#if defined(JSON_HAS_INT64)
143 typedef Json::UInt64 UInt64;
144 typedef Json::Int64 Int64;
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +0000145#endif // defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000146 typedef Json::LargestInt LargestInt;
147 typedef Json::LargestUInt LargestUInt;
148 typedef Json::ArrayIndex ArrayIndex;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000149
Christopher Dunn8a702972015-03-03 10:38:27 -0600150 static const Value& null; ///< We regret this reference to a global instance; prefer the simpler Value().
151 static const Value& nullRef; ///< just a kludge for binary-compatibility; same as null
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000152 /// Minimum signed integer value that can be stored in a Json::Value.
153 static const LargestInt minLargestInt;
154 /// Maximum signed integer value that can be stored in a Json::Value.
155 static const LargestInt maxLargestInt;
156 /// Maximum unsigned integer value that can be stored in a Json::Value.
157 static const LargestUInt maxLargestUInt;
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +0000158
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000159 /// Minimum signed int value that can be stored in a Json::Value.
160 static const Int minInt;
161 /// Maximum signed int value that can be stored in a Json::Value.
162 static const Int maxInt;
163 /// Maximum unsigned int value that can be stored in a Json::Value.
164 static const UInt maxUInt;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000165
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000166#if defined(JSON_HAS_INT64)
167 /// Minimum signed 64 bits int value that can be stored in a Json::Value.
168 static const Int64 minInt64;
169 /// Maximum signed 64 bits int value that can be stored in a Json::Value.
170 static const Int64 maxInt64;
171 /// Maximum unsigned 64 bits int value that can be stored in a Json::Value.
172 static const UInt64 maxUInt64;
Aaron Jacobsf1053e72011-05-24 03:18:02 +0000173#endif // defined(JSON_HAS_INT64)
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +0000174
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000175private:
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000176#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000177 class CZString {
178 public:
179 enum DuplicationPolicy {
180 noDuplication = 0,
181 duplicate,
182 duplicateOnCopy
183 };
184 CZString(ArrayIndex index);
Christopher Dunnc28610f2015-02-21 11:44:16 -0600185 CZString(char const* str, unsigned length, DuplicationPolicy allocate);
186 CZString(CZString const& other);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000187 ~CZString();
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000188 CZString& operator=(CZString other);
Christopher Dunnc28610f2015-02-21 11:44:16 -0600189 bool operator<(CZString const& other) const;
190 bool operator==(CZString const& other) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000191 ArrayIndex index() const;
Christopher Dunnc28610f2015-02-21 11:44:16 -0600192 //const char* c_str() const; ///< \deprecated
193 char const* data() const;
194 unsigned length() const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000195 bool isStaticString() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000196
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000197 private:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000198 void swap(CZString& other);
Christopher Dunnc28610f2015-02-21 11:44:16 -0600199
Christopher Dunn57ad0512015-03-02 12:10:35 -0600200 struct StringStorage {
201 DuplicationPolicy policy_: 2;
202 unsigned length_: 30; // 1GB max
203 };
204
Christopher Dunnc28610f2015-02-21 11:44:16 -0600205 char const* cstr_; // actually, a prefixed string, unless policy is noDup
Christopher Dunn57ad0512015-03-02 12:10:35 -0600206 union {
207 ArrayIndex index_;
208 StringStorage storage_;
209 };
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000210 };
211
212public:
213#ifndef JSON_USE_CPPTL_SMALLMAP
214 typedef std::map<CZString, Value> ObjectValues;
215#else
216 typedef CppTL::SmallMap<CZString, Value> ObjectValues;
217#endif // ifndef JSON_USE_CPPTL_SMALLMAP
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000218#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
219
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000220public:
221 /** \brief Create a default Value of the given type.
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000222
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000223 This is a very useful constructor.
224 To create an empty array, pass arrayValue.
225 To create an empty object, pass objectValue.
226 Another Value can then be set to this one by assignment.
227This is useful since clear() and resize() will not alter types.
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000228
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000229 Examples:
230\code
231Json::Value null_value; // null
232Json::Value arr_value(Json::arrayValue); // []
233Json::Value obj_value(Json::objectValue); // {}
234\endcode
235 */
236 Value(ValueType type = nullValue);
237 Value(Int value);
238 Value(UInt value);
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +0000239#if defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000240 Value(Int64 value);
241 Value(UInt64 value);
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +0000242#endif // if defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000243 Value(double value);
Christopher Dunn8a702972015-03-03 10:38:27 -0600244 Value(const char* value); ///< Copy til first 0. (NULL causes to seg-fault.)
245 Value(const char* beginValue, const char* endValue); ///< Copy all, incl zeroes.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000246 /** \brief Constructs a value from a static string.
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000247
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000248 * Like other value string constructor but do not duplicate the string for
249 * internal storage. The given string must remain alive after the call to this
250 * constructor.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600251 * \note This works only for null-terminated strings. (We cannot change the
252 * size of this class, so we have nowhere to store the length,
253 * which might be computed later for various operations.)
254 *
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000255 * Example of usage:
256 * \code
Christopher Dunnc28610f2015-02-21 11:44:16 -0600257 * static StaticString foo("some text");
258 * Json::Value aValue(foo);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000259 * \endcode
260 */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000261 Value(const StaticString& value);
Christopher Dunn8a702972015-03-03 10:38:27 -0600262 Value(const std::string& value); ///< Copy data() til size(). Embedded zeroes too.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000263#ifdef JSON_USE_CPPTL
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000264 Value(const CppTL::ConstString& value);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000265#endif
266 Value(bool value);
Christopher Dunn66eb72f2015-01-20 11:02:22 -0600267 /// Deep copy.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000268 Value(const Value& other);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000269 ~Value();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000270
Christopher Dunn7f439f42015-03-06 09:22:57 -0600271 /// Deep copy, then swap(other).
272 /// \note Over-write existing comments. To preserve comments, use #swapPayload().
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000273 Value& operator=(Value other);
Christopher Dunn66eb72f2015-01-20 11:02:22 -0600274 /// Swap everything.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000275 void swap(Value& other);
Christopher Dunn66eb72f2015-01-20 11:02:22 -0600276 /// Swap values but leave comments and source offsets in place.
277 void swapPayload(Value& other);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000278
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000279 ValueType type() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000280
Christopher Dunn66eb72f2015-01-20 11:02:22 -0600281 /// Compare payload only, not comments etc.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000282 bool operator<(const Value& other) const;
283 bool operator<=(const Value& other) const;
284 bool operator>=(const Value& other) const;
285 bool operator>(const Value& other) const;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000286 bool operator==(const Value& other) const;
287 bool operator!=(const Value& other) const;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000288 int compare(const Value& other) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000289
Christopher Dunn8a702972015-03-03 10:38:27 -0600290 const char* asCString() const; ///< Embedded zeroes could cause you trouble!
291 std::string asString() const; ///< Embedded zeroes are possible.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600292 /** Get raw char* of string-value.
293 * \return false if !string. (Seg-fault if str or end are NULL.)
294 */
295 bool getString(
296 char const** str, char const** end) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000297#ifdef JSON_USE_CPPTL
298 CppTL::ConstString asConstString() const;
299#endif
300 Int asInt() const;
301 UInt asUInt() const;
Aaron Jacobsf1053e72011-05-24 03:18:02 +0000302#if defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000303 Int64 asInt64() const;
304 UInt64 asUInt64() const;
Aaron Jacobsf1053e72011-05-24 03:18:02 +0000305#endif // if defined(JSON_HAS_INT64)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000306 LargestInt asLargestInt() const;
307 LargestUInt asLargestUInt() const;
308 float asFloat() const;
309 double asDouble() const;
310 bool asBool() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000311
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000312 bool isNull() const;
313 bool isBool() const;
314 bool isInt() const;
315 bool isInt64() const;
316 bool isUInt() const;
317 bool isUInt64() const;
318 bool isIntegral() const;
319 bool isDouble() const;
320 bool isNumeric() const;
321 bool isString() const;
322 bool isArray() const;
323 bool isObject() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000324
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000325 bool isConvertibleTo(ValueType other) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000326
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000327 /// Number of values in array or object
328 ArrayIndex size() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000329
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000330 /// \brief Return true if empty array, empty object, or null;
331 /// otherwise, false.
332 bool empty() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000333
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000334 /// Return isNull()
335 bool operator!() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000336
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000337 /// Remove all object members and array elements.
338 /// \pre type() is arrayValue, objectValue, or nullValue
339 /// \post type() is unchanged
340 void clear();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000341
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000342 /// Resize the array to size elements.
343 /// New elements are initialized to null.
344 /// May only be called on nullValue or arrayValue.
345 /// \pre type() is arrayValue or nullValue
346 /// \post type() is arrayValue
347 void resize(ArrayIndex size);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000348
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000349 /// Access an array element (zero based index ).
350 /// If the array contains less than index element, then null value are
351 /// inserted
352 /// in the array so that its size is index+1.
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 Value& operator[](ArrayIndex index);
Baptiste Lepilleurfa130ef2010-12-24 12:47:14 +0000356
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000357 /// Access an array element (zero based index ).
358 /// If the array contains less than index element, then null value are
359 /// inserted
360 /// in the array so that its size is index+1.
361 /// (You may need to say 'value[0u]' to get your compiler to distinguish
362 /// this from the operator[] which takes a string.)
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000363 Value& operator[](int index);
Baptiste Lepilleurfa130ef2010-12-24 12:47:14 +0000364
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000365 /// Access an array element (zero based index )
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 const Value& operator[](ArrayIndex index) const;
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[](int index) const;
Baptiste Lepilleurfa130ef2010-12-24 12:47:14 +0000374
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000375 /// If the array contains at least index+1 elements, returns the element
376 /// value,
377 /// otherwise returns defaultValue.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000378 Value get(ArrayIndex index, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000379 /// Return true if index < size().
380 bool isValidIndex(ArrayIndex index) const;
381 /// \brief Append value to array at the end.
382 ///
383 /// Equivalent to jsonvalue[jsonvalue.size()] = value;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000384 Value& append(const Value& value);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000385
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000386 /// Access an object value by name, create a null member if it does not exist.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600387 /// \note Because of our implementation, keys are limited to 2^30 -1 chars.
388 /// Exceeding that will cause an exception.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000389 Value& operator[](const char* key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000390 /// Access an object value by name, returns null if there is no member with
391 /// that name.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000392 const Value& operator[](const char* key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000393 /// Access an object value by name, create a null member if it does not exist.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600394 /// \param key may contain embedded nulls.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000395 Value& operator[](const std::string& key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000396 /// Access an object value by name, returns null if there is no member with
397 /// that name.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600398 /// \param key may contain embedded nulls.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000399 const Value& operator[](const std::string& key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000400 /** \brief Access an object value by name, create a null member if it does not
401 exist.
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000402
Christopher Dunn25342ba2015-03-02 18:05:26 -0600403 * If the object has no entry for that name, then the member name used to store
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000404 * the new entry is not duplicated.
405 * Example of use:
406 * \code
407 * Json::Value object;
408 * static const StaticString code("code");
409 * object[code] = 1234;
410 * \endcode
411 */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000412 Value& operator[](const StaticString& key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000413#ifdef JSON_USE_CPPTL
414 /// Access an object value by name, create a null member if it does not exist.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000415 Value& operator[](const CppTL::ConstString& key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000416 /// Access an object value by name, returns null if there is no member with
417 /// that name.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000418 const Value& operator[](const CppTL::ConstString& key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000419#endif
420 /// Return the member named key if it exist, defaultValue otherwise.
Christopher Dunn0fd28752015-03-05 16:38:43 -0600421 /// \note deep copy
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000422 Value get(const char* key, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000423 /// Return the member named key if it exist, defaultValue otherwise.
Christopher Dunn0fd28752015-03-05 16:38:43 -0600424 /// \note deep copy
Christopher Dunn25342ba2015-03-02 18:05:26 -0600425 /// \param key may contain embedded nulls.
426 Value get(const char* key, const char* end, const Value& defaultValue) const;
427 /// Return the member named key if it exist, defaultValue otherwise.
Christopher Dunn0fd28752015-03-05 16:38:43 -0600428 /// \note deep copy
Christopher Dunn25342ba2015-03-02 18:05:26 -0600429 /// \param key may contain embedded nulls.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000430 Value get(const std::string& key, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000431#ifdef JSON_USE_CPPTL
432 /// Return the member named key if it exist, defaultValue otherwise.
Christopher Dunn0fd28752015-03-05 16:38:43 -0600433 /// \note deep copy
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000434 Value get(const CppTL::ConstString& key, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000435#endif
Christopher Dunn25342ba2015-03-02 18:05:26 -0600436 /// Most general and efficient version of isMember()const, get()const,
437 /// and operator[]const
438 /// \note As stated elsewhere, behavior is undefined if (end-key) >= 2^30
439 Value const* find(char const* key, char const* end) const;
Christopher Dunnc28610f2015-02-21 11:44:16 -0600440 /// Most general and efficient version of object-mutators.
441 /// \note As stated elsewhere, behavior is undefined if (end-key) >= 2^30
442 /// \return non-zero, but JSON_ASSERT if this is neither object nor nullValue.
443 Value const* demand(char const* key, char const* end);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000444 /// \brief Remove and return the named member.
445 ///
446 /// Do nothing if it did not exist.
447 /// \return the removed Value, or null.
448 /// \pre type() is objectValue or nullValue
449 /// \post type() is unchanged
Christopher Dunn76746b02015-01-21 16:01:30 -0600450 /// \deprecated
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000451 Value removeMember(const char* key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000452 /// Same as removeMember(const char*)
Christopher Dunn25342ba2015-03-02 18:05:26 -0600453 /// \param key may contain embedded nulls.
Christopher Dunn76746b02015-01-21 16:01:30 -0600454 /// \deprecated
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000455 Value removeMember(const std::string& key);
Christopher Dunn25342ba2015-03-02 18:05:26 -0600456 /// Same as removeMember(const char* key, const char* end, Value* removed),
457 /// but 'key' is null-terminated.
458 bool removeMember(const char* key, Value* removed);
Christopher Dunn76746b02015-01-21 16:01:30 -0600459 /** \brief Remove the named map member.
460
461 Update 'removed' iff removed.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600462 \param key may contain embedded nulls.
Christopher Dunn76746b02015-01-21 16:01:30 -0600463 \return true iff removed (no exceptions)
464 */
Christopher Dunn25342ba2015-03-02 18:05:26 -0600465 bool removeMember(std::string const& key, Value* removed);
466 /// Same as removeMember(std::string const& key, Value* removed)
467 bool removeMember(const char* key, const char* end, Value* removed);
Christopher Dunn9de2c2d2015-01-20 16:15:40 -0600468 /** \brief Remove the indexed array element.
469
470 O(n) expensive operations.
471 Update 'removed' iff removed.
Christopher Dunne87e41c2015-01-20 16:24:11 -0600472 \return true iff removed (no exceptions)
Christopher Dunn9de2c2d2015-01-20 16:15:40 -0600473 */
474 bool removeIndex(ArrayIndex i, Value* removed);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000475
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000476 /// Return true if the object has a member named key.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600477 /// \note 'key' must be null-terminated.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000478 bool isMember(const char* key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000479 /// Return true if the object has a member named key.
Christopher Dunn25342ba2015-03-02 18:05:26 -0600480 /// \param key may contain embedded nulls.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000481 bool isMember(const std::string& key) const;
Christopher Dunn25342ba2015-03-02 18:05:26 -0600482 /// Same as isMember(std::string const& key)const
483 bool isMember(const char* key, const char* end) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000484#ifdef JSON_USE_CPPTL
485 /// Return true if the object has a member named key.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000486 bool isMember(const CppTL::ConstString& key) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000487#endif
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000488
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000489 /// \brief Return a list of the member names.
490 ///
491 /// If null, return an empty list.
492 /// \pre type() is objectValue or nullValue
493 /// \post if type() was nullValue, it remains nullValue
494 Members getMemberNames() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000495
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000496 //# ifdef JSON_USE_CPPTL
497 // EnumMemberNames enumMemberNames() const;
498 // EnumValues enumValues() const;
499 //# endif
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000500
Christopher Dunn1e3149a2015-01-25 14:16:13 -0600501 /// \deprecated Always pass len.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000502 void setComment(const char* comment, CommentPlacement placement);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000503 /// Comments must be //... or /* ... */
Christopher Dunn1e3149a2015-01-25 14:16:13 -0600504 void setComment(const char* comment, size_t len, CommentPlacement placement);
505 /// Comments must be //... or /* ... */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000506 void setComment(const std::string& comment, CommentPlacement placement);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000507 bool hasComment(CommentPlacement placement) const;
508 /// Include delimiters and embedded newlines.
509 std::string getComment(CommentPlacement placement) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000510
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000511 std::string toStyledString() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000512
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000513 const_iterator begin() const;
514 const_iterator end() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000515
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000516 iterator begin();
517 iterator end();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000518
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000519 // Accessors for the [start, limit) range of bytes within the JSON text from
520 // which this value was parsed, if any.
521 void setOffsetStart(size_t start);
522 void setOffsetLimit(size_t limit);
523 size_t getOffsetStart() const;
524 size_t getOffsetLimit() const;
Aaron Jacobs68db6552014-04-23 23:41:12 +0000525
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000526private:
Billy Donahue8eb5d892014-11-10 01:35:42 -0500527 void initBasic(ValueType type, bool allocated = false);
528
Christopher Dunnc28610f2015-02-21 11:44:16 -0600529 Value& resolveReference(const char* key);
530 Value& resolveReference(const char* key, const char* end);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000531
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000532 struct CommentInfo {
533 CommentInfo();
534 ~CommentInfo();
535
Christopher Dunn1e3149a2015-01-25 14:16:13 -0600536 void setComment(const char* text, size_t len);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000537
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000538 char* comment_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000539 };
540
541 // struct MemberNamesTransform
542 //{
543 // typedef const char *result_type;
544 // const char *operator()( const CZString &name ) const
545 // {
546 // return name.c_str();
547 // }
548 //};
549
550 union ValueHolder {
551 LargestInt int_;
552 LargestUInt uint_;
553 double real_;
554 bool bool_;
Christopher Dunnc28610f2015-02-21 11:44:16 -0600555 char* string_; // actually ptr to unsigned, followed by str, unless !allocated_
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000556 ObjectValues* map_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000557 } value_;
558 ValueType type_ : 8;
Christopher Dunn2bc61372015-01-24 13:42:37 -0600559 unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600560 // If not allocated_, string_ must be null-terminated.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000561 CommentInfo* comments_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000562
563 // [start, limit) byte offsets in the source JSON text from which this Value
564 // was extracted.
565 size_t start_;
566 size_t limit_;
567};
568
569/** \brief Experimental and untested: represents an element of the "path" to
570 * access a node.
571 */
572class JSON_API PathArgument {
573public:
574 friend class Path;
575
576 PathArgument();
577 PathArgument(ArrayIndex index);
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000578 PathArgument(const char* key);
579 PathArgument(const std::string& key);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000580
581private:
582 enum Kind {
583 kindNone = 0,
584 kindIndex,
585 kindKey
586 };
587 std::string key_;
588 ArrayIndex index_;
589 Kind kind_;
590};
591
592/** \brief Experimental and untested: represents a "path" to access a node.
593 *
594 * Syntax:
595 * - "." => root node
596 * - ".[n]" => elements at index 'n' of root node (an array value)
597 * - ".name" => member named 'name' of root node (an object value)
598 * - ".name1.name2.name3"
599 * - ".[0][1][2].name1[3]"
600 * - ".%" => member name is provided as parameter
601 * - ".[%]" => index is provied as parameter
602 */
603class JSON_API Path {
604public:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000605 Path(const std::string& path,
606 const PathArgument& a1 = PathArgument(),
607 const PathArgument& a2 = PathArgument(),
608 const PathArgument& a3 = PathArgument(),
609 const PathArgument& a4 = PathArgument(),
610 const PathArgument& a5 = PathArgument());
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000611
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000612 const Value& resolve(const Value& root) const;
613 Value resolve(const Value& root, const Value& defaultValue) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000614 /// Creates the "path" to access the specified node and returns a reference on
615 /// the node.
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000616 Value& make(Value& root) const;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000617
618private:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000619 typedef std::vector<const PathArgument*> InArgs;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000620 typedef std::vector<PathArgument> Args;
621
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000622 void makePath(const std::string& path, const InArgs& in);
623 void addPathInArg(const std::string& path,
624 const InArgs& in,
625 InArgs::const_iterator& itInArg,
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000626 PathArgument::Kind kind);
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000627 void invalidPath(const std::string& path, int location);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000628
629 Args args_;
630};
631
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000632/** \brief base class for Value iterators.
633 *
634 */
635class JSON_API ValueIteratorBase {
636public:
637 typedef std::bidirectional_iterator_tag iterator_category;
638 typedef unsigned int size_t;
639 typedef int difference_type;
640 typedef ValueIteratorBase SelfType;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000641
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000642 ValueIteratorBase();
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000643 explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000644
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000645 bool operator==(const SelfType& other) const { return isEqual(other); }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000646
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000647 bool operator!=(const SelfType& other) const { return !isEqual(other); }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000648
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000649 difference_type operator-(const SelfType& other) const {
Kevin Grant4c5832a2015-02-14 20:53:35 -0800650 return other.computeDistance(*this);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000651 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000652
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000653 /// Return either the index or the member name of the referenced value as a
654 /// Value.
655 Value key() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000656
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000657 /// Return the index of the referenced Value. -1 if it is not an arrayValue.
658 UInt index() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000659
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000660 /// Return the member name of the referenced Value. "" if it is not an
661 /// objectValue.
Christopher Dunnc28610f2015-02-21 11:44:16 -0600662 /// \deprecated This cannot be used for UTF-8 strings, since there can be embedded nulls.
663 char const* memberName() const;
664 /// Return the member name of the referenced Value, or NULL if it is not an
665 /// objectValue.
666 /// Better version than memberName(). Allows embedded nulls.
667 char const* memberName(char const** end) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000668
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000669protected:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000670 Value& deref() const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000671
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000672 void increment();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000673
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000674 void decrement();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000675
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000676 difference_type computeDistance(const SelfType& other) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000677
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000678 bool isEqual(const SelfType& other) const;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000679
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000680 void copy(const SelfType& other);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000681
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000682private:
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000683 Value::ObjectValues::iterator current_;
684 // Indicates that iterator is for a null value.
685 bool isNull_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000686};
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000687
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000688/** \brief const iterator for object and array value.
689 *
690 */
691class JSON_API ValueConstIterator : public ValueIteratorBase {
692 friend class Value;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000693
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000694public:
695 typedef const Value value_type;
Christopher Dunnc28610f2015-02-21 11:44:16 -0600696 //typedef unsigned int size_t;
697 //typedef int difference_type;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000698 typedef const Value& reference;
699 typedef const Value* pointer;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000700 typedef ValueConstIterator SelfType;
701
702 ValueConstIterator();
703
704private:
705/*! \internal Use by Value to create an iterator.
706 */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000707 explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000708public:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000709 SelfType& operator=(const ValueIteratorBase& other);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000710
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000711 SelfType operator++(int) {
712 SelfType temp(*this);
713 ++*this;
714 return temp;
715 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000716
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000717 SelfType operator--(int) {
718 SelfType temp(*this);
719 --*this;
720 return temp;
721 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000722
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000723 SelfType& operator--() {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000724 decrement();
725 return *this;
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 increment();
730 return *this;
731 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000732
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000733 reference operator*() const { return deref(); }
Braden McDorman540db3b2014-09-14 02:31:23 -0500734
735 pointer operator->() const { return &deref(); }
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000736};
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000737
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000738/** \brief Iterator for object and array value.
739 */
740class JSON_API ValueIterator : public ValueIteratorBase {
741 friend class Value;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000742
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000743public:
744 typedef Value value_type;
745 typedef unsigned int size_t;
746 typedef int difference_type;
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000747 typedef Value& reference;
748 typedef Value* pointer;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000749 typedef ValueIterator SelfType;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000750
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000751 ValueIterator();
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000752 ValueIterator(const ValueConstIterator& other);
753 ValueIterator(const ValueIterator& other);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000754
755private:
756/*! \internal Use by Value to create an iterator.
757 */
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000758 explicit ValueIterator(const Value::ObjectValues::iterator& current);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000759public:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000760 SelfType& operator=(const SelfType& other);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000761
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000762 SelfType operator++(int) {
763 SelfType temp(*this);
764 ++*this;
765 return temp;
766 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000767
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000768 SelfType operator--(int) {
769 SelfType temp(*this);
770 --*this;
771 return temp;
772 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000773
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000774 SelfType& operator--() {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000775 decrement();
776 return *this;
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 increment();
781 return *this;
782 }
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000783
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000784 reference operator*() const { return deref(); }
Braden McDorman540db3b2014-09-14 02:31:23 -0500785
786 pointer operator->() const { return &deref(); }
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000787};
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000788
789} // namespace Json
790
datadiode9454e682015-01-20 15:25:04 -0600791
792namespace std {
793/// Specialize std::swap() for Json::Value.
794template<>
795inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); }
796}
797
798
Baptiste Lepilleureafd7022013-05-08 20:21:11 +0000799#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000800#pragma warning(pop)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +0000801#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
802
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000803#endif // CPPTL_JSON_H_INCLUDED