Baptiste Lepilleur | 7469f1d | 2010-04-20 21:35:19 +0000 | [diff] [blame] | 1 | // 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 Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 6 | #ifndef CPPTL_JSON_H_INCLUDED |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 7 | #define CPPTL_JSON_H_INCLUDED |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 8 | |
Baptiste Lepilleur | eadc478 | 2011-05-02 21:09:30 +0000 | [diff] [blame] | 9 | #if !defined(JSON_IS_AMALGAMATION) |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 10 | #include "forwards.h" |
Baptiste Lepilleur | eadc478 | 2011-05-02 21:09:30 +0000 | [diff] [blame] | 11 | #endif // if !defined(JSON_IS_AMALGAMATION) |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 12 | #include <string> |
| 13 | #include <vector> |
Christopher Dunn | 75279cc | 2015-03-08 12:20:06 -0500 | [diff] [blame] | 14 | #include <exception> |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 15 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 16 | #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 Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 24 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 25 | // Disable warning C4251: <data member>: <type> needs to have dll-interface to |
| 26 | // be used by... |
Baptiste Lepilleur | eafd702 | 2013-05-08 20:21:11 +0000 | [diff] [blame] | 27 | #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 28 | #pragma warning(push) |
| 29 | #pragma warning(disable : 4251) |
Baptiste Lepilleur | eafd702 | 2013-05-08 20:21:11 +0000 | [diff] [blame] | 30 | #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) |
| 31 | |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 32 | /** \brief JSON (JavaScript Object Notation). |
| 33 | */ |
| 34 | namespace Json { |
| 35 | |
Christopher Dunn | 75279cc | 2015-03-08 12:20:06 -0500 | [diff] [blame] | 36 | /** Base class for all exceptions we throw. |
Christopher Dunn | 4e30c4f | 2015-03-08 12:56:32 -0500 | [diff] [blame] | 37 | * |
| 38 | * We use nothing but these internally. Of course, STL can throw others. |
Christopher Dunn | 75279cc | 2015-03-08 12:20:06 -0500 | [diff] [blame] | 39 | */ |
Christopher Dunn | 5383794 | 2015-03-08 12:31:00 -0500 | [diff] [blame] | 40 | class JSON_API Exception; |
| 41 | /** Exceptions which the user cannot easily avoid. |
| 42 | * |
Christopher Dunn | 4e30c4f | 2015-03-08 12:56:32 -0500 | [diff] [blame] | 43 | * E.g. out-of-memory (when we use malloc), stack-overflow, malicious input |
| 44 | * |
| 45 | * \remark derived from Json::Exception |
Christopher Dunn | 5383794 | 2015-03-08 12:31:00 -0500 | [diff] [blame] | 46 | */ |
| 47 | class JSON_API RuntimeError; |
Christopher Dunn | 4e30c4f | 2015-03-08 12:56:32 -0500 | [diff] [blame] | 48 | /** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros. |
Christopher Dunn | 5383794 | 2015-03-08 12:31:00 -0500 | [diff] [blame] | 49 | * |
| 50 | * These are precondition-violations (user bugs) and internal errors (our bugs). |
Christopher Dunn | 4e30c4f | 2015-03-08 12:56:32 -0500 | [diff] [blame] | 51 | * |
| 52 | * \remark derived from Json::Exception |
Christopher Dunn | 5383794 | 2015-03-08 12:31:00 -0500 | [diff] [blame] | 53 | */ |
| 54 | class JSON_API LogicError; |
| 55 | |
Christopher Dunn | 4e30c4f | 2015-03-08 12:56:32 -0500 | [diff] [blame] | 56 | /// used internally |
| 57 | void throwRuntimeError(std::string const& msg); |
| 58 | /// used internally |
| 59 | void throwLogicError(std::string const& msg); |
Christopher Dunn | 75279cc | 2015-03-08 12:20:06 -0500 | [diff] [blame] | 60 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 61 | /** \brief Type of the value held by a Value object. |
| 62 | */ |
| 63 | enum ValueType { |
| 64 | nullValue = 0, ///< 'null' value |
| 65 | intValue, ///< signed integer value |
| 66 | uintValue, ///< unsigned integer value |
| 67 | realValue, ///< double value |
| 68 | stringValue, ///< UTF-8 string value |
| 69 | booleanValue, ///< bool value |
| 70 | arrayValue, ///< array value (ordered list) |
| 71 | objectValue ///< object value (collection of name/value pairs). |
| 72 | }; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 73 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 74 | enum CommentPlacement { |
| 75 | commentBefore = 0, ///< a comment placed on the line before a value |
| 76 | commentAfterOnSameLine, ///< a comment just after a value on the same line |
| 77 | commentAfter, ///< a comment on the line after a value (only make sense for |
Aaron Jacobs | 3a0c4fc | 2014-07-01 09:20:48 +1000 | [diff] [blame] | 78 | /// root value) |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 79 | numberOfCommentPlacement |
| 80 | }; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 81 | |
| 82 | //# ifdef JSON_USE_CPPTL |
| 83 | // typedef CppTL::AnyEnumerator<const char *> EnumMemberNames; |
| 84 | // typedef CppTL::AnyEnumerator<const Value &> EnumValues; |
| 85 | //# endif |
| 86 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 87 | /** \brief Lightweight wrapper to tag static string. |
| 88 | * |
| 89 | * Value constructor and objectValue member assignement takes advantage of the |
| 90 | * StaticString and avoid the cost of string duplication when storing the |
| 91 | * string or the member name. |
| 92 | * |
| 93 | * Example of usage: |
| 94 | * \code |
| 95 | * Json::Value aValue( StaticString("some text") ); |
| 96 | * Json::Value object; |
| 97 | * static const StaticString code("code"); |
| 98 | * object[code] = 1234; |
| 99 | * \endcode |
| 100 | */ |
| 101 | class JSON_API StaticString { |
| 102 | public: |
Christopher Dunn | ff61752 | 2015-03-06 10:31:46 -0600 | [diff] [blame] | 103 | explicit StaticString(const char* czstring) : c_str_(czstring) {} |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 104 | |
Christopher Dunn | ff61752 | 2015-03-06 10:31:46 -0600 | [diff] [blame] | 105 | operator const char*() const { return c_str_; } |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 106 | |
Christopher Dunn | ff61752 | 2015-03-06 10:31:46 -0600 | [diff] [blame] | 107 | const char* c_str() const { return c_str_; } |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 108 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 109 | private: |
Christopher Dunn | ff61752 | 2015-03-06 10:31:46 -0600 | [diff] [blame] | 110 | const char* c_str_; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 111 | }; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 112 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 113 | /** \brief Represents a <a HREF="http://www.json.org">JSON</a> value. |
| 114 | * |
| 115 | * This class is a discriminated union wrapper that can represents a: |
| 116 | * - signed integer [range: Value::minInt - Value::maxInt] |
| 117 | * - unsigned integer (range: 0 - Value::maxUInt) |
| 118 | * - double |
| 119 | * - UTF-8 string |
| 120 | * - boolean |
| 121 | * - 'null' |
| 122 | * - an ordered list of Value |
| 123 | * - collection of name/value pairs (javascript object) |
| 124 | * |
| 125 | * The type of the held value is represented by a #ValueType and |
| 126 | * can be obtained using type(). |
| 127 | * |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 128 | * Values of an #objectValue or #arrayValue can be accessed using operator[]() |
| 129 | * methods. |
| 130 | * Non-const methods will automatically create the a #nullValue element |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 131 | * if it does not exist. |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 132 | * The sequence of an #arrayValue will be automatically resized and initialized |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 133 | * with #nullValue. resize() can be used to enlarge or truncate an #arrayValue. |
| 134 | * |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 135 | * The get() methods can be used to obtain default value in the case the |
| 136 | * required element does not exist. |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 137 | * |
| 138 | * It is possible to iterate over the list of a #objectValue values using |
| 139 | * the getMemberNames() method. |
Christopher Dunn | 25342ba | 2015-03-02 18:05:26 -0600 | [diff] [blame] | 140 | * |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 141 | * \note #Value string-length fit in size_t, but keys must be < 2^30. |
| 142 | * (The reason is an implementation detail.) A #CharReader will raise an |
Christopher Dunn | 25342ba | 2015-03-02 18:05:26 -0600 | [diff] [blame] | 143 | * exception if a bound is exceeded to avoid security holes in your app, |
| 144 | * but the Value API does *not* check bounds. That is the responsibility |
| 145 | * of the caller. |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 146 | */ |
| 147 | class JSON_API Value { |
| 148 | friend class ValueIteratorBase; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 149 | public: |
| 150 | typedef std::vector<std::string> Members; |
| 151 | typedef ValueIterator iterator; |
| 152 | typedef ValueConstIterator const_iterator; |
| 153 | typedef Json::UInt UInt; |
| 154 | typedef Json::Int Int; |
| 155 | #if defined(JSON_HAS_INT64) |
| 156 | typedef Json::UInt64 UInt64; |
| 157 | typedef Json::Int64 Int64; |
Baptiste Lepilleur | 842e9ac | 2010-12-27 17:45:23 +0000 | [diff] [blame] | 158 | #endif // defined(JSON_HAS_INT64) |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 159 | typedef Json::LargestInt LargestInt; |
| 160 | typedef Json::LargestUInt LargestUInt; |
| 161 | typedef Json::ArrayIndex ArrayIndex; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 162 | |
Christopher Dunn | 8a70297 | 2015-03-03 10:38:27 -0600 | [diff] [blame] | 163 | static const Value& null; ///< We regret this reference to a global instance; prefer the simpler Value(). |
| 164 | static const Value& nullRef; ///< just a kludge for binary-compatibility; same as null |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 165 | /// Minimum signed integer value that can be stored in a Json::Value. |
| 166 | static const LargestInt minLargestInt; |
| 167 | /// Maximum signed integer value that can be stored in a Json::Value. |
| 168 | static const LargestInt maxLargestInt; |
| 169 | /// Maximum unsigned integer value that can be stored in a Json::Value. |
| 170 | static const LargestUInt maxLargestUInt; |
Baptiste Lepilleur | 842e9ac | 2010-12-27 17:45:23 +0000 | [diff] [blame] | 171 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 172 | /// Minimum signed int value that can be stored in a Json::Value. |
| 173 | static const Int minInt; |
| 174 | /// Maximum signed int value that can be stored in a Json::Value. |
| 175 | static const Int maxInt; |
| 176 | /// Maximum unsigned int value that can be stored in a Json::Value. |
| 177 | static const UInt maxUInt; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 178 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 179 | #if defined(JSON_HAS_INT64) |
| 180 | /// Minimum signed 64 bits int value that can be stored in a Json::Value. |
| 181 | static const Int64 minInt64; |
| 182 | /// Maximum signed 64 bits int value that can be stored in a Json::Value. |
| 183 | static const Int64 maxInt64; |
| 184 | /// Maximum unsigned 64 bits int value that can be stored in a Json::Value. |
| 185 | static const UInt64 maxUInt64; |
Aaron Jacobs | f1053e7 | 2011-05-24 03:18:02 +0000 | [diff] [blame] | 186 | #endif // defined(JSON_HAS_INT64) |
Baptiste Lepilleur | 842e9ac | 2010-12-27 17:45:23 +0000 | [diff] [blame] | 187 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 188 | private: |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 189 | #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 190 | class CZString { |
| 191 | public: |
| 192 | enum DuplicationPolicy { |
| 193 | noDuplication = 0, |
| 194 | duplicate, |
| 195 | duplicateOnCopy |
| 196 | }; |
| 197 | CZString(ArrayIndex index); |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 198 | CZString(char const* str, unsigned length, DuplicationPolicy allocate); |
| 199 | CZString(CZString const& other); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 200 | ~CZString(); |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 201 | CZString& operator=(CZString other); |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 202 | bool operator<(CZString const& other) const; |
| 203 | bool operator==(CZString const& other) const; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 204 | ArrayIndex index() const; |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 205 | //const char* c_str() const; ///< \deprecated |
| 206 | char const* data() const; |
| 207 | unsigned length() const; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 208 | bool isStaticString() const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 209 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 210 | private: |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 211 | void swap(CZString& other); |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 212 | |
Christopher Dunn | 57ad051 | 2015-03-02 12:10:35 -0600 | [diff] [blame] | 213 | struct StringStorage { |
| 214 | DuplicationPolicy policy_: 2; |
| 215 | unsigned length_: 30; // 1GB max |
| 216 | }; |
| 217 | |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 218 | char const* cstr_; // actually, a prefixed string, unless policy is noDup |
Christopher Dunn | 57ad051 | 2015-03-02 12:10:35 -0600 | [diff] [blame] | 219 | union { |
| 220 | ArrayIndex index_; |
| 221 | StringStorage storage_; |
| 222 | }; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 223 | }; |
| 224 | |
| 225 | public: |
| 226 | #ifndef JSON_USE_CPPTL_SMALLMAP |
| 227 | typedef std::map<CZString, Value> ObjectValues; |
| 228 | #else |
| 229 | typedef CppTL::SmallMap<CZString, Value> ObjectValues; |
| 230 | #endif // ifndef JSON_USE_CPPTL_SMALLMAP |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 231 | #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION |
| 232 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 233 | public: |
| 234 | /** \brief Create a default Value of the given type. |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 235 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 236 | This is a very useful constructor. |
| 237 | To create an empty array, pass arrayValue. |
| 238 | To create an empty object, pass objectValue. |
| 239 | Another Value can then be set to this one by assignment. |
| 240 | This is useful since clear() and resize() will not alter types. |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 241 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 242 | Examples: |
| 243 | \code |
| 244 | Json::Value null_value; // null |
| 245 | Json::Value arr_value(Json::arrayValue); // [] |
| 246 | Json::Value obj_value(Json::objectValue); // {} |
| 247 | \endcode |
| 248 | */ |
| 249 | Value(ValueType type = nullValue); |
| 250 | Value(Int value); |
| 251 | Value(UInt value); |
Baptiste Lepilleur | 842e9ac | 2010-12-27 17:45:23 +0000 | [diff] [blame] | 252 | #if defined(JSON_HAS_INT64) |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 253 | Value(Int64 value); |
| 254 | Value(UInt64 value); |
Baptiste Lepilleur | 842e9ac | 2010-12-27 17:45:23 +0000 | [diff] [blame] | 255 | #endif // if defined(JSON_HAS_INT64) |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 256 | Value(double value); |
Christopher Dunn | 8a70297 | 2015-03-03 10:38:27 -0600 | [diff] [blame] | 257 | Value(const char* value); ///< Copy til first 0. (NULL causes to seg-fault.) |
| 258 | Value(const char* beginValue, const char* endValue); ///< Copy all, incl zeroes. |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 259 | /** \brief Constructs a value from a static string. |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 260 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 261 | * Like other value string constructor but do not duplicate the string for |
| 262 | * internal storage. The given string must remain alive after the call to this |
| 263 | * constructor. |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 264 | * \note This works only for null-terminated strings. (We cannot change the |
| 265 | * size of this class, so we have nowhere to store the length, |
| 266 | * which might be computed later for various operations.) |
| 267 | * |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 268 | * Example of usage: |
| 269 | * \code |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 270 | * static StaticString foo("some text"); |
| 271 | * Json::Value aValue(foo); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 272 | * \endcode |
| 273 | */ |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 274 | Value(const StaticString& value); |
Christopher Dunn | 8a70297 | 2015-03-03 10:38:27 -0600 | [diff] [blame] | 275 | Value(const std::string& value); ///< Copy data() til size(). Embedded zeroes too. |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 276 | #ifdef JSON_USE_CPPTL |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 277 | Value(const CppTL::ConstString& value); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 278 | #endif |
| 279 | Value(bool value); |
Christopher Dunn | 66eb72f | 2015-01-20 11:02:22 -0600 | [diff] [blame] | 280 | /// Deep copy. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 281 | Value(const Value& other); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 282 | ~Value(); |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 283 | |
Christopher Dunn | 7f439f4 | 2015-03-06 09:22:57 -0600 | [diff] [blame] | 284 | /// Deep copy, then swap(other). |
| 285 | /// \note Over-write existing comments. To preserve comments, use #swapPayload(). |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 286 | Value& operator=(Value other); |
Christopher Dunn | 66eb72f | 2015-01-20 11:02:22 -0600 | [diff] [blame] | 287 | /// Swap everything. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 288 | void swap(Value& other); |
Christopher Dunn | 66eb72f | 2015-01-20 11:02:22 -0600 | [diff] [blame] | 289 | /// Swap values but leave comments and source offsets in place. |
| 290 | void swapPayload(Value& other); |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 291 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 292 | ValueType type() const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 293 | |
Christopher Dunn | 66eb72f | 2015-01-20 11:02:22 -0600 | [diff] [blame] | 294 | /// Compare payload only, not comments etc. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 295 | bool operator<(const Value& other) const; |
| 296 | bool operator<=(const Value& other) const; |
| 297 | bool operator>=(const Value& other) const; |
| 298 | bool operator>(const Value& other) const; |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 299 | bool operator==(const Value& other) const; |
| 300 | bool operator!=(const Value& other) const; |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 301 | int compare(const Value& other) const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 302 | |
Christopher Dunn | 8a70297 | 2015-03-03 10:38:27 -0600 | [diff] [blame] | 303 | const char* asCString() const; ///< Embedded zeroes could cause you trouble! |
| 304 | std::string asString() const; ///< Embedded zeroes are possible. |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 305 | /** Get raw char* of string-value. |
| 306 | * \return false if !string. (Seg-fault if str or end are NULL.) |
| 307 | */ |
| 308 | bool getString( |
| 309 | char const** str, char const** end) const; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 310 | #ifdef JSON_USE_CPPTL |
| 311 | CppTL::ConstString asConstString() const; |
| 312 | #endif |
| 313 | Int asInt() const; |
| 314 | UInt asUInt() const; |
Aaron Jacobs | f1053e7 | 2011-05-24 03:18:02 +0000 | [diff] [blame] | 315 | #if defined(JSON_HAS_INT64) |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 316 | Int64 asInt64() const; |
| 317 | UInt64 asUInt64() const; |
Aaron Jacobs | f1053e7 | 2011-05-24 03:18:02 +0000 | [diff] [blame] | 318 | #endif // if defined(JSON_HAS_INT64) |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 319 | LargestInt asLargestInt() const; |
| 320 | LargestUInt asLargestUInt() const; |
| 321 | float asFloat() const; |
| 322 | double asDouble() const; |
| 323 | bool asBool() const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 324 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 325 | bool isNull() const; |
| 326 | bool isBool() const; |
| 327 | bool isInt() const; |
| 328 | bool isInt64() const; |
| 329 | bool isUInt() const; |
| 330 | bool isUInt64() const; |
| 331 | bool isIntegral() const; |
| 332 | bool isDouble() const; |
| 333 | bool isNumeric() const; |
| 334 | bool isString() const; |
| 335 | bool isArray() const; |
| 336 | bool isObject() const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 337 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 338 | bool isConvertibleTo(ValueType other) const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 339 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 340 | /// Number of values in array or object |
| 341 | ArrayIndex size() const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 342 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 343 | /// \brief Return true if empty array, empty object, or null; |
| 344 | /// otherwise, false. |
| 345 | bool empty() const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 346 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 347 | /// Return isNull() |
| 348 | bool operator!() const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 349 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 350 | /// Remove all object members and array elements. |
| 351 | /// \pre type() is arrayValue, objectValue, or nullValue |
| 352 | /// \post type() is unchanged |
| 353 | void clear(); |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 354 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 355 | /// Resize the array to size elements. |
| 356 | /// New elements are initialized to null. |
| 357 | /// May only be called on nullValue or arrayValue. |
| 358 | /// \pre type() is arrayValue or nullValue |
| 359 | /// \post type() is arrayValue |
| 360 | void resize(ArrayIndex size); |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 361 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 362 | /// Access an array element (zero based index ). |
| 363 | /// If the array contains less than index element, then null value are |
| 364 | /// inserted |
| 365 | /// in the array so that its size is index+1. |
| 366 | /// (You may need to say 'value[0u]' to get your compiler to distinguish |
| 367 | /// this from the operator[] which takes a string.) |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 368 | Value& operator[](ArrayIndex index); |
Baptiste Lepilleur | fa130ef | 2010-12-24 12:47:14 +0000 | [diff] [blame] | 369 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 370 | /// Access an array element (zero based index ). |
| 371 | /// If the array contains less than index element, then null value are |
| 372 | /// inserted |
| 373 | /// in the array so that its size is index+1. |
| 374 | /// (You may need to say 'value[0u]' to get your compiler to distinguish |
| 375 | /// this from the operator[] which takes a string.) |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 376 | Value& operator[](int index); |
Baptiste Lepilleur | fa130ef | 2010-12-24 12:47:14 +0000 | [diff] [blame] | 377 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 378 | /// Access an array element (zero based index ) |
| 379 | /// (You may need to say 'value[0u]' to get your compiler to distinguish |
| 380 | /// this from the operator[] which takes a string.) |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 381 | const Value& operator[](ArrayIndex index) const; |
Baptiste Lepilleur | fa130ef | 2010-12-24 12:47:14 +0000 | [diff] [blame] | 382 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 383 | /// Access an array element (zero based index ) |
| 384 | /// (You may need to say 'value[0u]' to get your compiler to distinguish |
| 385 | /// this from the operator[] which takes a string.) |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 386 | const Value& operator[](int index) const; |
Baptiste Lepilleur | fa130ef | 2010-12-24 12:47:14 +0000 | [diff] [blame] | 387 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 388 | /// If the array contains at least index+1 elements, returns the element |
| 389 | /// value, |
| 390 | /// otherwise returns defaultValue. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 391 | Value get(ArrayIndex index, const Value& defaultValue) const; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 392 | /// Return true if index < size(). |
| 393 | bool isValidIndex(ArrayIndex index) const; |
| 394 | /// \brief Append value to array at the end. |
| 395 | /// |
| 396 | /// Equivalent to jsonvalue[jsonvalue.size()] = value; |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 397 | Value& append(const Value& value); |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 398 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 399 | /// Access an object value by name, create a null member if it does not exist. |
Christopher Dunn | 25342ba | 2015-03-02 18:05:26 -0600 | [diff] [blame] | 400 | /// \note Because of our implementation, keys are limited to 2^30 -1 chars. |
| 401 | /// Exceeding that will cause an exception. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 402 | Value& operator[](const char* key); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 403 | /// Access an object value by name, returns null if there is no member with |
| 404 | /// that name. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 405 | const Value& operator[](const char* key) const; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 406 | /// Access an object value by name, create a null member if it does not exist. |
Christopher Dunn | 25342ba | 2015-03-02 18:05:26 -0600 | [diff] [blame] | 407 | /// \param key may contain embedded nulls. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 408 | Value& operator[](const std::string& key); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 409 | /// Access an object value by name, returns null if there is no member with |
| 410 | /// that name. |
Christopher Dunn | 25342ba | 2015-03-02 18:05:26 -0600 | [diff] [blame] | 411 | /// \param key may contain embedded nulls. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 412 | const Value& operator[](const std::string& key) const; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 413 | /** \brief Access an object value by name, create a null member if it does not |
| 414 | exist. |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 415 | |
Christopher Dunn | 25342ba | 2015-03-02 18:05:26 -0600 | [diff] [blame] | 416 | * If the object has no entry for that name, then the member name used to store |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 417 | * the new entry is not duplicated. |
| 418 | * Example of use: |
| 419 | * \code |
| 420 | * Json::Value object; |
| 421 | * static const StaticString code("code"); |
| 422 | * object[code] = 1234; |
| 423 | * \endcode |
| 424 | */ |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 425 | Value& operator[](const StaticString& key); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 426 | #ifdef JSON_USE_CPPTL |
| 427 | /// Access an object value by name, create a null member if it does not exist. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 428 | Value& operator[](const CppTL::ConstString& key); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 429 | /// Access an object value by name, returns null if there is no member with |
| 430 | /// that name. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 431 | const Value& operator[](const CppTL::ConstString& key) const; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 432 | #endif |
| 433 | /// Return the member named key if it exist, defaultValue otherwise. |
Christopher Dunn | 0fd2875 | 2015-03-05 16:38:43 -0600 | [diff] [blame] | 434 | /// \note deep copy |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 435 | Value get(const char* key, const Value& defaultValue) const; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 436 | /// Return the member named key if it exist, defaultValue otherwise. |
Christopher Dunn | 0fd2875 | 2015-03-05 16:38:43 -0600 | [diff] [blame] | 437 | /// \note deep copy |
Christopher Dunn | 25342ba | 2015-03-02 18:05:26 -0600 | [diff] [blame] | 438 | /// \param key may contain embedded nulls. |
| 439 | Value get(const char* key, const char* end, const Value& defaultValue) const; |
| 440 | /// Return the member named key if it exist, defaultValue otherwise. |
Christopher Dunn | 0fd2875 | 2015-03-05 16:38:43 -0600 | [diff] [blame] | 441 | /// \note deep copy |
Christopher Dunn | 25342ba | 2015-03-02 18:05:26 -0600 | [diff] [blame] | 442 | /// \param key may contain embedded nulls. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 443 | Value get(const std::string& key, const Value& defaultValue) const; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 444 | #ifdef JSON_USE_CPPTL |
| 445 | /// Return the member named key if it exist, defaultValue otherwise. |
Christopher Dunn | 0fd2875 | 2015-03-05 16:38:43 -0600 | [diff] [blame] | 446 | /// \note deep copy |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 447 | Value get(const CppTL::ConstString& key, const Value& defaultValue) const; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 448 | #endif |
Christopher Dunn | 25342ba | 2015-03-02 18:05:26 -0600 | [diff] [blame] | 449 | /// Most general and efficient version of isMember()const, get()const, |
| 450 | /// and operator[]const |
| 451 | /// \note As stated elsewhere, behavior is undefined if (end-key) >= 2^30 |
| 452 | Value const* find(char const* key, char const* end) const; |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 453 | /// Most general and efficient version of object-mutators. |
| 454 | /// \note As stated elsewhere, behavior is undefined if (end-key) >= 2^30 |
| 455 | /// \return non-zero, but JSON_ASSERT if this is neither object nor nullValue. |
| 456 | Value const* demand(char const* key, char const* end); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 457 | /// \brief Remove and return the named member. |
| 458 | /// |
| 459 | /// Do nothing if it did not exist. |
| 460 | /// \return the removed Value, or null. |
| 461 | /// \pre type() is objectValue or nullValue |
| 462 | /// \post type() is unchanged |
Christopher Dunn | 76746b0 | 2015-01-21 16:01:30 -0600 | [diff] [blame] | 463 | /// \deprecated |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 464 | Value removeMember(const char* key); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 465 | /// Same as removeMember(const char*) |
Christopher Dunn | 25342ba | 2015-03-02 18:05:26 -0600 | [diff] [blame] | 466 | /// \param key may contain embedded nulls. |
Christopher Dunn | 76746b0 | 2015-01-21 16:01:30 -0600 | [diff] [blame] | 467 | /// \deprecated |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 468 | Value removeMember(const std::string& key); |
Christopher Dunn | 25342ba | 2015-03-02 18:05:26 -0600 | [diff] [blame] | 469 | /// Same as removeMember(const char* key, const char* end, Value* removed), |
| 470 | /// but 'key' is null-terminated. |
| 471 | bool removeMember(const char* key, Value* removed); |
Christopher Dunn | 76746b0 | 2015-01-21 16:01:30 -0600 | [diff] [blame] | 472 | /** \brief Remove the named map member. |
| 473 | |
| 474 | Update 'removed' iff removed. |
Christopher Dunn | 25342ba | 2015-03-02 18:05:26 -0600 | [diff] [blame] | 475 | \param key may contain embedded nulls. |
Christopher Dunn | 76746b0 | 2015-01-21 16:01:30 -0600 | [diff] [blame] | 476 | \return true iff removed (no exceptions) |
| 477 | */ |
Christopher Dunn | 25342ba | 2015-03-02 18:05:26 -0600 | [diff] [blame] | 478 | bool removeMember(std::string const& key, Value* removed); |
| 479 | /// Same as removeMember(std::string const& key, Value* removed) |
| 480 | bool removeMember(const char* key, const char* end, Value* removed); |
Christopher Dunn | 9de2c2d | 2015-01-20 16:15:40 -0600 | [diff] [blame] | 481 | /** \brief Remove the indexed array element. |
| 482 | |
| 483 | O(n) expensive operations. |
| 484 | Update 'removed' iff removed. |
Christopher Dunn | e87e41c | 2015-01-20 16:24:11 -0600 | [diff] [blame] | 485 | \return true iff removed (no exceptions) |
Christopher Dunn | 9de2c2d | 2015-01-20 16:15:40 -0600 | [diff] [blame] | 486 | */ |
| 487 | bool removeIndex(ArrayIndex i, Value* removed); |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 488 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 489 | /// Return true if the object has a member named key. |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 490 | /// \note 'key' must be null-terminated. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 491 | bool isMember(const char* key) const; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 492 | /// Return true if the object has a member named key. |
Christopher Dunn | 25342ba | 2015-03-02 18:05:26 -0600 | [diff] [blame] | 493 | /// \param key may contain embedded nulls. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 494 | bool isMember(const std::string& key) const; |
Christopher Dunn | 25342ba | 2015-03-02 18:05:26 -0600 | [diff] [blame] | 495 | /// Same as isMember(std::string const& key)const |
| 496 | bool isMember(const char* key, const char* end) const; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 497 | #ifdef JSON_USE_CPPTL |
| 498 | /// Return true if the object has a member named key. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 499 | bool isMember(const CppTL::ConstString& key) const; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 500 | #endif |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 501 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 502 | /// \brief Return a list of the member names. |
| 503 | /// |
| 504 | /// If null, return an empty list. |
| 505 | /// \pre type() is objectValue or nullValue |
| 506 | /// \post if type() was nullValue, it remains nullValue |
| 507 | Members getMemberNames() const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 508 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 509 | //# ifdef JSON_USE_CPPTL |
| 510 | // EnumMemberNames enumMemberNames() const; |
| 511 | // EnumValues enumValues() const; |
| 512 | //# endif |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 513 | |
Christopher Dunn | 1e3149a | 2015-01-25 14:16:13 -0600 | [diff] [blame] | 514 | /// \deprecated Always pass len. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 515 | void setComment(const char* comment, CommentPlacement placement); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 516 | /// Comments must be //... or /* ... */ |
Christopher Dunn | 1e3149a | 2015-01-25 14:16:13 -0600 | [diff] [blame] | 517 | void setComment(const char* comment, size_t len, CommentPlacement placement); |
| 518 | /// Comments must be //... or /* ... */ |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 519 | void setComment(const std::string& comment, CommentPlacement placement); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 520 | bool hasComment(CommentPlacement placement) const; |
| 521 | /// Include delimiters and embedded newlines. |
| 522 | std::string getComment(CommentPlacement placement) const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 523 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 524 | std::string toStyledString() const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 525 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 526 | const_iterator begin() const; |
| 527 | const_iterator end() const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 528 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 529 | iterator begin(); |
| 530 | iterator end(); |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 531 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 532 | // Accessors for the [start, limit) range of bytes within the JSON text from |
| 533 | // which this value was parsed, if any. |
| 534 | void setOffsetStart(size_t start); |
| 535 | void setOffsetLimit(size_t limit); |
| 536 | size_t getOffsetStart() const; |
| 537 | size_t getOffsetLimit() const; |
Aaron Jacobs | 68db655 | 2014-04-23 23:41:12 +0000 | [diff] [blame] | 538 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 539 | private: |
Billy Donahue | 8eb5d89 | 2014-11-10 01:35:42 -0500 | [diff] [blame] | 540 | void initBasic(ValueType type, bool allocated = false); |
| 541 | |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 542 | Value& resolveReference(const char* key); |
| 543 | Value& resolveReference(const char* key, const char* end); |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 544 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 545 | struct CommentInfo { |
| 546 | CommentInfo(); |
| 547 | ~CommentInfo(); |
| 548 | |
Christopher Dunn | 1e3149a | 2015-01-25 14:16:13 -0600 | [diff] [blame] | 549 | void setComment(const char* text, size_t len); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 550 | |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 551 | char* comment_; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 552 | }; |
| 553 | |
| 554 | // struct MemberNamesTransform |
| 555 | //{ |
| 556 | // typedef const char *result_type; |
| 557 | // const char *operator()( const CZString &name ) const |
| 558 | // { |
| 559 | // return name.c_str(); |
| 560 | // } |
| 561 | //}; |
| 562 | |
| 563 | union ValueHolder { |
| 564 | LargestInt int_; |
| 565 | LargestUInt uint_; |
| 566 | double real_; |
| 567 | bool bool_; |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 568 | char* string_; // actually ptr to unsigned, followed by str, unless !allocated_ |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 569 | ObjectValues* map_; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 570 | } value_; |
| 571 | ValueType type_ : 8; |
Christopher Dunn | 2bc6137 | 2015-01-24 13:42:37 -0600 | [diff] [blame] | 572 | unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is useless. |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 573 | // If not allocated_, string_ must be null-terminated. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 574 | CommentInfo* comments_; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 575 | |
| 576 | // [start, limit) byte offsets in the source JSON text from which this Value |
| 577 | // was extracted. |
| 578 | size_t start_; |
| 579 | size_t limit_; |
| 580 | }; |
| 581 | |
| 582 | /** \brief Experimental and untested: represents an element of the "path" to |
| 583 | * access a node. |
| 584 | */ |
| 585 | class JSON_API PathArgument { |
| 586 | public: |
| 587 | friend class Path; |
| 588 | |
| 589 | PathArgument(); |
| 590 | PathArgument(ArrayIndex index); |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 591 | PathArgument(const char* key); |
| 592 | PathArgument(const std::string& key); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 593 | |
| 594 | private: |
| 595 | enum Kind { |
| 596 | kindNone = 0, |
| 597 | kindIndex, |
| 598 | kindKey |
| 599 | }; |
| 600 | std::string key_; |
| 601 | ArrayIndex index_; |
| 602 | Kind kind_; |
| 603 | }; |
| 604 | |
| 605 | /** \brief Experimental and untested: represents a "path" to access a node. |
| 606 | * |
| 607 | * Syntax: |
| 608 | * - "." => root node |
| 609 | * - ".[n]" => elements at index 'n' of root node (an array value) |
| 610 | * - ".name" => member named 'name' of root node (an object value) |
| 611 | * - ".name1.name2.name3" |
| 612 | * - ".[0][1][2].name1[3]" |
| 613 | * - ".%" => member name is provided as parameter |
| 614 | * - ".[%]" => index is provied as parameter |
| 615 | */ |
| 616 | class JSON_API Path { |
| 617 | public: |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 618 | Path(const std::string& path, |
| 619 | const PathArgument& a1 = PathArgument(), |
| 620 | const PathArgument& a2 = PathArgument(), |
| 621 | const PathArgument& a3 = PathArgument(), |
| 622 | const PathArgument& a4 = PathArgument(), |
| 623 | const PathArgument& a5 = PathArgument()); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 624 | |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 625 | const Value& resolve(const Value& root) const; |
| 626 | Value resolve(const Value& root, const Value& defaultValue) const; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 627 | /// Creates the "path" to access the specified node and returns a reference on |
| 628 | /// the node. |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 629 | Value& make(Value& root) const; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 630 | |
| 631 | private: |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 632 | typedef std::vector<const PathArgument*> InArgs; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 633 | typedef std::vector<PathArgument> Args; |
| 634 | |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 635 | void makePath(const std::string& path, const InArgs& in); |
| 636 | void addPathInArg(const std::string& path, |
| 637 | const InArgs& in, |
| 638 | InArgs::const_iterator& itInArg, |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 639 | PathArgument::Kind kind); |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 640 | void invalidPath(const std::string& path, int location); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 641 | |
| 642 | Args args_; |
| 643 | }; |
| 644 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 645 | /** \brief base class for Value iterators. |
| 646 | * |
| 647 | */ |
| 648 | class JSON_API ValueIteratorBase { |
| 649 | public: |
| 650 | typedef std::bidirectional_iterator_tag iterator_category; |
| 651 | typedef unsigned int size_t; |
| 652 | typedef int difference_type; |
| 653 | typedef ValueIteratorBase SelfType; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 654 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 655 | ValueIteratorBase(); |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 656 | explicit ValueIteratorBase(const Value::ObjectValues::iterator& current); |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 657 | |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 658 | bool operator==(const SelfType& other) const { return isEqual(other); } |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 659 | |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 660 | bool operator!=(const SelfType& other) const { return !isEqual(other); } |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 661 | |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 662 | difference_type operator-(const SelfType& other) const { |
Kevin Grant | 4c5832a | 2015-02-14 20:53:35 -0800 | [diff] [blame] | 663 | return other.computeDistance(*this); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 664 | } |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 665 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 666 | /// Return either the index or the member name of the referenced value as a |
| 667 | /// Value. |
| 668 | Value key() const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 669 | |
Christopher Dunn | ed495ed | 2015-03-08 14:01:28 -0500 | [diff] [blame^] | 670 | /// Return the index of the referenced Value, or -1 if it is not an arrayValue. |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 671 | UInt index() const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 672 | |
Christopher Dunn | ed495ed | 2015-03-08 14:01:28 -0500 | [diff] [blame^] | 673 | /// Return the member name of the referenced Value, or "" if it is not an |
| 674 | /// objectValue. |
| 675 | /// \note Avoid `c_str()` on result, as embedded zeroes are possible. |
| 676 | std::string name() const; |
| 677 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 678 | /// Return the member name of the referenced Value. "" if it is not an |
| 679 | /// objectValue. |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 680 | /// \deprecated This cannot be used for UTF-8 strings, since there can be embedded nulls. |
Christopher Dunn | ed495ed | 2015-03-08 14:01:28 -0500 | [diff] [blame^] | 681 | JSONCPP_DEPRECATED("Use `key = name();` instead.") |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 682 | char const* memberName() const; |
| 683 | /// Return the member name of the referenced Value, or NULL if it is not an |
| 684 | /// objectValue. |
Christopher Dunn | ed495ed | 2015-03-08 14:01:28 -0500 | [diff] [blame^] | 685 | /// \note Better version than memberName(). Allows embedded nulls. |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 686 | char const* memberName(char const** end) const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 687 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 688 | protected: |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 689 | Value& deref() const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 690 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 691 | void increment(); |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 692 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 693 | void decrement(); |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 694 | |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 695 | difference_type computeDistance(const SelfType& other) const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 696 | |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 697 | bool isEqual(const SelfType& other) const; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 698 | |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 699 | void copy(const SelfType& other); |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 700 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 701 | private: |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 702 | Value::ObjectValues::iterator current_; |
| 703 | // Indicates that iterator is for a null value. |
| 704 | bool isNull_; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 705 | }; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 706 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 707 | /** \brief const iterator for object and array value. |
| 708 | * |
| 709 | */ |
| 710 | class JSON_API ValueConstIterator : public ValueIteratorBase { |
| 711 | friend class Value; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 712 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 713 | public: |
| 714 | typedef const Value value_type; |
Christopher Dunn | c28610f | 2015-02-21 11:44:16 -0600 | [diff] [blame] | 715 | //typedef unsigned int size_t; |
| 716 | //typedef int difference_type; |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 717 | typedef const Value& reference; |
| 718 | typedef const Value* pointer; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 719 | typedef ValueConstIterator SelfType; |
| 720 | |
| 721 | ValueConstIterator(); |
| 722 | |
| 723 | private: |
| 724 | /*! \internal Use by Value to create an iterator. |
| 725 | */ |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 726 | explicit ValueConstIterator(const Value::ObjectValues::iterator& current); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 727 | public: |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 728 | SelfType& operator=(const ValueIteratorBase& other); |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 729 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 730 | SelfType operator++(int) { |
| 731 | SelfType temp(*this); |
| 732 | ++*this; |
| 733 | return temp; |
| 734 | } |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 735 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 736 | SelfType operator--(int) { |
| 737 | SelfType temp(*this); |
| 738 | --*this; |
| 739 | return temp; |
| 740 | } |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 741 | |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 742 | SelfType& operator--() { |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 743 | decrement(); |
| 744 | return *this; |
| 745 | } |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 746 | |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 747 | SelfType& operator++() { |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 748 | increment(); |
| 749 | return *this; |
| 750 | } |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 751 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 752 | reference operator*() const { return deref(); } |
Braden McDorman | 540db3b | 2014-09-14 02:31:23 -0500 | [diff] [blame] | 753 | |
| 754 | pointer operator->() const { return &deref(); } |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 755 | }; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 756 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 757 | /** \brief Iterator for object and array value. |
| 758 | */ |
| 759 | class JSON_API ValueIterator : public ValueIteratorBase { |
| 760 | friend class Value; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 761 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 762 | public: |
| 763 | typedef Value value_type; |
| 764 | typedef unsigned int size_t; |
| 765 | typedef int difference_type; |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 766 | typedef Value& reference; |
| 767 | typedef Value* pointer; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 768 | typedef ValueIterator SelfType; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 769 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 770 | ValueIterator(); |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 771 | ValueIterator(const ValueConstIterator& other); |
| 772 | ValueIterator(const ValueIterator& other); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 773 | |
| 774 | private: |
| 775 | /*! \internal Use by Value to create an iterator. |
| 776 | */ |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 777 | explicit ValueIterator(const Value::ObjectValues::iterator& current); |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 778 | public: |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 779 | SelfType& operator=(const SelfType& other); |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 780 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 781 | SelfType operator++(int) { |
| 782 | SelfType temp(*this); |
| 783 | ++*this; |
| 784 | return temp; |
| 785 | } |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 786 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 787 | SelfType operator--(int) { |
| 788 | SelfType temp(*this); |
| 789 | --*this; |
| 790 | return temp; |
| 791 | } |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 792 | |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 793 | SelfType& operator--() { |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 794 | decrement(); |
| 795 | return *this; |
| 796 | } |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 797 | |
Aaron Jacobs | 11086dd | 2014-09-15 10:15:29 +1000 | [diff] [blame] | 798 | SelfType& operator++() { |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 799 | increment(); |
| 800 | return *this; |
| 801 | } |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 802 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 803 | reference operator*() const { return deref(); } |
Braden McDorman | 540db3b | 2014-09-14 02:31:23 -0500 | [diff] [blame] | 804 | |
| 805 | pointer operator->() const { return &deref(); } |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 806 | }; |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 807 | |
| 808 | } // namespace Json |
| 809 | |
datadiode | 9454e68 | 2015-01-20 15:25:04 -0600 | [diff] [blame] | 810 | |
| 811 | namespace std { |
| 812 | /// Specialize std::swap() for Json::Value. |
| 813 | template<> |
| 814 | inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); } |
| 815 | } |
| 816 | |
| 817 | |
Baptiste Lepilleur | eafd702 | 2013-05-08 20:21:11 +0000 | [diff] [blame] | 818 | #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 819 | #pragma warning(pop) |
Baptiste Lepilleur | eafd702 | 2013-05-08 20:21:11 +0000 | [diff] [blame] | 820 | #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) |
| 821 | |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 822 | #endif // CPPTL_JSON_H_INCLUDED |