|
||||
File indexing completed on 2025-01-18 09:15:01
0001 /// Json-cpp amalgamated header (http://jsoncpp.sourceforge.net/). 0002 /// It is intended to be used with #include "json/json.h" 0003 0004 // ////////////////////////////////////////////////////////////////////// 0005 // Beginning of content of file: LICENSE 0006 // ////////////////////////////////////////////////////////////////////// 0007 0008 /* 0009 The JsonCpp library's source code, including accompanying documentation, 0010 tests and demonstration applications, are licensed under the following 0011 conditions... 0012 0013 Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all 0014 jurisdictions which recognize such a disclaimer. In such jurisdictions, 0015 this software is released into the Public Domain. 0016 0017 In jurisdictions which do not recognize Public Domain property (e.g. Germany as of 0018 2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and 0019 The JsonCpp Authors, and is released under the terms of the MIT License (see below). 0020 0021 In jurisdictions which recognize Public Domain property, the user of this 0022 software may choose to accept it either as 1) Public Domain, 2) under the 0023 conditions of the MIT License (see below), or 3) under the terms of dual 0024 Public Domain/MIT License conditions described here, as they choose. 0025 0026 The MIT License is about as close to Public Domain as a license can get, and is 0027 described in clear, concise terms at: 0028 0029 http://en.wikipedia.org/wiki/MIT_License 0030 0031 The full text of the MIT License follows: 0032 0033 ======================================================================== 0034 Copyright (c) 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 0035 0036 Permission is hereby granted, free of charge, to any person 0037 obtaining a copy of this software and associated documentation 0038 files (the "Software"), to deal in the Software without 0039 restriction, including without limitation the rights to use, copy, 0040 modify, merge, publish, distribute, sublicense, and/or sell copies 0041 of the Software, and to permit persons to whom the Software is 0042 furnished to do so, subject to the following conditions: 0043 0044 The above copyright notice and this permission notice shall be 0045 included in all copies or substantial portions of the Software. 0046 0047 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 0048 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 0049 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 0050 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 0051 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 0052 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 0053 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0054 SOFTWARE. 0055 ======================================================================== 0056 (END LICENSE TEXT) 0057 0058 The MIT license is compatible with both the GPL and commercial 0059 software, affording one all of the rights of Public Domain with the 0060 minor nuisance of being required to keep the above copyright notice 0061 and license text in the source code. Note also that by accepting the 0062 Public Domain "license" you can re-license your copy using whatever 0063 license you like. 0064 0065 */ 0066 0067 // ////////////////////////////////////////////////////////////////////// 0068 // End of content of file: LICENSE 0069 // ////////////////////////////////////////////////////////////////////// 0070 0071 0072 0073 0074 0075 #ifndef JSON_AMALGAMATED_H_INCLUDED 0076 # define JSON_AMALGAMATED_H_INCLUDED 0077 /// If defined, indicates that the source file is amalgamated 0078 /// to prevent private header inclusion. 0079 #define JSON_IS_AMALGAMATION 0080 0081 // ////////////////////////////////////////////////////////////////////// 0082 // Beginning of content of file: include/json/version.h 0083 // ////////////////////////////////////////////////////////////////////// 0084 0085 // DO NOT EDIT. This file (and "version") is generated by CMake. 0086 // Run CMake configure step to update it. 0087 #ifndef JSON_VERSION_H_INCLUDED 0088 # define JSON_VERSION_H_INCLUDED 0089 0090 # define JSONCPP_VERSION_STRING "1.8.4" 0091 # define JSONCPP_VERSION_MAJOR 1 0092 # define JSONCPP_VERSION_MINOR 8 0093 # define JSONCPP_VERSION_PATCH 4 0094 # define JSONCPP_VERSION_QUALIFIER 0095 # define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8)) 0096 0097 #ifdef JSONCPP_USING_SECURE_MEMORY 0098 #undef JSONCPP_USING_SECURE_MEMORY 0099 #endif 0100 #define JSONCPP_USING_SECURE_MEMORY 0 0101 // If non-zero, the library zeroes any memory that it has allocated before 0102 // it frees its memory. 0103 0104 #endif // JSON_VERSION_H_INCLUDED 0105 0106 // ////////////////////////////////////////////////////////////////////// 0107 // End of content of file: include/json/version.h 0108 // ////////////////////////////////////////////////////////////////////// 0109 0110 0111 0112 0113 0114 0115 // ////////////////////////////////////////////////////////////////////// 0116 // Beginning of content of file: include/json/config.h 0117 // ////////////////////////////////////////////////////////////////////// 0118 0119 // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 0120 // Distributed under MIT license, or public domain if desired and 0121 // recognized in your jurisdiction. 0122 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 0123 0124 #ifndef JSON_CONFIG_H_INCLUDED 0125 #define JSON_CONFIG_H_INCLUDED 0126 #include <stddef.h> 0127 #include <string> //typedef String 0128 #include <stdint.h> //typedef int64_t, uint64_t 0129 0130 /// If defined, indicates that json library is embedded in CppTL library. 0131 //# define JSON_IN_CPPTL 1 0132 0133 /// If defined, indicates that json may leverage CppTL library 0134 //# define JSON_USE_CPPTL 1 0135 /// If defined, indicates that cpptl vector based map should be used instead of 0136 /// std::map 0137 /// as Value container. 0138 //# define JSON_USE_CPPTL_SMALLMAP 1 0139 0140 // If non-zero, the library uses exceptions to report bad input instead of C 0141 // assertion macros. The default is to use exceptions. 0142 #ifndef JSON_USE_EXCEPTION 0143 #define JSON_USE_EXCEPTION 1 0144 #endif 0145 0146 /// If defined, indicates that the source file is amalgamated 0147 /// to prevent private header inclusion. 0148 /// Remarks: it is automatically defined in the generated amalgamated header. 0149 // #define JSON_IS_AMALGAMATION 0150 0151 #ifdef JSON_IN_CPPTL 0152 #include <cpptl/config.h> 0153 #ifndef JSON_USE_CPPTL 0154 #define JSON_USE_CPPTL 1 0155 #endif 0156 #endif 0157 0158 #ifdef JSON_IN_CPPTL 0159 #define JSON_API CPPTL_API 0160 #elif defined(JSON_DLL_BUILD) 0161 #if defined(_MSC_VER) || defined(__MINGW32__) 0162 #define JSON_API __declspec(dllexport) 0163 #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING 0164 #endif // if defined(_MSC_VER) 0165 #elif defined(JSON_DLL) 0166 #if defined(_MSC_VER) || defined(__MINGW32__) 0167 #define JSON_API __declspec(dllimport) 0168 #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING 0169 #endif // if defined(_MSC_VER) 0170 #endif // ifdef JSON_IN_CPPTL 0171 #if !defined(JSON_API) 0172 #define JSON_API 0173 #endif 0174 0175 // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for 0176 // integer 0177 // Storages, and 64 bits integer support is disabled. 0178 // #define JSON_NO_INT64 1 0179 0180 #if defined(_MSC_VER) // MSVC 0181 # if _MSC_VER <= 1200 // MSVC 6 0182 // Microsoft Visual Studio 6 only support conversion from __int64 to double 0183 // (no conversion from unsigned __int64). 0184 # define JSON_USE_INT64_DOUBLE_CONVERSION 1 0185 // Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255' 0186 // characters in the debug information) 0187 // All projects I've ever seen with VS6 were using this globally (not bothering 0188 // with pragma push/pop). 0189 # pragma warning(disable : 4786) 0190 # endif // MSVC 6 0191 0192 # if _MSC_VER >= 1500 // MSVC 2008 0193 /// Indicates that the following function is deprecated. 0194 # define JSONCPP_DEPRECATED(message) __declspec(deprecated(message)) 0195 # endif 0196 0197 #endif // defined(_MSC_VER) 0198 0199 // In c++11 the override keyword allows you to explicitly define that a function 0200 // is intended to override the base-class version. This makes the code more 0201 // manageable and fixes a set of common hard-to-find bugs. 0202 #if __cplusplus >= 201103L 0203 # define JSONCPP_OVERRIDE override 0204 # define JSONCPP_NOEXCEPT noexcept 0205 # define JSONCPP_OP_EXPLICIT explicit 0206 #elif defined(_MSC_VER) && _MSC_VER > 1600 && _MSC_VER < 1900 0207 # define JSONCPP_OVERRIDE override 0208 # define JSONCPP_NOEXCEPT throw() 0209 # if _MSC_VER >= 1800 // MSVC 2013 0210 # define JSONCPP_OP_EXPLICIT explicit 0211 # else 0212 # define JSONCPP_OP_EXPLICIT 0213 # endif 0214 #elif defined(_MSC_VER) && _MSC_VER >= 1900 0215 # define JSONCPP_OVERRIDE override 0216 # define JSONCPP_NOEXCEPT noexcept 0217 # define JSONCPP_OP_EXPLICIT explicit 0218 #else 0219 # define JSONCPP_OVERRIDE 0220 # define JSONCPP_NOEXCEPT throw() 0221 # define JSONCPP_OP_EXPLICIT 0222 #endif 0223 0224 #ifndef JSON_HAS_RVALUE_REFERENCES 0225 0226 #if defined(_MSC_VER) && _MSC_VER >= 1600 // MSVC >= 2010 0227 #define JSON_HAS_RVALUE_REFERENCES 1 0228 #endif // MSVC >= 2010 0229 0230 #ifdef __clang__ 0231 #if __has_feature(cxx_rvalue_references) 0232 #define JSON_HAS_RVALUE_REFERENCES 1 0233 #endif // has_feature 0234 0235 #elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc) 0236 #if defined(__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L) 0237 #define JSON_HAS_RVALUE_REFERENCES 1 0238 #endif // GXX_EXPERIMENTAL 0239 0240 #endif // __clang__ || __GNUC__ 0241 0242 #endif // not defined JSON_HAS_RVALUE_REFERENCES 0243 0244 #ifndef JSON_HAS_RVALUE_REFERENCES 0245 #define JSON_HAS_RVALUE_REFERENCES 0 0246 #endif 0247 0248 #ifdef __clang__ 0249 # if __has_extension(attribute_deprecated_with_message) 0250 # define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message))) 0251 # endif 0252 #elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc) 0253 # if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) 0254 # define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message))) 0255 # elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) 0256 # define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__)) 0257 # endif // GNUC version 0258 #endif // __clang__ || __GNUC__ 0259 0260 #if !defined(JSONCPP_DEPRECATED) 0261 #define JSONCPP_DEPRECATED(message) 0262 #endif // if !defined(JSONCPP_DEPRECATED) 0263 0264 #if __GNUC__ >= 6 0265 # define JSON_USE_INT64_DOUBLE_CONVERSION 1 0266 #endif 0267 0268 #if !defined(JSON_IS_AMALGAMATION) 0269 0270 # include "version.h" 0271 0272 # if JSONCPP_USING_SECURE_MEMORY 0273 # include "allocator.h" //typedef Allocator 0274 # endif 0275 0276 #endif // if !defined(JSON_IS_AMALGAMATION) 0277 0278 namespace Json { 0279 typedef int Int; 0280 typedef unsigned int UInt; 0281 #if defined(JSON_NO_INT64) 0282 typedef int LargestInt; 0283 typedef unsigned int LargestUInt; 0284 #undef JSON_HAS_INT64 0285 #else // if defined(JSON_NO_INT64) 0286 // For Microsoft Visual use specific types as long long is not supported 0287 #if defined(_MSC_VER) // Microsoft Visual Studio 0288 typedef __int64 Int64; 0289 typedef unsigned __int64 UInt64; 0290 #else // if defined(_MSC_VER) // Other platforms, use long long 0291 typedef int64_t Int64; 0292 typedef uint64_t UInt64; 0293 #endif // if defined(_MSC_VER) 0294 typedef Int64 LargestInt; 0295 typedef UInt64 LargestUInt; 0296 #define JSON_HAS_INT64 0297 #endif // if defined(JSON_NO_INT64) 0298 #if JSONCPP_USING_SECURE_MEMORY 0299 #define JSONCPP_STRING std::basic_string<char, std::char_traits<char>, Json::SecureAllocator<char> > 0300 #define JSONCPP_OSTRINGSTREAM std::basic_ostringstream<char, std::char_traits<char>, Json::SecureAllocator<char> > 0301 #define JSONCPP_OSTREAM std::basic_ostream<char, std::char_traits<char>> 0302 #define JSONCPP_ISTRINGSTREAM std::basic_istringstream<char, std::char_traits<char>, Json::SecureAllocator<char> > 0303 #define JSONCPP_ISTREAM std::istream 0304 #else 0305 #define JSONCPP_STRING std::string 0306 #define JSONCPP_OSTRINGSTREAM std::ostringstream 0307 #define JSONCPP_OSTREAM std::ostream 0308 #define JSONCPP_ISTRINGSTREAM std::istringstream 0309 #define JSONCPP_ISTREAM std::istream 0310 #endif // if JSONCPP_USING_SECURE_MEMORY 0311 } // end namespace Json 0312 0313 #endif // JSON_CONFIG_H_INCLUDED 0314 0315 // ////////////////////////////////////////////////////////////////////// 0316 // End of content of file: include/json/config.h 0317 // ////////////////////////////////////////////////////////////////////// 0318 0319 0320 0321 0322 0323 0324 // ////////////////////////////////////////////////////////////////////// 0325 // Beginning of content of file: include/json/forwards.h 0326 // ////////////////////////////////////////////////////////////////////// 0327 0328 // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 0329 // Distributed under MIT license, or public domain if desired and 0330 // recognized in your jurisdiction. 0331 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 0332 0333 #ifndef JSON_FORWARDS_H_INCLUDED 0334 #define JSON_FORWARDS_H_INCLUDED 0335 0336 #if !defined(JSON_IS_AMALGAMATION) 0337 #include "config.h" 0338 #endif // if !defined(JSON_IS_AMALGAMATION) 0339 0340 namespace Json { 0341 0342 // writer.h 0343 class FastWriter; 0344 class StyledWriter; 0345 0346 // reader.h 0347 class Reader; 0348 0349 // features.h 0350 class Features; 0351 0352 // value.h 0353 typedef unsigned int ArrayIndex; 0354 class StaticString; 0355 class Path; 0356 class PathArgument; 0357 class Value; 0358 class ValueIteratorBase; 0359 class ValueIterator; 0360 class ValueConstIterator; 0361 0362 } // namespace Json 0363 0364 #endif // JSON_FORWARDS_H_INCLUDED 0365 0366 // ////////////////////////////////////////////////////////////////////// 0367 // End of content of file: include/json/forwards.h 0368 // ////////////////////////////////////////////////////////////////////// 0369 0370 0371 0372 0373 0374 0375 // ////////////////////////////////////////////////////////////////////// 0376 // Beginning of content of file: include/json/features.h 0377 // ////////////////////////////////////////////////////////////////////// 0378 0379 // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 0380 // Distributed under MIT license, or public domain if desired and 0381 // recognized in your jurisdiction. 0382 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 0383 0384 #ifndef CPPTL_JSON_FEATURES_H_INCLUDED 0385 #define CPPTL_JSON_FEATURES_H_INCLUDED 0386 0387 #if !defined(JSON_IS_AMALGAMATION) 0388 #include "forwards.h" 0389 #endif // if !defined(JSON_IS_AMALGAMATION) 0390 0391 #pragma pack(push, 8) 0392 0393 namespace Json { 0394 0395 /** \brief Configuration passed to reader and writer. 0396 * This configuration object can be used to force the Reader or Writer 0397 * to behave in a standard conforming way. 0398 */ 0399 class JSON_API Features { 0400 public: 0401 /** \brief A configuration that allows all features and assumes all strings 0402 * are UTF-8. 0403 * - C & C++ comments are allowed 0404 * - Root object can be any JSON value 0405 * - Assumes Value strings are encoded in UTF-8 0406 */ 0407 static Features all(); 0408 0409 /** \brief A configuration that is strictly compatible with the JSON 0410 * specification. 0411 * - Comments are forbidden. 0412 * - Root object must be either an array or an object value. 0413 * - Assumes Value strings are encoded in UTF-8 0414 */ 0415 static Features strictMode(); 0416 0417 /** \brief Initialize the configuration like JsonConfig::allFeatures; 0418 */ 0419 Features(); 0420 0421 /// \c true if comments are allowed. Default: \c true. 0422 bool allowComments_; 0423 0424 /// \c true if root must be either an array or an object value. Default: \c 0425 /// false. 0426 bool strictRoot_; 0427 0428 /// \c true if dropped null placeholders are allowed. Default: \c false. 0429 bool allowDroppedNullPlaceholders_; 0430 0431 /// \c true if numeric object key are allowed. Default: \c false. 0432 bool allowNumericKeys_; 0433 }; 0434 0435 } // namespace Json 0436 0437 #pragma pack(pop) 0438 0439 #endif // CPPTL_JSON_FEATURES_H_INCLUDED 0440 0441 // ////////////////////////////////////////////////////////////////////// 0442 // End of content of file: include/json/features.h 0443 // ////////////////////////////////////////////////////////////////////// 0444 0445 0446 0447 0448 0449 0450 // ////////////////////////////////////////////////////////////////////// 0451 // Beginning of content of file: include/json/value.h 0452 // ////////////////////////////////////////////////////////////////////// 0453 0454 // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 0455 // Distributed under MIT license, or public domain if desired and 0456 // recognized in your jurisdiction. 0457 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 0458 0459 #ifndef CPPTL_JSON_H_INCLUDED 0460 #define CPPTL_JSON_H_INCLUDED 0461 0462 #if !defined(JSON_IS_AMALGAMATION) 0463 #include "forwards.h" 0464 #endif // if !defined(JSON_IS_AMALGAMATION) 0465 #include <string> 0466 #include <vector> 0467 #include <exception> 0468 0469 #ifndef JSON_USE_CPPTL_SMALLMAP 0470 #include <map> 0471 #else 0472 #include <cpptl/smallmap.h> 0473 #endif 0474 #ifdef JSON_USE_CPPTL 0475 #include <cpptl/forwards.h> 0476 #endif 0477 0478 //Conditional NORETURN attribute on the throw functions would: 0479 // a) suppress false positives from static code analysis 0480 // b) possibly improve optimization opportunities. 0481 #if !defined(JSONCPP_NORETURN) 0482 # if defined(_MSC_VER) 0483 # define JSONCPP_NORETURN __declspec(noreturn) 0484 # elif defined(__GNUC__) 0485 # define JSONCPP_NORETURN __attribute__ ((__noreturn__)) 0486 # else 0487 # define JSONCPP_NORETURN 0488 # endif 0489 #endif 0490 0491 // Disable warning C4251: <data member>: <type> needs to have dll-interface to 0492 // be used by... 0493 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 0494 #pragma warning(push) 0495 #pragma warning(disable : 4251) 0496 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 0497 0498 #pragma pack(push, 8) 0499 0500 /** \brief JSON (JavaScript Object Notation). 0501 */ 0502 namespace Json { 0503 0504 /** Base class for all exceptions we throw. 0505 * 0506 * We use nothing but these internally. Of course, STL can throw others. 0507 */ 0508 class JSON_API Exception : public std::exception { 0509 public: 0510 Exception(JSONCPP_STRING const& msg); 0511 ~Exception() JSONCPP_NOEXCEPT JSONCPP_OVERRIDE; 0512 char const* what() const JSONCPP_NOEXCEPT JSONCPP_OVERRIDE; 0513 protected: 0514 JSONCPP_STRING msg_; 0515 }; 0516 0517 /** Exceptions which the user cannot easily avoid. 0518 * 0519 * E.g. out-of-memory (when we use malloc), stack-overflow, malicious input 0520 * 0521 * \remark derived from Json::Exception 0522 */ 0523 class JSON_API RuntimeError : public Exception { 0524 public: 0525 RuntimeError(JSONCPP_STRING const& msg); 0526 }; 0527 0528 /** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros. 0529 * 0530 * These are precondition-violations (user bugs) and internal errors (our bugs). 0531 * 0532 * \remark derived from Json::Exception 0533 */ 0534 class JSON_API LogicError : public Exception { 0535 public: 0536 LogicError(JSONCPP_STRING const& msg); 0537 }; 0538 0539 /// used internally 0540 JSONCPP_NORETURN void throwRuntimeError(JSONCPP_STRING const& msg); 0541 /// used internally 0542 JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const& msg); 0543 0544 /** \brief Type of the value held by a Value object. 0545 */ 0546 enum ValueType { 0547 nullValue = 0, ///< 'null' value 0548 intValue, ///< signed integer value 0549 uintValue, ///< unsigned integer value 0550 realValue, ///< double value 0551 stringValue, ///< UTF-8 string value 0552 booleanValue, ///< bool value 0553 arrayValue, ///< array value (ordered list) 0554 objectValue ///< object value (collection of name/value pairs). 0555 }; 0556 0557 enum CommentPlacement { 0558 commentBefore = 0, ///< a comment placed on the line before a value 0559 commentAfterOnSameLine, ///< a comment just after a value on the same line 0560 commentAfter, ///< a comment on the line after a value (only make sense for 0561 /// root value) 0562 numberOfCommentPlacement 0563 }; 0564 0565 /** \brief Type of precision for formatting of real values. 0566 */ 0567 enum PrecisionType { 0568 significantDigits = 0, ///< we set max number of significant digits in string 0569 decimalPlaces ///< we set max number of digits after "." in string 0570 }; 0571 0572 //# ifdef JSON_USE_CPPTL 0573 // typedef CppTL::AnyEnumerator<const char *> EnumMemberNames; 0574 // typedef CppTL::AnyEnumerator<const Value &> EnumValues; 0575 //# endif 0576 0577 /** \brief Lightweight wrapper to tag static string. 0578 * 0579 * Value constructor and objectValue member assignment takes advantage of the 0580 * StaticString and avoid the cost of string duplication when storing the 0581 * string or the member name. 0582 * 0583 * Example of usage: 0584 * \code 0585 * Json::Value aValue( StaticString("some text") ); 0586 * Json::Value object; 0587 * static const StaticString code("code"); 0588 * object[code] = 1234; 0589 * \endcode 0590 */ 0591 class JSON_API StaticString { 0592 public: 0593 explicit StaticString(const char* czstring) : c_str_(czstring) {} 0594 0595 operator const char*() const { return c_str_; } 0596 0597 const char* c_str() const { return c_str_; } 0598 0599 private: 0600 const char* c_str_; 0601 }; 0602 0603 /** \brief Represents a <a HREF="http://www.json.org">JSON</a> value. 0604 * 0605 * This class is a discriminated union wrapper that can represents a: 0606 * - signed integer [range: Value::minInt - Value::maxInt] 0607 * - unsigned integer (range: 0 - Value::maxUInt) 0608 * - double 0609 * - UTF-8 string 0610 * - boolean 0611 * - 'null' 0612 * - an ordered list of Value 0613 * - collection of name/value pairs (javascript object) 0614 * 0615 * The type of the held value is represented by a #ValueType and 0616 * can be obtained using type(). 0617 * 0618 * Values of an #objectValue or #arrayValue can be accessed using operator[]() 0619 * methods. 0620 * Non-const methods will automatically create the a #nullValue element 0621 * if it does not exist. 0622 * The sequence of an #arrayValue will be automatically resized and initialized 0623 * with #nullValue. resize() can be used to enlarge or truncate an #arrayValue. 0624 * 0625 * The get() methods can be used to obtain default value in the case the 0626 * required element does not exist. 0627 * 0628 * It is possible to iterate over the list of a #objectValue values using 0629 * the getMemberNames() method. 0630 * 0631 * \note #Value string-length fit in size_t, but keys must be < 2^30. 0632 * (The reason is an implementation detail.) A #CharReader will raise an 0633 * exception if a bound is exceeded to avoid security holes in your app, 0634 * but the Value API does *not* check bounds. That is the responsibility 0635 * of the caller. 0636 */ 0637 class JSON_API Value { 0638 friend class ValueIteratorBase; 0639 public: 0640 typedef std::vector<JSONCPP_STRING> Members; 0641 typedef ValueIterator iterator; 0642 typedef ValueConstIterator const_iterator; 0643 typedef Json::UInt UInt; 0644 typedef Json::Int Int; 0645 #if defined(JSON_HAS_INT64) 0646 typedef Json::UInt64 UInt64; 0647 typedef Json::Int64 Int64; 0648 #endif // defined(JSON_HAS_INT64) 0649 typedef Json::LargestInt LargestInt; 0650 typedef Json::LargestUInt LargestUInt; 0651 typedef Json::ArrayIndex ArrayIndex; 0652 0653 // Required for boost integration, e. g. BOOST_TEST 0654 typedef std::string value_type; 0655 0656 static const Value& null; ///< We regret this reference to a global instance; prefer the simpler Value(). 0657 static const Value& nullRef; ///< just a kludge for binary-compatibility; same as null 0658 static Value const& nullSingleton(); ///< Prefer this to null or nullRef. 0659 0660 /// Minimum signed integer value that can be stored in a Json::Value. 0661 static const LargestInt minLargestInt; 0662 /// Maximum signed integer value that can be stored in a Json::Value. 0663 static const LargestInt maxLargestInt; 0664 /// Maximum unsigned integer value that can be stored in a Json::Value. 0665 static const LargestUInt maxLargestUInt; 0666 0667 /// Minimum signed int value that can be stored in a Json::Value. 0668 static const Int minInt; 0669 /// Maximum signed int value that can be stored in a Json::Value. 0670 static const Int maxInt; 0671 /// Maximum unsigned int value that can be stored in a Json::Value. 0672 static const UInt maxUInt; 0673 0674 #if defined(JSON_HAS_INT64) 0675 /// Minimum signed 64 bits int value that can be stored in a Json::Value. 0676 static const Int64 minInt64; 0677 /// Maximum signed 64 bits int value that can be stored in a Json::Value. 0678 static const Int64 maxInt64; 0679 /// Maximum unsigned 64 bits int value that can be stored in a Json::Value. 0680 static const UInt64 maxUInt64; 0681 #endif // defined(JSON_HAS_INT64) 0682 0683 /// Default precision for real value for string representation. 0684 static const UInt defaultRealPrecision; 0685 0686 // Workaround for bug in the NVIDIAs CUDA 9.1 nvcc compiler 0687 // when using gcc and clang backend compilers. CZString 0688 // cannot be defined as private. See issue #486 0689 #ifdef __NVCC__ 0690 public: 0691 #else 0692 private: 0693 #endif 0694 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION 0695 class CZString { 0696 public: 0697 enum DuplicationPolicy { 0698 noDuplication = 0, 0699 duplicate, 0700 duplicateOnCopy 0701 }; 0702 CZString(ArrayIndex index); 0703 CZString(char const* str, unsigned length, DuplicationPolicy allocate); 0704 CZString(CZString const& other); 0705 #if JSON_HAS_RVALUE_REFERENCES 0706 CZString(CZString&& other); 0707 #endif 0708 ~CZString(); 0709 CZString& operator=(const CZString& other); 0710 0711 #if JSON_HAS_RVALUE_REFERENCES 0712 CZString& operator=(CZString&& other); 0713 #endif 0714 0715 bool operator<(CZString const& other) const; 0716 bool operator==(CZString const& other) const; 0717 ArrayIndex index() const; 0718 //const char* c_str() const; ///< \deprecated 0719 char const* data() const; 0720 unsigned length() const; 0721 bool isStaticString() const; 0722 0723 private: 0724 void swap(CZString& other); 0725 0726 struct StringStorage { 0727 unsigned policy_: 2; 0728 unsigned length_: 30; // 1GB max 0729 }; 0730 0731 char const* cstr_; // actually, a prefixed string, unless policy is noDup 0732 union { 0733 ArrayIndex index_; 0734 StringStorage storage_; 0735 }; 0736 }; 0737 0738 public: 0739 #ifndef JSON_USE_CPPTL_SMALLMAP 0740 typedef std::map<CZString, Value> ObjectValues; 0741 #else 0742 typedef CppTL::SmallMap<CZString, Value> ObjectValues; 0743 #endif // ifndef JSON_USE_CPPTL_SMALLMAP 0744 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION 0745 0746 public: 0747 /** \brief Create a default Value of the given type. 0748 0749 This is a very useful constructor. 0750 To create an empty array, pass arrayValue. 0751 To create an empty object, pass objectValue. 0752 Another Value can then be set to this one by assignment. 0753 This is useful since clear() and resize() will not alter types. 0754 0755 Examples: 0756 \code 0757 Json::Value null_value; // null 0758 Json::Value arr_value(Json::arrayValue); // [] 0759 Json::Value obj_value(Json::objectValue); // {} 0760 \endcode 0761 */ 0762 Value(ValueType type = nullValue); 0763 Value(Int value); 0764 Value(UInt value); 0765 #if defined(JSON_HAS_INT64) 0766 Value(Int64 value); 0767 Value(UInt64 value); 0768 #endif // if defined(JSON_HAS_INT64) 0769 Value(double value); 0770 Value(const char* value); ///< Copy til first 0. (NULL causes to seg-fault.) 0771 Value(const char* begin, const char* end); ///< Copy all, incl zeroes. 0772 /** \brief Constructs a value from a static string. 0773 0774 * Like other value string constructor but do not duplicate the string for 0775 * internal storage. The given string must remain alive after the call to this 0776 * constructor. 0777 * \note This works only for null-terminated strings. (We cannot change the 0778 * size of this class, so we have nowhere to store the length, 0779 * which might be computed later for various operations.) 0780 * 0781 * Example of usage: 0782 * \code 0783 * static StaticString foo("some text"); 0784 * Json::Value aValue(foo); 0785 * \endcode 0786 */ 0787 Value(const StaticString& value); 0788 Value(const JSONCPP_STRING& value); ///< Copy data() til size(). Embedded zeroes too. 0789 #ifdef JSON_USE_CPPTL 0790 Value(const CppTL::ConstString& value); 0791 #endif 0792 Value(bool value); 0793 /// Deep copy. 0794 Value(const Value& other); 0795 #if JSON_HAS_RVALUE_REFERENCES 0796 /// Move constructor 0797 Value(Value&& other); 0798 #endif 0799 ~Value(); 0800 0801 /// Deep copy, then swap(other). 0802 /// \note Over-write existing comments. To preserve comments, use #swapPayload(). 0803 Value& operator=(Value other); 0804 0805 /// Swap everything. 0806 void swap(Value& other); 0807 /// Swap values but leave comments and source offsets in place. 0808 void swapPayload(Value& other); 0809 0810 /// copy everything. 0811 void copy(const Value& other); 0812 /// copy values but leave comments and source offsets in place. 0813 void copyPayload(const Value& other); 0814 0815 ValueType type() const; 0816 0817 /// Compare payload only, not comments etc. 0818 bool operator<(const Value& other) const; 0819 bool operator<=(const Value& other) const; 0820 bool operator>=(const Value& other) const; 0821 bool operator>(const Value& other) const; 0822 bool operator==(const Value& other) const; 0823 bool operator!=(const Value& other) const; 0824 int compare(const Value& other) const; 0825 0826 const char* asCString() const; ///< Embedded zeroes could cause you trouble! 0827 #if JSONCPP_USING_SECURE_MEMORY 0828 unsigned getCStringLength() const; //Allows you to understand the length of the CString 0829 #endif 0830 JSONCPP_STRING asString() const; ///< Embedded zeroes are possible. 0831 /** Get raw char* of string-value. 0832 * \return false if !string. (Seg-fault if str or end are NULL.) 0833 */ 0834 bool getString( 0835 char const** begin, char const** end) const; 0836 #ifdef JSON_USE_CPPTL 0837 CppTL::ConstString asConstString() const; 0838 #endif 0839 Int asInt() const; 0840 UInt asUInt() const; 0841 #if defined(JSON_HAS_INT64) 0842 Int64 asInt64() const; 0843 UInt64 asUInt64() const; 0844 #endif // if defined(JSON_HAS_INT64) 0845 LargestInt asLargestInt() const; 0846 LargestUInt asLargestUInt() const; 0847 float asFloat() const; 0848 double asDouble() const; 0849 bool asBool() const; 0850 0851 bool isNull() const; 0852 bool isBool() const; 0853 bool isInt() const; 0854 bool isInt64() const; 0855 bool isUInt() const; 0856 bool isUInt64() const; 0857 bool isIntegral() const; 0858 bool isDouble() const; 0859 bool isNumeric() const; 0860 bool isString() const; 0861 bool isArray() const; 0862 bool isObject() const; 0863 0864 bool isConvertibleTo(ValueType other) const; 0865 0866 /// Number of values in array or object 0867 ArrayIndex size() const; 0868 0869 /// \brief Return true if empty array, empty object, or null; 0870 /// otherwise, false. 0871 bool empty() const; 0872 0873 /// Return !isNull() 0874 JSONCPP_OP_EXPLICIT operator bool() const; 0875 0876 /// Remove all object members and array elements. 0877 /// \pre type() is arrayValue, objectValue, or nullValue 0878 /// \post type() is unchanged 0879 void clear(); 0880 0881 /// Resize the array to size elements. 0882 /// New elements are initialized to null. 0883 /// May only be called on nullValue or arrayValue. 0884 /// \pre type() is arrayValue or nullValue 0885 /// \post type() is arrayValue 0886 void resize(ArrayIndex size); 0887 0888 /// Access an array element (zero based index ). 0889 /// If the array contains less than index element, then null value are 0890 /// inserted 0891 /// in the array so that its size is index+1. 0892 /// (You may need to say 'value[0u]' to get your compiler to distinguish 0893 /// this from the operator[] which takes a string.) 0894 Value& operator[](ArrayIndex index); 0895 0896 /// Access an array element (zero based index ). 0897 /// If the array contains less than index element, then null value are 0898 /// inserted 0899 /// in the array so that its size is index+1. 0900 /// (You may need to say 'value[0u]' to get your compiler to distinguish 0901 /// this from the operator[] which takes a string.) 0902 Value& operator[](int index); 0903 0904 /// Access an array element (zero based index ) 0905 /// (You may need to say 'value[0u]' to get your compiler to distinguish 0906 /// this from the operator[] which takes a string.) 0907 const Value& operator[](ArrayIndex index) const; 0908 0909 /// Access an array element (zero based index ) 0910 /// (You may need to say 'value[0u]' to get your compiler to distinguish 0911 /// this from the operator[] which takes a string.) 0912 const Value& operator[](int index) const; 0913 0914 /// If the array contains at least index+1 elements, returns the element 0915 /// value, 0916 /// otherwise returns defaultValue. 0917 Value get(ArrayIndex index, const Value& defaultValue) const; 0918 /// Return true if index < size(). 0919 bool isValidIndex(ArrayIndex index) const; 0920 /// \brief Append value to array at the end. 0921 /// 0922 /// Equivalent to jsonvalue[jsonvalue.size()] = value; 0923 Value& append(const Value& value); 0924 0925 #if JSON_HAS_RVALUE_REFERENCES 0926 Value& append(Value&& value); 0927 #endif 0928 0929 /// Access an object value by name, create a null member if it does not exist. 0930 /// \note Because of our implementation, keys are limited to 2^30 -1 chars. 0931 /// Exceeding that will cause an exception. 0932 Value& operator[](const char* key); 0933 /// Access an object value by name, returns null if there is no member with 0934 /// that name. 0935 const Value& operator[](const char* key) const; 0936 /// Access an object value by name, create a null member if it does not exist. 0937 /// \param key may contain embedded nulls. 0938 Value& operator[](const JSONCPP_STRING& key); 0939 /// Access an object value by name, returns null if there is no member with 0940 /// that name. 0941 /// \param key may contain embedded nulls. 0942 const Value& operator[](const JSONCPP_STRING& key) const; 0943 /** \brief Access an object value by name, create a null member if it does not 0944 exist. 0945 0946 * If the object has no entry for that name, then the member name used to store 0947 * the new entry is not duplicated. 0948 * Example of use: 0949 * \code 0950 * Json::Value object; 0951 * static const StaticString code("code"); 0952 * object[code] = 1234; 0953 * \endcode 0954 */ 0955 Value& operator[](const StaticString& key); 0956 #ifdef JSON_USE_CPPTL 0957 /// Access an object value by name, create a null member if it does not exist. 0958 Value& operator[](const CppTL::ConstString& key); 0959 /// Access an object value by name, returns null if there is no member with 0960 /// that name. 0961 const Value& operator[](const CppTL::ConstString& key) const; 0962 #endif 0963 /// Return the member named key if it exist, defaultValue otherwise. 0964 /// \note deep copy 0965 Value get(const char* key, const Value& defaultValue) const; 0966 /// Return the member named key if it exist, defaultValue otherwise. 0967 /// \note deep copy 0968 /// \note key may contain embedded nulls. 0969 Value get(const char* begin, const char* end, const Value& defaultValue) const; 0970 /// Return the member named key if it exist, defaultValue otherwise. 0971 /// \note deep copy 0972 /// \param key may contain embedded nulls. 0973 Value get(const JSONCPP_STRING& key, const Value& defaultValue) const; 0974 #ifdef JSON_USE_CPPTL 0975 /// Return the member named key if it exist, defaultValue otherwise. 0976 /// \note deep copy 0977 Value get(const CppTL::ConstString& key, const Value& defaultValue) const; 0978 #endif 0979 /// Most general and efficient version of isMember()const, get()const, 0980 /// and operator[]const 0981 /// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30 0982 Value const* find(char const* begin, char const* end) const; 0983 /// Most general and efficient version of object-mutators. 0984 /// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30 0985 /// \return non-zero, but JSON_ASSERT if this is neither object nor nullValue. 0986 Value const* demand(char const* begin, char const* end); 0987 /// \brief Remove and return the named member. 0988 /// 0989 /// Do nothing if it did not exist. 0990 /// \return the removed Value, or null. 0991 /// \pre type() is objectValue or nullValue 0992 /// \post type() is unchanged 0993 /// \deprecated 0994 void removeMember(const char* key); 0995 /// Same as removeMember(const char*) 0996 /// \param key may contain embedded nulls. 0997 /// \deprecated 0998 void removeMember(const JSONCPP_STRING& key); 0999 /// Same as removeMember(const char* begin, const char* end, Value* removed), 1000 /// but 'key' is null-terminated. 1001 bool removeMember(const char* key, Value* removed); 1002 /** \brief Remove the named map member. 1003 1004 Update 'removed' iff removed. 1005 \param key may contain embedded nulls. 1006 \return true iff removed (no exceptions) 1007 */ 1008 bool removeMember(JSONCPP_STRING const& key, Value* removed); 1009 /// Same as removeMember(JSONCPP_STRING const& key, Value* removed) 1010 bool removeMember(const char* begin, const char* end, Value* removed); 1011 /** \brief Remove the indexed array element. 1012 1013 O(n) expensive operations. 1014 Update 'removed' iff removed. 1015 \return true iff removed (no exceptions) 1016 */ 1017 bool removeIndex(ArrayIndex i, Value* removed); 1018 1019 /// Return true if the object has a member named key. 1020 /// \note 'key' must be null-terminated. 1021 bool isMember(const char* key) const; 1022 /// Return true if the object has a member named key. 1023 /// \param key may contain embedded nulls. 1024 bool isMember(const JSONCPP_STRING& key) const; 1025 /// Same as isMember(JSONCPP_STRING const& key)const 1026 bool isMember(const char* begin, const char* end) const; 1027 #ifdef JSON_USE_CPPTL 1028 /// Return true if the object has a member named key. 1029 bool isMember(const CppTL::ConstString& key) const; 1030 #endif 1031 1032 /// \brief Return a list of the member names. 1033 /// 1034 /// If null, return an empty list. 1035 /// \pre type() is objectValue or nullValue 1036 /// \post if type() was nullValue, it remains nullValue 1037 Members getMemberNames() const; 1038 1039 //# ifdef JSON_USE_CPPTL 1040 // EnumMemberNames enumMemberNames() const; 1041 // EnumValues enumValues() const; 1042 //# endif 1043 1044 /// \deprecated Always pass len. 1045 JSONCPP_DEPRECATED("Use setComment(JSONCPP_STRING const&) instead.") 1046 void setComment(const char* comment, CommentPlacement placement); 1047 /// Comments must be //... or /* ... */ 1048 void setComment(const char* comment, size_t len, CommentPlacement placement); 1049 /// Comments must be //... or /* ... */ 1050 void setComment(const JSONCPP_STRING& comment, CommentPlacement placement); 1051 bool hasComment(CommentPlacement placement) const; 1052 /// Include delimiters and embedded newlines. 1053 JSONCPP_STRING getComment(CommentPlacement placement) const; 1054 1055 JSONCPP_STRING toStyledString() const; 1056 1057 const_iterator begin() const; 1058 const_iterator end() const; 1059 1060 iterator begin(); 1061 iterator end(); 1062 1063 // Accessors for the [start, limit) range of bytes within the JSON text from 1064 // which this value was parsed, if any. 1065 void setOffsetStart(ptrdiff_t start); 1066 void setOffsetLimit(ptrdiff_t limit); 1067 ptrdiff_t getOffsetStart() const; 1068 ptrdiff_t getOffsetLimit() const; 1069 1070 private: 1071 void initBasic(ValueType type, bool allocated = false); 1072 void dupPayload(const Value& other); 1073 void releasePayload(); 1074 void dupMeta(const Value& other); 1075 1076 Value& resolveReference(const char* key); 1077 Value& resolveReference(const char* key, const char* end); 1078 1079 struct CommentInfo { 1080 CommentInfo(); 1081 ~CommentInfo(); 1082 1083 void setComment(const char* text, size_t len); 1084 1085 char* comment_; 1086 }; 1087 1088 // struct MemberNamesTransform 1089 //{ 1090 // typedef const char *result_type; 1091 // const char *operator()( const CZString &name ) const 1092 // { 1093 // return name.c_str(); 1094 // } 1095 //}; 1096 1097 union ValueHolder { 1098 LargestInt int_; 1099 LargestUInt uint_; 1100 double real_; 1101 bool bool_; 1102 char* string_; // actually ptr to unsigned, followed by str, unless !allocated_ 1103 ObjectValues* map_; 1104 } value_; 1105 ValueType type_ : 8; 1106 unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is useless. 1107 // If not allocated_, string_ must be null-terminated. 1108 CommentInfo* comments_; 1109 1110 // [start, limit) byte offsets in the source JSON text from which this Value 1111 // was extracted. 1112 ptrdiff_t start_; 1113 ptrdiff_t limit_; 1114 }; 1115 1116 /** \brief Experimental and untested: represents an element of the "path" to 1117 * access a node. 1118 */ 1119 class JSON_API PathArgument { 1120 public: 1121 friend class Path; 1122 1123 PathArgument(); 1124 PathArgument(ArrayIndex index); 1125 PathArgument(const char* key); 1126 PathArgument(const JSONCPP_STRING& key); 1127 1128 private: 1129 enum Kind { 1130 kindNone = 0, 1131 kindIndex, 1132 kindKey 1133 }; 1134 JSONCPP_STRING key_; 1135 ArrayIndex index_; 1136 Kind kind_; 1137 }; 1138 1139 /** \brief Experimental and untested: represents a "path" to access a node. 1140 * 1141 * Syntax: 1142 * - "." => root node 1143 * - ".[n]" => elements at index 'n' of root node (an array value) 1144 * - ".name" => member named 'name' of root node (an object value) 1145 * - ".name1.name2.name3" 1146 * - ".[0][1][2].name1[3]" 1147 * - ".%" => member name is provided as parameter 1148 * - ".[%]" => index is provied as parameter 1149 */ 1150 class JSON_API Path { 1151 public: 1152 Path(const JSONCPP_STRING& path, 1153 const PathArgument& a1 = PathArgument(), 1154 const PathArgument& a2 = PathArgument(), 1155 const PathArgument& a3 = PathArgument(), 1156 const PathArgument& a4 = PathArgument(), 1157 const PathArgument& a5 = PathArgument()); 1158 1159 const Value& resolve(const Value& root) const; 1160 Value resolve(const Value& root, const Value& defaultValue) const; 1161 /// Creates the "path" to access the specified node and returns a reference on 1162 /// the node. 1163 Value& make(Value& root) const; 1164 1165 private: 1166 typedef std::vector<const PathArgument*> InArgs; 1167 typedef std::vector<PathArgument> Args; 1168 1169 void makePath(const JSONCPP_STRING& path, const InArgs& in); 1170 void addPathInArg(const JSONCPP_STRING& path, 1171 const InArgs& in, 1172 InArgs::const_iterator& itInArg, 1173 PathArgument::Kind kind); 1174 void invalidPath(const JSONCPP_STRING& path, int location); 1175 1176 Args args_; 1177 }; 1178 1179 /** \brief base class for Value iterators. 1180 * 1181 */ 1182 class JSON_API ValueIteratorBase { 1183 public: 1184 typedef std::bidirectional_iterator_tag iterator_category; 1185 typedef unsigned int size_t; 1186 typedef int difference_type; 1187 typedef ValueIteratorBase SelfType; 1188 1189 bool operator==(const SelfType& other) const { return isEqual(other); } 1190 1191 bool operator!=(const SelfType& other) const { return !isEqual(other); } 1192 1193 difference_type operator-(const SelfType& other) const { 1194 return other.computeDistance(*this); 1195 } 1196 1197 /// Return either the index or the member name of the referenced value as a 1198 /// Value. 1199 Value key() const; 1200 1201 /// Return the index of the referenced Value, or -1 if it is not an arrayValue. 1202 UInt index() const; 1203 1204 /// Return the member name of the referenced Value, or "" if it is not an 1205 /// objectValue. 1206 /// \note Avoid `c_str()` on result, as embedded zeroes are possible. 1207 JSONCPP_STRING name() const; 1208 1209 /// Return the member name of the referenced Value. "" if it is not an 1210 /// objectValue. 1211 /// \deprecated This cannot be used for UTF-8 strings, since there can be embedded nulls. 1212 JSONCPP_DEPRECATED("Use `key = name();` instead.") 1213 char const* memberName() const; 1214 /// Return the member name of the referenced Value, or NULL if it is not an 1215 /// objectValue. 1216 /// \note Better version than memberName(). Allows embedded nulls. 1217 char const* memberName(char const** end) const; 1218 1219 protected: 1220 Value& deref() const; 1221 1222 void increment(); 1223 1224 void decrement(); 1225 1226 difference_type computeDistance(const SelfType& other) const; 1227 1228 bool isEqual(const SelfType& other) const; 1229 1230 void copy(const SelfType& other); 1231 1232 private: 1233 Value::ObjectValues::iterator current_; 1234 // Indicates that iterator is for a null value. 1235 bool isNull_; 1236 1237 public: 1238 // For some reason, BORLAND needs these at the end, rather 1239 // than earlier. No idea why. 1240 ValueIteratorBase(); 1241 explicit ValueIteratorBase(const Value::ObjectValues::iterator& current); 1242 }; 1243 1244 /** \brief const iterator for object and array value. 1245 * 1246 */ 1247 class JSON_API ValueConstIterator : public ValueIteratorBase { 1248 friend class Value; 1249 1250 public: 1251 typedef const Value value_type; 1252 //typedef unsigned int size_t; 1253 //typedef int difference_type; 1254 typedef const Value& reference; 1255 typedef const Value* pointer; 1256 typedef ValueConstIterator SelfType; 1257 1258 ValueConstIterator(); 1259 ValueConstIterator(ValueIterator const& other); 1260 1261 private: 1262 /*! \internal Use by Value to create an iterator. 1263 */ 1264 explicit ValueConstIterator(const Value::ObjectValues::iterator& current); 1265 public: 1266 SelfType& operator=(const ValueIteratorBase& other); 1267 1268 SelfType operator++(int) { 1269 SelfType temp(*this); 1270 ++*this; 1271 return temp; 1272 } 1273 1274 SelfType operator--(int) { 1275 SelfType temp(*this); 1276 --*this; 1277 return temp; 1278 } 1279 1280 SelfType& operator--() { 1281 decrement(); 1282 return *this; 1283 } 1284 1285 SelfType& operator++() { 1286 increment(); 1287 return *this; 1288 } 1289 1290 reference operator*() const { return deref(); } 1291 1292 pointer operator->() const { return &deref(); } 1293 }; 1294 1295 /** \brief Iterator for object and array value. 1296 */ 1297 class JSON_API ValueIterator : public ValueIteratorBase { 1298 friend class Value; 1299 1300 public: 1301 typedef Value value_type; 1302 typedef unsigned int size_t; 1303 typedef int difference_type; 1304 typedef Value& reference; 1305 typedef Value* pointer; 1306 typedef ValueIterator SelfType; 1307 1308 ValueIterator(); 1309 explicit ValueIterator(const ValueConstIterator& other); 1310 ValueIterator(const ValueIterator& other); 1311 1312 private: 1313 /*! \internal Use by Value to create an iterator. 1314 */ 1315 explicit ValueIterator(const Value::ObjectValues::iterator& current); 1316 public: 1317 SelfType& operator=(const SelfType& other); 1318 1319 SelfType operator++(int) { 1320 SelfType temp(*this); 1321 ++*this; 1322 return temp; 1323 } 1324 1325 SelfType operator--(int) { 1326 SelfType temp(*this); 1327 --*this; 1328 return temp; 1329 } 1330 1331 SelfType& operator--() { 1332 decrement(); 1333 return *this; 1334 } 1335 1336 SelfType& operator++() { 1337 increment(); 1338 return *this; 1339 } 1340 1341 reference operator*() const { return deref(); } 1342 1343 pointer operator->() const { return &deref(); } 1344 }; 1345 1346 inline void swap(Value& a, Value& b) { a.swap(b); } 1347 1348 } // namespace Json 1349 1350 #pragma pack(pop) 1351 1352 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 1353 #pragma warning(pop) 1354 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 1355 1356 #endif // CPPTL_JSON_H_INCLUDED 1357 1358 // ////////////////////////////////////////////////////////////////////// 1359 // End of content of file: include/json/value.h 1360 // ////////////////////////////////////////////////////////////////////// 1361 1362 1363 1364 1365 1366 1367 // ////////////////////////////////////////////////////////////////////// 1368 // Beginning of content of file: include/json/reader.h 1369 // ////////////////////////////////////////////////////////////////////// 1370 1371 // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 1372 // Distributed under MIT license, or public domain if desired and 1373 // recognized in your jurisdiction. 1374 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 1375 1376 #ifndef CPPTL_JSON_READER_H_INCLUDED 1377 #define CPPTL_JSON_READER_H_INCLUDED 1378 1379 #if !defined(JSON_IS_AMALGAMATION) 1380 #include "features.h" 1381 #include "value.h" 1382 #endif // if !defined(JSON_IS_AMALGAMATION) 1383 #include <deque> 1384 #include <iosfwd> 1385 #include <stack> 1386 #include <string> 1387 #include <istream> 1388 1389 // Disable warning C4251: <data member>: <type> needs to have dll-interface to 1390 // be used by... 1391 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 1392 #pragma warning(push) 1393 #pragma warning(disable : 4251) 1394 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 1395 1396 #pragma pack(push, 8) 1397 1398 namespace Json { 1399 1400 /** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a 1401 *Value. 1402 * 1403 * \deprecated Use CharReader and CharReaderBuilder. 1404 */ 1405 class JSON_API Reader { 1406 public: 1407 typedef char Char; 1408 typedef const Char* Location; 1409 1410 /** \brief An error tagged with where in the JSON text it was encountered. 1411 * 1412 * The offsets give the [start, limit) range of bytes within the text. Note 1413 * that this is bytes, not codepoints. 1414 * 1415 */ 1416 struct StructuredError { 1417 ptrdiff_t offset_start; 1418 ptrdiff_t offset_limit; 1419 JSONCPP_STRING message; 1420 }; 1421 1422 /** \brief Constructs a Reader allowing all features 1423 * for parsing. 1424 */ 1425 JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead") 1426 Reader(); 1427 1428 /** \brief Constructs a Reader allowing the specified feature set 1429 * for parsing. 1430 */ 1431 JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead") 1432 Reader(const Features& features); 1433 1434 /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> 1435 * document. 1436 * \param document UTF-8 encoded string containing the document to read. 1437 * \param root [out] Contains the root value of the document if it was 1438 * successfully parsed. 1439 * \param collectComments \c true to collect comment and allow writing them 1440 * back during 1441 * serialization, \c false to discard comments. 1442 * This parameter is ignored if 1443 * Features::allowComments_ 1444 * is \c false. 1445 * \return \c true if the document was successfully parsed, \c false if an 1446 * error occurred. 1447 */ 1448 bool 1449 parse(const std::string& document, Value& root, bool collectComments = true); 1450 1451 /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> 1452 document. 1453 * \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the 1454 document to read. 1455 * \param endDoc Pointer on the end of the UTF-8 encoded string of the 1456 document to read. 1457 * Must be >= beginDoc. 1458 * \param root [out] Contains the root value of the document if it was 1459 * successfully parsed. 1460 * \param collectComments \c true to collect comment and allow writing them 1461 back during 1462 * serialization, \c false to discard comments. 1463 * This parameter is ignored if 1464 Features::allowComments_ 1465 * is \c false. 1466 * \return \c true if the document was successfully parsed, \c false if an 1467 error occurred. 1468 */ 1469 bool parse(const char* beginDoc, 1470 const char* endDoc, 1471 Value& root, 1472 bool collectComments = true); 1473 1474 /// \brief Parse from input stream. 1475 /// \see Json::operator>>(std::istream&, Json::Value&). 1476 bool parse(JSONCPP_ISTREAM& is, Value& root, bool collectComments = true); 1477 1478 /** \brief Returns a user friendly string that list errors in the parsed 1479 * document. 1480 * \return Formatted error message with the list of errors with their location 1481 * in 1482 * the parsed document. An empty string is returned if no error 1483 * occurred 1484 * during parsing. 1485 * \deprecated Use getFormattedErrorMessages() instead (typo fix). 1486 */ 1487 JSONCPP_DEPRECATED("Use getFormattedErrorMessages() instead.") 1488 JSONCPP_STRING getFormatedErrorMessages() const; 1489 1490 /** \brief Returns a user friendly string that list errors in the parsed 1491 * document. 1492 * \return Formatted error message with the list of errors with their location 1493 * in 1494 * the parsed document. An empty string is returned if no error 1495 * occurred 1496 * during parsing. 1497 */ 1498 JSONCPP_STRING getFormattedErrorMessages() const; 1499 1500 /** \brief Returns a vector of structured erros encounted while parsing. 1501 * \return A (possibly empty) vector of StructuredError objects. Currently 1502 * only one error can be returned, but the caller should tolerate 1503 * multiple 1504 * errors. This can occur if the parser recovers from a non-fatal 1505 * parse error and then encounters additional errors. 1506 */ 1507 std::vector<StructuredError> getStructuredErrors() const; 1508 1509 /** \brief Add a semantic error message. 1510 * \param value JSON Value location associated with the error 1511 * \param message The error message. 1512 * \return \c true if the error was successfully added, \c false if the 1513 * Value offset exceeds the document size. 1514 */ 1515 bool pushError(const Value& value, const JSONCPP_STRING& message); 1516 1517 /** \brief Add a semantic error message with extra context. 1518 * \param value JSON Value location associated with the error 1519 * \param message The error message. 1520 * \param extra Additional JSON Value location to contextualize the error 1521 * \return \c true if the error was successfully added, \c false if either 1522 * Value offset exceeds the document size. 1523 */ 1524 bool pushError(const Value& value, const JSONCPP_STRING& message, const Value& extra); 1525 1526 /** \brief Return whether there are any errors. 1527 * \return \c true if there are no errors to report \c false if 1528 * errors have occurred. 1529 */ 1530 bool good() const; 1531 1532 private: 1533 enum TokenType { 1534 tokenEndOfStream = 0, 1535 tokenObjectBegin, 1536 tokenObjectEnd, 1537 tokenArrayBegin, 1538 tokenArrayEnd, 1539 tokenString, 1540 tokenNumber, 1541 tokenTrue, 1542 tokenFalse, 1543 tokenNull, 1544 tokenArraySeparator, 1545 tokenMemberSeparator, 1546 tokenComment, 1547 tokenError 1548 }; 1549 1550 class Token { 1551 public: 1552 TokenType type_; 1553 Location start_; 1554 Location end_; 1555 }; 1556 1557 class ErrorInfo { 1558 public: 1559 Token token_; 1560 JSONCPP_STRING message_; 1561 Location extra_; 1562 }; 1563 1564 typedef std::deque<ErrorInfo> Errors; 1565 1566 bool readToken(Token& token); 1567 void skipSpaces(); 1568 bool match(Location pattern, int patternLength); 1569 bool readComment(); 1570 bool readCStyleComment(); 1571 bool readCppStyleComment(); 1572 bool readString(); 1573 void readNumber(); 1574 bool readValue(); 1575 bool readObject(Token& token); 1576 bool readArray(Token& token); 1577 bool decodeNumber(Token& token); 1578 bool decodeNumber(Token& token, Value& decoded); 1579 bool decodeString(Token& token); 1580 bool decodeString(Token& token, JSONCPP_STRING& decoded); 1581 bool decodeDouble(Token& token); 1582 bool decodeDouble(Token& token, Value& decoded); 1583 bool decodeUnicodeCodePoint(Token& token, 1584 Location& current, 1585 Location end, 1586 unsigned int& unicode); 1587 bool decodeUnicodeEscapeSequence(Token& token, 1588 Location& current, 1589 Location end, 1590 unsigned int& unicode); 1591 bool addError(const JSONCPP_STRING& message, Token& token, Location extra = 0); 1592 bool recoverFromError(TokenType skipUntilToken); 1593 bool addErrorAndRecover(const JSONCPP_STRING& message, 1594 Token& token, 1595 TokenType skipUntilToken); 1596 void skipUntilSpace(); 1597 Value& currentValue(); 1598 Char getNextChar(); 1599 void 1600 getLocationLineAndColumn(Location location, int& line, int& column) const; 1601 JSONCPP_STRING getLocationLineAndColumn(Location location) const; 1602 void addComment(Location begin, Location end, CommentPlacement placement); 1603 void skipCommentTokens(Token& token); 1604 1605 static bool containsNewLine(Location begin, Location end); 1606 static JSONCPP_STRING normalizeEOL(Location begin, Location end); 1607 1608 typedef std::stack<Value*> Nodes; 1609 Nodes nodes_; 1610 Errors errors_; 1611 JSONCPP_STRING document_; 1612 Location begin_; 1613 Location end_; 1614 Location current_; 1615 Location lastValueEnd_; 1616 Value* lastValue_; 1617 JSONCPP_STRING commentsBefore_; 1618 Features features_; 1619 bool collectComments_; 1620 }; // Reader 1621 1622 /** Interface for reading JSON from a char array. 1623 */ 1624 class JSON_API CharReader { 1625 public: 1626 virtual ~CharReader() {} 1627 /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> 1628 document. 1629 * The document must be a UTF-8 encoded string containing the document to read. 1630 * 1631 * \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the 1632 document to read. 1633 * \param endDoc Pointer on the end of the UTF-8 encoded string of the 1634 document to read. 1635 * Must be >= beginDoc. 1636 * \param root [out] Contains the root value of the document if it was 1637 * successfully parsed. 1638 * \param errs [out] Formatted error messages (if not NULL) 1639 * a user friendly string that lists errors in the parsed 1640 * document. 1641 * \return \c true if the document was successfully parsed, \c false if an 1642 error occurred. 1643 */ 1644 virtual bool parse( 1645 char const* beginDoc, char const* endDoc, 1646 Value* root, JSONCPP_STRING* errs) = 0; 1647 1648 class JSON_API Factory { 1649 public: 1650 virtual ~Factory() {} 1651 /** \brief Allocate a CharReader via operator new(). 1652 * \throw std::exception if something goes wrong (e.g. invalid settings) 1653 */ 1654 virtual CharReader* newCharReader() const = 0; 1655 }; // Factory 1656 }; // CharReader 1657 1658 /** \brief Build a CharReader implementation. 1659 1660 Usage: 1661 \code 1662 using namespace Json; 1663 CharReaderBuilder builder; 1664 builder["collectComments"] = false; 1665 Value value; 1666 JSONCPP_STRING errs; 1667 bool ok = parseFromStream(builder, std::cin, &value, &errs); 1668 \endcode 1669 */ 1670 class JSON_API CharReaderBuilder : public CharReader::Factory { 1671 public: 1672 // Note: We use a Json::Value so that we can add data-members to this class 1673 // without a major version bump. 1674 /** Configuration of this builder. 1675 These are case-sensitive. 1676 Available settings (case-sensitive): 1677 - `"collectComments": false or true` 1678 - true to collect comment and allow writing them 1679 back during serialization, false to discard comments. 1680 This parameter is ignored if allowComments is false. 1681 - `"allowComments": false or true` 1682 - true if comments are allowed. 1683 - `"strictRoot": false or true` 1684 - true if root must be either an array or an object value 1685 - `"allowDroppedNullPlaceholders": false or true` 1686 - true if dropped null placeholders are allowed. (See StreamWriterBuilder.) 1687 - `"allowNumericKeys": false or true` 1688 - true if numeric object keys are allowed. 1689 - `"allowSingleQuotes": false or true` 1690 - true if '' are allowed for strings (both keys and values) 1691 - `"stackLimit": integer` 1692 - Exceeding stackLimit (recursive depth of `readValue()`) will 1693 cause an exception. 1694 - This is a security issue (seg-faults caused by deeply nested JSON), 1695 so the default is low. 1696 - `"failIfExtra": false or true` 1697 - If true, `parse()` returns false when extra non-whitespace trails 1698 the JSON value in the input string. 1699 - `"rejectDupKeys": false or true` 1700 - If true, `parse()` returns false when a key is duplicated within an object. 1701 - `"allowSpecialFloats": false or true` 1702 - If true, special float values (NaNs and infinities) are allowed 1703 and their values are lossfree restorable. 1704 1705 You can examine 'settings_` yourself 1706 to see the defaults. You can also write and read them just like any 1707 JSON Value. 1708 \sa setDefaults() 1709 */ 1710 Json::Value settings_; 1711 1712 CharReaderBuilder(); 1713 ~CharReaderBuilder() JSONCPP_OVERRIDE; 1714 1715 CharReader* newCharReader() const JSONCPP_OVERRIDE; 1716 1717 /** \return true if 'settings' are legal and consistent; 1718 * otherwise, indicate bad settings via 'invalid'. 1719 */ 1720 bool validate(Json::Value* invalid) const; 1721 1722 /** A simple way to update a specific setting. 1723 */ 1724 Value& operator[](JSONCPP_STRING key); 1725 1726 /** Called by ctor, but you can use this to reset settings_. 1727 * \pre 'settings' != NULL (but Json::null is fine) 1728 * \remark Defaults: 1729 * \snippet src/lib_json/json_reader.cpp CharReaderBuilderDefaults 1730 */ 1731 static void setDefaults(Json::Value* settings); 1732 /** Same as old Features::strictMode(). 1733 * \pre 'settings' != NULL (but Json::null is fine) 1734 * \remark Defaults: 1735 * \snippet src/lib_json/json_reader.cpp CharReaderBuilderStrictMode 1736 */ 1737 static void strictMode(Json::Value* settings); 1738 }; 1739 1740 /** Consume entire stream and use its begin/end. 1741 * Someday we might have a real StreamReader, but for now this 1742 * is convenient. 1743 */ 1744 bool JSON_API parseFromStream( 1745 CharReader::Factory const&, 1746 JSONCPP_ISTREAM&, 1747 Value* root, std::string* errs); 1748 1749 /** \brief Read from 'sin' into 'root'. 1750 1751 Always keep comments from the input JSON. 1752 1753 This can be used to read a file into a particular sub-object. 1754 For example: 1755 \code 1756 Json::Value root; 1757 cin >> root["dir"]["file"]; 1758 cout << root; 1759 \endcode 1760 Result: 1761 \verbatim 1762 { 1763 "dir": { 1764 "file": { 1765 // The input stream JSON would be nested here. 1766 } 1767 } 1768 } 1769 \endverbatim 1770 \throw std::exception on parse error. 1771 \see Json::operator<<() 1772 */ 1773 JSON_API JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM&, Value&); 1774 1775 } // namespace Json 1776 1777 #pragma pack(pop) 1778 1779 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 1780 #pragma warning(pop) 1781 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 1782 1783 #endif // CPPTL_JSON_READER_H_INCLUDED 1784 1785 // ////////////////////////////////////////////////////////////////////// 1786 // End of content of file: include/json/reader.h 1787 // ////////////////////////////////////////////////////////////////////// 1788 1789 1790 1791 1792 1793 1794 // ////////////////////////////////////////////////////////////////////// 1795 // Beginning of content of file: include/json/writer.h 1796 // ////////////////////////////////////////////////////////////////////// 1797 1798 // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 1799 // Distributed under MIT license, or public domain if desired and 1800 // recognized in your jurisdiction. 1801 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 1802 1803 #ifndef JSON_WRITER_H_INCLUDED 1804 #define JSON_WRITER_H_INCLUDED 1805 1806 #if !defined(JSON_IS_AMALGAMATION) 1807 #include "value.h" 1808 #endif // if !defined(JSON_IS_AMALGAMATION) 1809 #include <vector> 1810 #include <string> 1811 #include <ostream> 1812 1813 // Disable warning C4251: <data member>: <type> needs to have dll-interface to 1814 // be used by... 1815 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) && defined(_MSC_VER) 1816 #pragma warning(push) 1817 #pragma warning(disable : 4251) 1818 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 1819 1820 #pragma pack(push, 8) 1821 1822 namespace Json { 1823 1824 class Value; 1825 1826 /** 1827 1828 Usage: 1829 \code 1830 using namespace Json; 1831 void writeToStdout(StreamWriter::Factory const& factory, Value const& value) { 1832 std::unique_ptr<StreamWriter> const writer( 1833 factory.newStreamWriter()); 1834 writer->write(value, &std::cout); 1835 std::cout << std::endl; // add lf and flush 1836 } 1837 \endcode 1838 */ 1839 class JSON_API StreamWriter { 1840 protected: 1841 JSONCPP_OSTREAM* sout_; // not owned; will not delete 1842 public: 1843 StreamWriter(); 1844 virtual ~StreamWriter(); 1845 /** Write Value into document as configured in sub-class. 1846 Do not take ownership of sout, but maintain a reference during function. 1847 \pre sout != NULL 1848 \return zero on success (For now, we always return zero, so check the stream instead.) 1849 \throw std::exception possibly, depending on configuration 1850 */ 1851 virtual int write(Value const& root, JSONCPP_OSTREAM* sout) = 0; 1852 1853 /** \brief A simple abstract factory. 1854 */ 1855 class JSON_API Factory { 1856 public: 1857 virtual ~Factory(); 1858 /** \brief Allocate a CharReader via operator new(). 1859 * \throw std::exception if something goes wrong (e.g. invalid settings) 1860 */ 1861 virtual StreamWriter* newStreamWriter() const = 0; 1862 }; // Factory 1863 }; // StreamWriter 1864 1865 /** \brief Write into stringstream, then return string, for convenience. 1866 * A StreamWriter will be created from the factory, used, and then deleted. 1867 */ 1868 JSONCPP_STRING JSON_API writeString(StreamWriter::Factory const& factory, Value const& root); 1869 1870 1871 /** \brief Build a StreamWriter implementation. 1872 1873 Usage: 1874 \code 1875 using namespace Json; 1876 Value value = ...; 1877 StreamWriterBuilder builder; 1878 builder["commentStyle"] = "None"; 1879 builder["indentation"] = " "; // or whatever you like 1880 std::unique_ptr<Json::StreamWriter> writer( 1881 builder.newStreamWriter()); 1882 writer->write(value, &std::cout); 1883 std::cout << std::endl; // add lf and flush 1884 \endcode 1885 */ 1886 class JSON_API StreamWriterBuilder : public StreamWriter::Factory { 1887 public: 1888 // Note: We use a Json::Value so that we can add data-members to this class 1889 // without a major version bump. 1890 /** Configuration of this builder. 1891 Available settings (case-sensitive): 1892 - "commentStyle": "None" or "All" 1893 - "indentation": "<anything>". 1894 - Setting this to an empty string also omits newline characters. 1895 - "enableYAMLCompatibility": false or true 1896 - slightly change the whitespace around colons 1897 - "dropNullPlaceholders": false or true 1898 - Drop the "null" string from the writer's output for nullValues. 1899 Strictly speaking, this is not valid JSON. But when the output is being 1900 fed to a browser's JavaScript, it makes for smaller output and the 1901 browser can handle the output just fine. 1902 - "useSpecialFloats": false or true 1903 - If true, outputs non-finite floating point values in the following way: 1904 NaN values as "NaN", positive infinity as "Infinity", and negative infinity 1905 as "-Infinity". 1906 - "precision": int 1907 - Number of precision digits for formatting of real values. 1908 - "precisionType": "significant"(default) or "decimal" 1909 - Type of precision for formatting of real values. 1910 1911 You can examine 'settings_` yourself 1912 to see the defaults. You can also write and read them just like any 1913 JSON Value. 1914 \sa setDefaults() 1915 */ 1916 Json::Value settings_; 1917 1918 StreamWriterBuilder(); 1919 ~StreamWriterBuilder() JSONCPP_OVERRIDE; 1920 1921 /** 1922 * \throw std::exception if something goes wrong (e.g. invalid settings) 1923 */ 1924 StreamWriter* newStreamWriter() const JSONCPP_OVERRIDE; 1925 1926 /** \return true if 'settings' are legal and consistent; 1927 * otherwise, indicate bad settings via 'invalid'. 1928 */ 1929 bool validate(Json::Value* invalid) const; 1930 /** A simple way to update a specific setting. 1931 */ 1932 Value& operator[](JSONCPP_STRING key); 1933 1934 /** Called by ctor, but you can use this to reset settings_. 1935 * \pre 'settings' != NULL (but Json::null is fine) 1936 * \remark Defaults: 1937 * \snippet src/lib_json/json_writer.cpp StreamWriterBuilderDefaults 1938 */ 1939 static void setDefaults(Json::Value* settings); 1940 }; 1941 1942 /** \brief Abstract class for writers. 1943 * \deprecated Use StreamWriter. (And really, this is an implementation detail.) 1944 */ 1945 class JSONCPP_DEPRECATED("Use StreamWriter instead") JSON_API Writer { 1946 public: 1947 virtual ~Writer(); 1948 1949 virtual JSONCPP_STRING write(const Value& root) = 0; 1950 }; 1951 1952 /** \brief Outputs a Value in <a HREF="http://www.json.org">JSON</a> format 1953 *without formatting (not human friendly). 1954 * 1955 * The JSON document is written in a single line. It is not intended for 'human' 1956 *consumption, 1957 * but may be useful to support feature such as RPC where bandwidth is limited. 1958 * \sa Reader, Value 1959 * \deprecated Use StreamWriterBuilder. 1960 */ 1961 #if defined(_MSC_VER) 1962 #pragma warning(push) 1963 #pragma warning(disable:4996) // Deriving from deprecated class 1964 #endif 1965 class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter : public Writer { 1966 public: 1967 FastWriter(); 1968 ~FastWriter() JSONCPP_OVERRIDE {} 1969 1970 void enableYAMLCompatibility(); 1971 1972 /** \brief Drop the "null" string from the writer's output for nullValues. 1973 * Strictly speaking, this is not valid JSON. But when the output is being 1974 * fed to a browser's JavaScript, it makes for smaller output and the 1975 * browser can handle the output just fine. 1976 */ 1977 void dropNullPlaceholders(); 1978 1979 void omitEndingLineFeed(); 1980 1981 public: // overridden from Writer 1982 JSONCPP_STRING write(const Value& root) JSONCPP_OVERRIDE; 1983 1984 private: 1985 void writeValue(const Value& value); 1986 1987 JSONCPP_STRING document_; 1988 bool yamlCompatibilityEnabled_; 1989 bool dropNullPlaceholders_; 1990 bool omitEndingLineFeed_; 1991 }; 1992 #if defined(_MSC_VER) 1993 #pragma warning(pop) 1994 #endif 1995 1996 /** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a 1997 *human friendly way. 1998 * 1999 * The rules for line break and indent are as follow: 2000 * - Object value: 2001 * - if empty then print {} without indent and line break 2002 * - if not empty the print '{', line break & indent, print one value per 2003 *line 2004 * and then unindent and line break and print '}'. 2005 * - Array value: 2006 * - if empty then print [] without indent and line break 2007 * - if the array contains no object value, empty array or some other value 2008 *types, 2009 * and all the values fit on one lines, then print the array on a single 2010 *line. 2011 * - otherwise, it the values do not fit on one line, or the array contains 2012 * object or non empty array, then print one value per line. 2013 * 2014 * If the Value have comments then they are outputed according to their 2015 *#CommentPlacement. 2016 * 2017 * \sa Reader, Value, Value::setComment() 2018 * \deprecated Use StreamWriterBuilder. 2019 */ 2020 #if defined(_MSC_VER) 2021 #pragma warning(push) 2022 #pragma warning(disable:4996) // Deriving from deprecated class 2023 #endif 2024 class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API StyledWriter : public Writer { 2025 public: 2026 StyledWriter(); 2027 ~StyledWriter() JSONCPP_OVERRIDE {} 2028 2029 public: // overridden from Writer 2030 /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format. 2031 * \param root Value to serialize. 2032 * \return String containing the JSON document that represents the root value. 2033 */ 2034 JSONCPP_STRING write(const Value& root) JSONCPP_OVERRIDE; 2035 2036 private: 2037 void writeValue(const Value& value); 2038 void writeArrayValue(const Value& value); 2039 bool isMultilineArray(const Value& value); 2040 void pushValue(const JSONCPP_STRING& value); 2041 void writeIndent(); 2042 void writeWithIndent(const JSONCPP_STRING& value); 2043 void indent(); 2044 void unindent(); 2045 void writeCommentBeforeValue(const Value& root); 2046 void writeCommentAfterValueOnSameLine(const Value& root); 2047 bool hasCommentForValue(const Value& value); 2048 static JSONCPP_STRING normalizeEOL(const JSONCPP_STRING& text); 2049 2050 typedef std::vector<JSONCPP_STRING> ChildValues; 2051 2052 ChildValues childValues_; 2053 JSONCPP_STRING document_; 2054 JSONCPP_STRING indentString_; 2055 unsigned int rightMargin_; 2056 unsigned int indentSize_; 2057 bool addChildValues_; 2058 }; 2059 #if defined(_MSC_VER) 2060 #pragma warning(pop) 2061 #endif 2062 2063 /** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a 2064 human friendly way, 2065 to a stream rather than to a string. 2066 * 2067 * The rules for line break and indent are as follow: 2068 * - Object value: 2069 * - if empty then print {} without indent and line break 2070 * - if not empty the print '{', line break & indent, print one value per 2071 line 2072 * and then unindent and line break and print '}'. 2073 * - Array value: 2074 * - if empty then print [] without indent and line break 2075 * - if the array contains no object value, empty array or some other value 2076 types, 2077 * and all the values fit on one lines, then print the array on a single 2078 line. 2079 * - otherwise, it the values do not fit on one line, or the array contains 2080 * object or non empty array, then print one value per line. 2081 * 2082 * If the Value have comments then they are outputed according to their 2083 #CommentPlacement. 2084 * 2085 * \sa Reader, Value, Value::setComment() 2086 * \deprecated Use StreamWriterBuilder. 2087 */ 2088 #if defined(_MSC_VER) 2089 #pragma warning(push) 2090 #pragma warning(disable:4996) // Deriving from deprecated class 2091 #endif 2092 class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API StyledStreamWriter { 2093 public: 2094 /** 2095 * \param indentation Each level will be indented by this amount extra. 2096 */ 2097 StyledStreamWriter(JSONCPP_STRING indentation = "\t"); 2098 ~StyledStreamWriter() {} 2099 2100 public: 2101 /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format. 2102 * \param out Stream to write to. (Can be ostringstream, e.g.) 2103 * \param root Value to serialize. 2104 * \note There is no point in deriving from Writer, since write() should not 2105 * return a value. 2106 */ 2107 void write(JSONCPP_OSTREAM& out, const Value& root); 2108 2109 private: 2110 void writeValue(const Value& value); 2111 void writeArrayValue(const Value& value); 2112 bool isMultilineArray(const Value& value); 2113 void pushValue(const JSONCPP_STRING& value); 2114 void writeIndent(); 2115 void writeWithIndent(const JSONCPP_STRING& value); 2116 void indent(); 2117 void unindent(); 2118 void writeCommentBeforeValue(const Value& root); 2119 void writeCommentAfterValueOnSameLine(const Value& root); 2120 bool hasCommentForValue(const Value& value); 2121 static JSONCPP_STRING normalizeEOL(const JSONCPP_STRING& text); 2122 2123 typedef std::vector<JSONCPP_STRING> ChildValues; 2124 2125 ChildValues childValues_; 2126 JSONCPP_OSTREAM* document_; 2127 JSONCPP_STRING indentString_; 2128 unsigned int rightMargin_; 2129 JSONCPP_STRING indentation_; 2130 bool addChildValues_ : 1; 2131 bool indented_ : 1; 2132 }; 2133 #if defined(_MSC_VER) 2134 #pragma warning(pop) 2135 #endif 2136 2137 #if defined(JSON_HAS_INT64) 2138 JSONCPP_STRING JSON_API valueToString(Int value); 2139 JSONCPP_STRING JSON_API valueToString(UInt value); 2140 #endif // if defined(JSON_HAS_INT64) 2141 JSONCPP_STRING JSON_API valueToString(LargestInt value); 2142 JSONCPP_STRING JSON_API valueToString(LargestUInt value); 2143 JSONCPP_STRING JSON_API valueToString(double value, unsigned int precision = Value::defaultRealPrecision, 2144 PrecisionType precisionType = PrecisionType::significantDigits); 2145 JSONCPP_STRING JSON_API valueToString(bool value); 2146 JSONCPP_STRING JSON_API valueToQuotedString(const char* value); 2147 2148 /// \brief Output using the StyledStreamWriter. 2149 /// \see Json::operator>>() 2150 JSON_API JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM&, const Value& root); 2151 2152 } // namespace Json 2153 2154 #pragma pack(pop) 2155 2156 #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 2157 #pragma warning(pop) 2158 #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 2159 2160 #endif // JSON_WRITER_H_INCLUDED 2161 2162 // ////////////////////////////////////////////////////////////////////// 2163 // End of content of file: include/json/writer.h 2164 // ////////////////////////////////////////////////////////////////////// 2165 2166 2167 2168 2169 2170 2171 // ////////////////////////////////////////////////////////////////////// 2172 // Beginning of content of file: include/json/assertions.h 2173 // ////////////////////////////////////////////////////////////////////// 2174 2175 // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 2176 // Distributed under MIT license, or public domain if desired and 2177 // recognized in your jurisdiction. 2178 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 2179 2180 #ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED 2181 #define CPPTL_JSON_ASSERTIONS_H_INCLUDED 2182 2183 #include <stdlib.h> 2184 #include <sstream> 2185 2186 #if !defined(JSON_IS_AMALGAMATION) 2187 #include "config.h" 2188 #endif // if !defined(JSON_IS_AMALGAMATION) 2189 2190 /** It should not be possible for a maliciously designed file to 2191 * cause an abort() or seg-fault, so these macros are used only 2192 * for pre-condition violations and internal logic errors. 2193 */ 2194 #if JSON_USE_EXCEPTION 2195 2196 // @todo <= add detail about condition in exception 2197 # define JSON_ASSERT(condition) \ 2198 {if (!(condition)) {Json::throwLogicError( "assert json failed" );}} 2199 2200 # define JSON_FAIL_MESSAGE(message) \ 2201 { \ 2202 JSONCPP_OSTRINGSTREAM oss; oss << message; \ 2203 Json::throwLogicError(oss.str()); \ 2204 abort(); \ 2205 } 2206 2207 #else // JSON_USE_EXCEPTION 2208 2209 # define JSON_ASSERT(condition) assert(condition) 2210 2211 // The call to assert() will show the failure message in debug builds. In 2212 // release builds we abort, for a core-dump or debugger. 2213 # define JSON_FAIL_MESSAGE(message) \ 2214 { \ 2215 JSONCPP_OSTRINGSTREAM oss; oss << message; \ 2216 assert(false && oss.str().c_str()); \ 2217 abort(); \ 2218 } 2219 2220 2221 #endif 2222 2223 #define JSON_ASSERT_MESSAGE(condition, message) \ 2224 if (!(condition)) { \ 2225 JSON_FAIL_MESSAGE(message); \ 2226 } 2227 2228 #endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED 2229 2230 // ////////////////////////////////////////////////////////////////////// 2231 // End of content of file: include/json/assertions.h 2232 // ////////////////////////////////////////////////////////////////////// 2233 2234 2235 2236 2237 2238 #endif //ifndef JSON_AMALGAMATED_H_INCLUDED
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |