| 1 |
// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors |
| 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 |
|
| 6 |
#ifndef JSON_CONFIG_H_INCLUDED |
| 7 |
#define JSON_CONFIG_H_INCLUDED |
| 8 |
|
| 9 |
#if defined(_MSC_VER) |
| 10 |
# pragma warning(push,1) |
| 11 |
#endif |
| 12 |
|
| 13 |
#include <cstddef> |
| 14 |
#include <cstdint> |
| 15 |
#include <istream> |
| 16 |
#include <memory> |
| 17 |
#include <ostream> |
| 18 |
#include <sstream> |
| 19 |
#include <string> |
| 20 |
#include <type_traits> |
| 21 |
|
| 22 |
// If non-zero, the library uses exceptions to report bad input instead of C |
| 23 |
// assertion macros. The default is to use exceptions. |
| 24 |
#ifndef JSON_USE_EXCEPTION |
| 25 |
#define JSON_USE_EXCEPTION 1 |
| 26 |
#endif |
| 27 |
|
| 28 |
// Temporary, tracked for removal with issue #982. |
| 29 |
#ifndef JSON_USE_NULLREF |
| 30 |
#define JSON_USE_NULLREF 1 |
| 31 |
#endif |
| 32 |
|
| 33 |
/// If defined, indicates that the source file is amalgamated |
| 34 |
/// to prevent private header inclusion. |
| 35 |
/// Remarks: it is automatically defined in the generated amalgamated header. |
| 36 |
// #define JSON_IS_AMALGAMATION |
| 37 |
|
| 38 |
// Export macros for DLL visibility |
| 39 |
#if defined(JSON_DLL_BUILD) |
| 40 |
#if defined(_MSC_VER) || defined(__MINGW32__) |
| 41 |
#define JSON_API __declspec(dllexport) |
| 42 |
#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING |
| 43 |
#elif defined(__GNUC__) || defined(__clang__) |
| 44 |
#define JSON_API __attribute__((visibility("default"))) |
| 45 |
#endif // if defined(_MSC_VER) |
| 46 |
|
| 47 |
#elif defined(JSON_DLL) |
| 48 |
#if defined(_MSC_VER) || defined(__MINGW32__) |
| 49 |
#define JSON_API __declspec(dllimport) |
| 50 |
#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING |
| 51 |
#endif // if defined(_MSC_VER) |
| 52 |
#endif // ifdef JSON_DLL_BUILD |
| 53 |
|
| 54 |
#if !defined(JSON_API) |
| 55 |
#define JSON_API |
| 56 |
#endif |
| 57 |
|
| 58 |
#if defined(_MSC_VER) && _MSC_VER < 1800 |
| 59 |
#error \ |
| 60 |
"ERROR: Visual Studio 12 (2013) with _MSC_VER=1800 is the oldest supported compiler with sufficient C++11 capabilities" |
| 61 |
#endif |
| 62 |
|
| 63 |
#if defined(_MSC_VER) && _MSC_VER < 1900 |
| 64 |
// As recommended at |
| 65 |
// https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 |
| 66 |
extern JSON_API int msvc_pre1900_c99_snprintf(char* outBuf, size_t size, |
| 67 |
const char* format, ...); |
| 68 |
#define jsoncpp_snprintf msvc_pre1900_c99_snprintf |
| 69 |
#else |
| 70 |
#define jsoncpp_snprintf std::snprintf |
| 71 |
#endif |
| 72 |
|
| 73 |
// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for |
| 74 |
// integer |
| 75 |
// Storages, and 64 bits integer support is disabled. |
| 76 |
// #define JSON_NO_INT64 1 |
| 77 |
|
| 78 |
// JSONCPP_OVERRIDE is maintained for backwards compatibility of external tools. |
| 79 |
// C++11 should be used directly in JSONCPP. |
| 80 |
#define JSONCPP_OVERRIDE override |
| 81 |
|
| 82 |
#ifdef __clang__ |
| 83 |
#if __has_extension(attribute_deprecated_with_message) |
| 84 |
#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message))) |
| 85 |
#endif |
| 86 |
#elif defined(__GNUC__) // not clang (gcc comes later since clang emulates gcc) |
| 87 |
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) |
| 88 |
#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message))) |
| 89 |
#elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) |
| 90 |
#define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__)) |
| 91 |
#endif // GNUC version |
| 92 |
#elif defined(_MSC_VER) // MSVC (after clang because clang on Windows emulates |
| 93 |
// MSVC) |
| 94 |
#define JSONCPP_DEPRECATED(message) __declspec(deprecated(message)) |
| 95 |
#endif // __clang__ || __GNUC__ || _MSC_VER |
| 96 |
|
| 97 |
#undef JSONCPP_DEPRECATED // no deprecations in CMake copy |
| 98 |
#if !defined(JSONCPP_DEPRECATED) |
| 99 |
#define JSONCPP_DEPRECATED(message) |
| 100 |
#endif // if !defined(JSONCPP_DEPRECATED) |
| 101 |
|
| 102 |
#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 6)) |
| 103 |
#define JSON_USE_INT64_DOUBLE_CONVERSION 1 |
| 104 |
#endif |
| 105 |
|
| 106 |
#if !defined(JSON_IS_AMALGAMATION) |
| 107 |
|
| 108 |
#include "allocator.h" |
| 109 |
#include "version.h" |
| 110 |
|
| 111 |
#endif // if !defined(JSON_IS_AMALGAMATION) |
| 112 |
|
| 113 |
namespace Json { |
| 114 |
using Int = int; |
| 115 |
using UInt = unsigned int; |
| 116 |
#if defined(JSON_NO_INT64) |
| 117 |
using LargestInt = int; |
| 118 |
using LargestUInt = unsigned int; |
| 119 |
#undef JSON_HAS_INT64 |
| 120 |
#else // if defined(JSON_NO_INT64) |
| 121 |
// For Microsoft Visual use specific types as long long is not supported |
| 122 |
#if defined(_MSC_VER) // Microsoft Visual Studio |
| 123 |
using Int64 = __int64; |
| 124 |
using UInt64 = unsigned __int64; |
| 125 |
#else // if defined(_MSC_VER) // Other platforms, use long long |
| 126 |
using Int64 = int64_t; |
| 127 |
using UInt64 = uint64_t; |
| 128 |
#endif // if defined(_MSC_VER) |
| 129 |
using LargestInt = Int64; |
| 130 |
using LargestUInt = UInt64; |
| 131 |
#define JSON_HAS_INT64 |
| 132 |
#endif // if defined(JSON_NO_INT64) |
| 133 |
|
| 134 |
template <typename T> |
| 135 |
using Allocator = |
| 136 |
typename std::conditional<JSONCPP_USING_SECURE_MEMORY, SecureAllocator<T>, |
| 137 |
std::allocator<T>>::type; |
| 138 |
using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>; |
| 139 |
using IStringStream = |
| 140 |
std::basic_istringstream<String::value_type, String::traits_type, |
| 141 |
String::allocator_type>; |
| 142 |
using OStringStream = |
| 143 |
std::basic_ostringstream<String::value_type, String::traits_type, |
| 144 |
String::allocator_type>; |
| 145 |
using IStream = std::istream; |
| 146 |
using OStream = std::ostream; |
| 147 |
} // namespace Json |
| 148 |
|
| 149 |
// Legacy names (formerly macros). |
| 150 |
using JSONCPP_STRING = Json::String; |
| 151 |
using JSONCPP_ISTRINGSTREAM = Json::IStringStream; |
| 152 |
using JSONCPP_OSTRINGSTREAM = Json::OStringStream; |
| 153 |
using JSONCPP_ISTREAM = Json::IStream; |
| 154 |
using JSONCPP_OSTREAM = Json::OStream; |
| 155 |
|
| 156 |
#endif // JSON_CONFIG_H_INCLUDED |