Devin Jeanpierre | 59e4d35 | 2017-07-21 03:44:36 -0700 | [diff] [blame] | 1 | // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors |
Baptiste Lepilleur | 7469f1d | 2010-04-20 21:35:19 +0000 | [diff] [blame] | 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 JSON_CONFIG_H_INCLUDED |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 7 | #define JSON_CONFIG_H_INCLUDED |
Hans Johnson | e50bfef | 2018-12-12 13:34:37 -0600 | [diff] [blame] | 8 | #include <cstddef> |
Billy Donahue | 1c2ed7a | 2019-01-17 16:35:29 -0500 | [diff] [blame] | 9 | #include <cstdint> |
| 10 | #include <istream> |
| 11 | #include <memory> |
| 12 | #include <ostream> |
| 13 | #include <sstream> |
| 14 | #include <string> |
| 15 | #include <type_traits> |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 16 | |
| 17 | /// If defined, indicates that json library is embedded in CppTL library. |
| 18 | //# define JSON_IN_CPPTL 1 |
| 19 | |
| 20 | /// If defined, indicates that json may leverage CppTL library |
| 21 | //# define JSON_USE_CPPTL 1 |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 22 | /// If defined, indicates that cpptl vector based map should be used instead of |
| 23 | /// std::map |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 24 | /// as Value container. |
| 25 | //# define JSON_USE_CPPTL_SMALLMAP 1 |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 26 | |
Aaron Jacobs | 7c507d7 | 2011-09-14 08:41:37 +0000 | [diff] [blame] | 27 | // If non-zero, the library uses exceptions to report bad input instead of C |
| 28 | // assertion macros. The default is to use exceptions. |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 29 | #ifndef JSON_USE_EXCEPTION |
| 30 | #define JSON_USE_EXCEPTION 1 |
| 31 | #endif |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 32 | |
Jordan Bayles | 25c5781 | 2019-07-11 14:27:29 -0700 | [diff] [blame] | 33 | // Temporary, tracked for removal with issue #982. |
| 34 | #ifndef JSON_USE_NULLREF |
| 35 | #define JSON_USE_NULLREF 1 |
| 36 | #endif |
| 37 | |
Josh Soref | e6a588a | 2017-12-03 11:54:29 -0500 | [diff] [blame] | 38 | /// If defined, indicates that the source file is amalgamated |
Baptiste Lepilleur | 64e40aa | 2011-05-01 20:13:40 +0000 | [diff] [blame] | 39 | /// to prevent private header inclusion. |
Josh Soref | e6a588a | 2017-12-03 11:54:29 -0500 | [diff] [blame] | 40 | /// Remarks: it is automatically defined in the generated amalgamated header. |
Baptiste Lepilleur | eadc478 | 2011-05-02 21:09:30 +0000 | [diff] [blame] | 41 | // #define JSON_IS_AMALGAMATION |
Baptiste Lepilleur | 64e40aa | 2011-05-01 20:13:40 +0000 | [diff] [blame] | 42 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 43 | #ifdef JSON_IN_CPPTL |
| 44 | #include <cpptl/config.h> |
| 45 | #ifndef JSON_USE_CPPTL |
| 46 | #define JSON_USE_CPPTL 1 |
| 47 | #endif |
| 48 | #endif |
Baptiste Lepilleur | 64e40aa | 2011-05-01 20:13:40 +0000 | [diff] [blame] | 49 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 50 | #ifdef JSON_IN_CPPTL |
| 51 | #define JSON_API CPPTL_API |
| 52 | #elif defined(JSON_DLL_BUILD) |
Gaurav | 8aabf93 | 2016-03-08 17:34:22 +0530 | [diff] [blame] | 53 | #if defined(_MSC_VER) || defined(__MINGW32__) |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 54 | #define JSON_API __declspec(dllexport) |
| 55 | #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING |
Frank Richter | b16abf8 | 2019-03-22 10:15:08 +0100 | [diff] [blame] | 56 | #elif defined(__GNUC__) || defined(__clang__) |
| 57 | #define JSON_API __attribute__((visibility("default"))) |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 58 | #endif // if defined(_MSC_VER) |
| 59 | #elif defined(JSON_DLL) |
Gaurav | 8aabf93 | 2016-03-08 17:34:22 +0530 | [diff] [blame] | 60 | #if defined(_MSC_VER) || defined(__MINGW32__) |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 61 | #define JSON_API __declspec(dllimport) |
| 62 | #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING |
| 63 | #endif // if defined(_MSC_VER) |
| 64 | #endif // ifdef JSON_IN_CPPTL |
| 65 | #if !defined(JSON_API) |
| 66 | #define JSON_API |
| 67 | #endif |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 68 | |
Hans Johnson | 31d6571 | 2019-01-11 14:13:08 -0600 | [diff] [blame] | 69 | #if defined(_MSC_VER) && _MSC_VER < 1800 |
Billy Donahue | dc4a7f9 | 2019-01-17 11:07:53 -0500 | [diff] [blame] | 70 | #error \ |
| 71 | "ERROR: Visual Studio 12 (2013) with _MSC_VER=1800 is the oldest supported compiler with sufficient C++11 capabilities" |
Hans Johnson | 31d6571 | 2019-01-11 14:13:08 -0600 | [diff] [blame] | 72 | #endif |
| 73 | |
Hans Johnson | 5c8e539 | 2018-12-12 13:31:55 -0600 | [diff] [blame] | 74 | #if defined(_MSC_VER) && _MSC_VER < 1900 |
Billy Donahue | dc4a7f9 | 2019-01-17 11:07:53 -0500 | [diff] [blame] | 75 | // As recommended at |
| 76 | // https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 |
| 77 | extern JSON_API int |
| 78 | msvc_pre1900_c99_snprintf(char* outBuf, size_t size, const char* format, ...); |
| 79 | #define jsoncpp_snprintf msvc_pre1900_c99_snprintf |
Hans Johnson | 5c8e539 | 2018-12-12 13:31:55 -0600 | [diff] [blame] | 80 | #else |
Billy Donahue | dc4a7f9 | 2019-01-17 11:07:53 -0500 | [diff] [blame] | 81 | #define jsoncpp_snprintf std::snprintf |
Hans Johnson | 5c8e539 | 2018-12-12 13:31:55 -0600 | [diff] [blame] | 82 | #endif |
| 83 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 84 | // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for |
| 85 | // integer |
Baptiste Lepilleur | 842e9ac | 2010-12-27 17:45:23 +0000 | [diff] [blame] | 86 | // Storages, and 64 bits integer support is disabled. |
Baptiste Lepilleur | 201fb2c | 2010-04-19 07:37:41 +0000 | [diff] [blame] | 87 | // #define JSON_NO_INT64 1 |
| 88 | |
Billy Donahue | dc4a7f9 | 2019-01-17 11:07:53 -0500 | [diff] [blame] | 89 | // JSONCPP_OVERRIDE is maintained for backwards compatibility of external tools. |
| 90 | // C++11 should be used directly in JSONCPP. |
| 91 | #define JSONCPP_OVERRIDE override |
| 92 | |
Christopher Dunn | e0f9aab | 2016-06-26 17:52:19 -0500 | [diff] [blame] | 93 | #if __cplusplus >= 201103L |
Billy Donahue | b5e1fe8 | 2018-05-20 16:55:27 -0400 | [diff] [blame] | 94 | #define JSONCPP_NOEXCEPT noexcept |
| 95 | #define JSONCPP_OP_EXPLICIT explicit |
Hans Johnson | 31d6571 | 2019-01-11 14:13:08 -0600 | [diff] [blame] | 96 | #elif defined(_MSC_VER) && _MSC_VER < 1900 |
Billy Donahue | b5e1fe8 | 2018-05-20 16:55:27 -0400 | [diff] [blame] | 97 | #define JSONCPP_NOEXCEPT throw() |
Billy Donahue | b5e1fe8 | 2018-05-20 16:55:27 -0400 | [diff] [blame] | 98 | #define JSONCPP_OP_EXPLICIT explicit |
Billy Donahue | b5e1fe8 | 2018-05-20 16:55:27 -0400 | [diff] [blame] | 99 | #elif defined(_MSC_VER) && _MSC_VER >= 1900 |
Billy Donahue | b5e1fe8 | 2018-05-20 16:55:27 -0400 | [diff] [blame] | 100 | #define JSONCPP_NOEXCEPT noexcept |
| 101 | #define JSONCPP_OP_EXPLICIT explicit |
| 102 | #else |
Billy Donahue | b5e1fe8 | 2018-05-20 16:55:27 -0400 | [diff] [blame] | 103 | #define JSONCPP_NOEXCEPT throw() |
| 104 | #define JSONCPP_OP_EXPLICIT |
Jean-Christophe Fillion-Robin | ba6fa48 | 2016-04-25 17:35:12 -0400 | [diff] [blame] | 105 | #endif |
Motti | 2b00891 | 2015-04-20 17:44:47 +0300 | [diff] [blame] | 106 | |
m-gupta | 3013ed4 | 2019-09-16 12:24:13 -0700 | [diff] [blame] | 107 | #if defined(__clang__) |
| 108 | #define JSON_USE_INT64_DOUBLE_CONVERSION 1 |
| 109 | #elif defined(__GNUC__) && (__GNUC__ >= 6) |
Billy Donahue | b5e1fe8 | 2018-05-20 16:55:27 -0400 | [diff] [blame] | 110 | #define JSON_USE_INT64_DOUBLE_CONVERSION 1 |
Christopher Dunn | 95f120f | 2016-02-07 11:09:41 -0600 | [diff] [blame] | 111 | #endif |
| 112 | |
Christopher Dunn | 12c67e8 | 2016-03-21 20:33:15 -0500 | [diff] [blame] | 113 | #if !defined(JSON_IS_AMALGAMATION) |
dawesc | f8674c6 | 2016-03-06 11:42:11 -0600 | [diff] [blame] | 114 | |
Billy Donahue | 1c2ed7a | 2019-01-17 16:35:29 -0500 | [diff] [blame] | 115 | #include "allocator.h" |
Billy Donahue | b5e1fe8 | 2018-05-20 16:55:27 -0400 | [diff] [blame] | 116 | #include "version.h" |
Christopher Dunn | 12c67e8 | 2016-03-21 20:33:15 -0500 | [diff] [blame] | 117 | |
Christopher Dunn | 12c67e8 | 2016-03-21 20:33:15 -0500 | [diff] [blame] | 118 | #endif // if !defined(JSON_IS_AMALGAMATION) |
dawesc | f8674c6 | 2016-03-06 11:42:11 -0600 | [diff] [blame] | 119 | |
Baptiste Lepilleur | 201fb2c | 2010-04-19 07:37:41 +0000 | [diff] [blame] | 120 | namespace Json { |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 121 | typedef int Int; |
| 122 | typedef unsigned int UInt; |
| 123 | #if defined(JSON_NO_INT64) |
| 124 | typedef int LargestInt; |
| 125 | typedef unsigned int LargestUInt; |
| 126 | #undef JSON_HAS_INT64 |
| 127 | #else // if defined(JSON_NO_INT64) |
| 128 | // For Microsoft Visual use specific types as long long is not supported |
| 129 | #if defined(_MSC_VER) // Microsoft Visual Studio |
| 130 | typedef __int64 Int64; |
| 131 | typedef unsigned __int64 UInt64; |
| 132 | #else // if defined(_MSC_VER) // Other platforms, use long long |
Christopher Dunn | b9afdf1 | 2016-08-21 19:58:43 -0500 | [diff] [blame] | 133 | typedef int64_t Int64; |
| 134 | typedef uint64_t UInt64; |
Billy Donahue | b5e1fe8 | 2018-05-20 16:55:27 -0400 | [diff] [blame] | 135 | #endif // if defined(_MSC_VER) |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 136 | typedef Int64 LargestInt; |
| 137 | typedef UInt64 LargestUInt; |
| 138 | #define JSON_HAS_INT64 |
| 139 | #endif // if defined(JSON_NO_INT64) |
Billy Donahue | 1c2ed7a | 2019-01-17 16:35:29 -0500 | [diff] [blame] | 140 | |
| 141 | template <typename T> |
| 142 | using Allocator = typename std::conditional<JSONCPP_USING_SECURE_MEMORY, |
| 143 | SecureAllocator<T>, |
Billy Donahue | 2b593a9 | 2019-01-18 03:46:57 -0500 | [diff] [blame] | 144 | std::allocator<T>>::type; |
| 145 | using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>; |
Billy Donahue | 1c2ed7a | 2019-01-17 16:35:29 -0500 | [diff] [blame] | 146 | using IStringStream = std::basic_istringstream<String::value_type, |
| 147 | String::traits_type, |
| 148 | String::allocator_type>; |
| 149 | using OStringStream = std::basic_ostringstream<String::value_type, |
| 150 | String::traits_type, |
| 151 | String::allocator_type>; |
| 152 | using IStream = std::istream; |
| 153 | using OStream = std::ostream; |
| 154 | } // namespace Json |
| 155 | |
| 156 | // Legacy names (formerly macros). |
| 157 | using JSONCPP_STRING = Json::String; |
| 158 | using JSONCPP_ISTRINGSTREAM = Json::IStringStream; |
| 159 | using JSONCPP_OSTRINGSTREAM = Json::OStringStream; |
| 160 | using JSONCPP_ISTREAM = Json::IStream; |
| 161 | using JSONCPP_OSTREAM = Json::OStream; |
Baptiste Lepilleur | 201fb2c | 2010-04-19 07:37:41 +0000 | [diff] [blame] | 162 | |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 163 | #endif // JSON_CONFIG_H_INCLUDED |