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 | |
Aaron Jacobs | 7c507d7 | 2011-09-14 08:41:37 +0000 | [diff] [blame] | 17 | // If non-zero, the library uses exceptions to report bad input instead of C |
| 18 | // assertion macros. The default is to use exceptions. |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 19 | #ifndef JSON_USE_EXCEPTION |
| 20 | #define JSON_USE_EXCEPTION 1 |
| 21 | #endif |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 22 | |
Jordan Bayles | 25c5781 | 2019-07-11 14:27:29 -0700 | [diff] [blame] | 23 | // Temporary, tracked for removal with issue #982. |
| 24 | #ifndef JSON_USE_NULLREF |
| 25 | #define JSON_USE_NULLREF 1 |
| 26 | #endif |
| 27 | |
Josh Soref | e6a588a | 2017-12-03 11:54:29 -0500 | [diff] [blame] | 28 | /// If defined, indicates that the source file is amalgamated |
Baptiste Lepilleur | 64e40aa | 2011-05-01 20:13:40 +0000 | [diff] [blame] | 29 | /// to prevent private header inclusion. |
Josh Soref | e6a588a | 2017-12-03 11:54:29 -0500 | [diff] [blame] | 30 | /// Remarks: it is automatically defined in the generated amalgamated header. |
Baptiste Lepilleur | eadc478 | 2011-05-02 21:09:30 +0000 | [diff] [blame] | 31 | // #define JSON_IS_AMALGAMATION |
Baptiste Lepilleur | 64e40aa | 2011-05-01 20:13:40 +0000 | [diff] [blame] | 32 | |
Jordan Bayles | a481201 | 2019-11-14 10:15:49 -0800 | [diff] [blame] | 33 | // Export macros for DLL visibility |
| 34 | #if defined(JSON_DLL_BUILD) |
| 35 | #if defined(_MSC_VER) || defined(__MINGW32__) |
| 36 | #define JSON_API __declspec(dllexport) |
| 37 | #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING |
| 38 | #elif defined(__GNUC__) || defined(__clang__) |
| 39 | #define JSON_API __attribute__((visibility("default"))) |
| 40 | #endif // if defined(_MSC_VER) |
| 41 | |
| 42 | #elif defined(JSON_DLL) |
| 43 | #if defined(_MSC_VER) || defined(__MINGW32__) |
| 44 | #define JSON_API __declspec(dllimport) |
| 45 | #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING |
| 46 | #endif // if defined(_MSC_VER) |
| 47 | #endif // ifdef JSON_DLL_BUILD |
| 48 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 49 | #if !defined(JSON_API) |
| 50 | #define JSON_API |
| 51 | #endif |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 52 | |
Hans Johnson | 31d6571 | 2019-01-11 14:13:08 -0600 | [diff] [blame] | 53 | #if defined(_MSC_VER) && _MSC_VER < 1800 |
Billy Donahue | dc4a7f9 | 2019-01-17 11:07:53 -0500 | [diff] [blame] | 54 | #error \ |
| 55 | "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] | 56 | #endif |
| 57 | |
Hans Johnson | 5c8e539 | 2018-12-12 13:31:55 -0600 | [diff] [blame] | 58 | #if defined(_MSC_VER) && _MSC_VER < 1900 |
Billy Donahue | dc4a7f9 | 2019-01-17 11:07:53 -0500 | [diff] [blame] | 59 | // As recommended at |
| 60 | // https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 |
Jordan Bayles | f34bf24 | 2019-10-11 11:19:00 -0700 | [diff] [blame] | 61 | extern JSON_API int msvc_pre1900_c99_snprintf(char* outBuf, size_t size, |
| 62 | const char* format, ...); |
Billy Donahue | dc4a7f9 | 2019-01-17 11:07:53 -0500 | [diff] [blame] | 63 | #define jsoncpp_snprintf msvc_pre1900_c99_snprintf |
Hans Johnson | 5c8e539 | 2018-12-12 13:31:55 -0600 | [diff] [blame] | 64 | #else |
Billy Donahue | dc4a7f9 | 2019-01-17 11:07:53 -0500 | [diff] [blame] | 65 | #define jsoncpp_snprintf std::snprintf |
Hans Johnson | 5c8e539 | 2018-12-12 13:31:55 -0600 | [diff] [blame] | 66 | #endif |
| 67 | |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 68 | // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for |
| 69 | // integer |
Baptiste Lepilleur | 842e9ac | 2010-12-27 17:45:23 +0000 | [diff] [blame] | 70 | // Storages, and 64 bits integer support is disabled. |
Baptiste Lepilleur | 201fb2c | 2010-04-19 07:37:41 +0000 | [diff] [blame] | 71 | // #define JSON_NO_INT64 1 |
| 72 | |
Billy Donahue | dc4a7f9 | 2019-01-17 11:07:53 -0500 | [diff] [blame] | 73 | // JSONCPP_OVERRIDE is maintained for backwards compatibility of external tools. |
| 74 | // C++11 should be used directly in JSONCPP. |
| 75 | #define JSONCPP_OVERRIDE override |
| 76 | |
Jordan Bayles | f34bf24 | 2019-10-11 11:19:00 -0700 | [diff] [blame] | 77 | #ifdef __clang__ |
| 78 | #if __has_extension(attribute_deprecated_with_message) |
| 79 | #define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message))) |
| 80 | #endif |
| 81 | #elif defined(__GNUC__) // not clang (gcc comes later since clang emulates gcc) |
| 82 | #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) |
| 83 | #define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message))) |
| 84 | #elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) |
| 85 | #define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__)) |
| 86 | #endif // GNUC version |
| 87 | #elif defined(_MSC_VER) // MSVC (after clang because clang on Windows emulates |
| 88 | // MSVC) |
| 89 | #define JSONCPP_DEPRECATED(message) __declspec(deprecated(message)) |
| 90 | #endif // __clang__ || __GNUC__ || _MSC_VER |
| 91 | |
| 92 | #if !defined(JSONCPP_DEPRECATED) |
| 93 | #define JSONCPP_DEPRECATED(message) |
| 94 | #endif // if !defined(JSONCPP_DEPRECATED) |
| 95 | |
| 96 | #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 6)) |
Billy Donahue | b5e1fe8 | 2018-05-20 16:55:27 -0400 | [diff] [blame] | 97 | #define JSON_USE_INT64_DOUBLE_CONVERSION 1 |
Christopher Dunn | 95f120f | 2016-02-07 11:09:41 -0600 | [diff] [blame] | 98 | #endif |
| 99 | |
Christopher Dunn | 12c67e8 | 2016-03-21 20:33:15 -0500 | [diff] [blame] | 100 | #if !defined(JSON_IS_AMALGAMATION) |
dawesc | f8674c6 | 2016-03-06 11:42:11 -0600 | [diff] [blame] | 101 | |
Billy Donahue | 1c2ed7a | 2019-01-17 16:35:29 -0500 | [diff] [blame] | 102 | #include "allocator.h" |
Billy Donahue | b5e1fe8 | 2018-05-20 16:55:27 -0400 | [diff] [blame] | 103 | #include "version.h" |
Christopher Dunn | 12c67e8 | 2016-03-21 20:33:15 -0500 | [diff] [blame] | 104 | |
Christopher Dunn | 12c67e8 | 2016-03-21 20:33:15 -0500 | [diff] [blame] | 105 | #endif // if !defined(JSON_IS_AMALGAMATION) |
dawesc | f8674c6 | 2016-03-06 11:42:11 -0600 | [diff] [blame] | 106 | |
Baptiste Lepilleur | 201fb2c | 2010-04-19 07:37:41 +0000 | [diff] [blame] | 107 | namespace Json { |
Chen | 2983f5a | 2019-12-04 09:08:45 +0800 | [diff] [blame] | 108 | using Int = int; |
| 109 | using UInt = unsigned int; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 110 | #if defined(JSON_NO_INT64) |
Chen | 2983f5a | 2019-12-04 09:08:45 +0800 | [diff] [blame] | 111 | using LargestInt = int; |
| 112 | using LargestUInt = unsigned int; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 113 | #undef JSON_HAS_INT64 |
| 114 | #else // if defined(JSON_NO_INT64) |
| 115 | // For Microsoft Visual use specific types as long long is not supported |
| 116 | #if defined(_MSC_VER) // Microsoft Visual Studio |
Chen | 2983f5a | 2019-12-04 09:08:45 +0800 | [diff] [blame] | 117 | using Int64 = __int64; |
| 118 | using UInt64 = unsigned __int64; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 119 | #else // if defined(_MSC_VER) // Other platforms, use long long |
Chen | 2983f5a | 2019-12-04 09:08:45 +0800 | [diff] [blame] | 120 | using Int64 = int64_t; |
| 121 | using UInt64 = uint64_t; |
Billy Donahue | b5e1fe8 | 2018-05-20 16:55:27 -0400 | [diff] [blame] | 122 | #endif // if defined(_MSC_VER) |
Chen | 2983f5a | 2019-12-04 09:08:45 +0800 | [diff] [blame] | 123 | using LargestInt = Int64; |
| 124 | using LargestUInt = UInt64; |
Aaron Jacobs | 9fa4e84 | 2014-07-01 08:48:54 +1000 | [diff] [blame] | 125 | #define JSON_HAS_INT64 |
| 126 | #endif // if defined(JSON_NO_INT64) |
Billy Donahue | 1c2ed7a | 2019-01-17 16:35:29 -0500 | [diff] [blame] | 127 | |
| 128 | template <typename T> |
Jordan Bayles | f34bf24 | 2019-10-11 11:19:00 -0700 | [diff] [blame] | 129 | using Allocator = |
| 130 | typename std::conditional<JSONCPP_USING_SECURE_MEMORY, SecureAllocator<T>, |
| 131 | std::allocator<T>>::type; |
Billy Donahue | 2b593a9 | 2019-01-18 03:46:57 -0500 | [diff] [blame] | 132 | using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>; |
Jordan Bayles | f34bf24 | 2019-10-11 11:19:00 -0700 | [diff] [blame] | 133 | using IStringStream = |
| 134 | std::basic_istringstream<String::value_type, String::traits_type, |
| 135 | String::allocator_type>; |
| 136 | using OStringStream = |
| 137 | std::basic_ostringstream<String::value_type, String::traits_type, |
| 138 | String::allocator_type>; |
Billy Donahue | 1c2ed7a | 2019-01-17 16:35:29 -0500 | [diff] [blame] | 139 | using IStream = std::istream; |
| 140 | using OStream = std::ostream; |
| 141 | } // namespace Json |
| 142 | |
| 143 | // Legacy names (formerly macros). |
| 144 | using JSONCPP_STRING = Json::String; |
| 145 | using JSONCPP_ISTRINGSTREAM = Json::IStringStream; |
| 146 | using JSONCPP_OSTRINGSTREAM = Json::OStringStream; |
| 147 | using JSONCPP_ISTREAM = Json::IStream; |
| 148 | using JSONCPP_OSTREAM = Json::OStream; |
Baptiste Lepilleur | 201fb2c | 2010-04-19 07:37:41 +0000 | [diff] [blame] | 149 | |
Christopher Dunn | 6d135cb | 2007-06-13 15:51:04 +0000 | [diff] [blame] | 150 | #endif // JSON_CONFIG_H_INCLUDED |