blob: 69125674b04c7ff7f4ee13aa934fb5f0a093564b [file] [log] [blame]
Haibo Huangb0bee822021-02-24 15:40:15 -08001// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
Leon Scroggins IIIf59fb0e2014-05-28 15:19:42 -04002// 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
Derek Sollenberger2eb3b4d2016-01-11 14:41:40 -05007#define JSON_CONFIG_H_INCLUDED
Haibo Huangb0bee822021-02-24 15:40:15 -08008#include <cstddef>
9#include <cstdint>
10#include <istream>
11#include <memory>
12#include <ostream>
13#include <sstream>
14#include <string>
15#include <type_traits>
Leon Scroggins IIIf59fb0e2014-05-28 15:19:42 -040016
17// If non-zero, the library uses exceptions to report bad input instead of C
18// assertion macros. The default is to use exceptions.
Derek Sollenberger2eb3b4d2016-01-11 14:41:40 -050019#ifndef JSON_USE_EXCEPTION
20#define JSON_USE_EXCEPTION 1
21#endif
Leon Scroggins IIIf59fb0e2014-05-28 15:19:42 -040022
Haibo Huangb0bee822021-02-24 15:40:15 -080023// Temporary, tracked for removal with issue #982.
24#ifndef JSON_USE_NULLREF
25#define JSON_USE_NULLREF 1
26#endif
27
28/// If defined, indicates that the source file is amalgamated
Leon Scroggins IIIf59fb0e2014-05-28 15:19:42 -040029/// to prevent private header inclusion.
Haibo Huangb0bee822021-02-24 15:40:15 -080030/// Remarks: it is automatically defined in the generated amalgamated header.
Leon Scroggins IIIf59fb0e2014-05-28 15:19:42 -040031// #define JSON_IS_AMALGAMATION
32
Haibo Huangb0bee822021-02-24 15:40:15 -080033// Export macros for DLL visibility
34#if defined(JSON_DLL_BUILD)
35#if defined(_MSC_VER) || defined(__MINGW32__)
Derek Sollenberger2eb3b4d2016-01-11 14:41:40 -050036#define JSON_API __declspec(dllexport)
37#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
Haibo Huangb0bee822021-02-24 15:40:15 -080038#elif defined(__GNUC__) || defined(__clang__)
39#define JSON_API __attribute__((visibility("default")))
Derek Sollenberger2eb3b4d2016-01-11 14:41:40 -050040#endif // if defined(_MSC_VER)
Haibo Huangb0bee822021-02-24 15:40:15 -080041
Derek Sollenberger2eb3b4d2016-01-11 14:41:40 -050042#elif defined(JSON_DLL)
Haibo Huangb0bee822021-02-24 15:40:15 -080043#if defined(_MSC_VER) || defined(__MINGW32__)
Derek Sollenberger2eb3b4d2016-01-11 14:41:40 -050044#define JSON_API __declspec(dllimport)
45#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
46#endif // if defined(_MSC_VER)
Haibo Huangb0bee822021-02-24 15:40:15 -080047#endif // ifdef JSON_DLL_BUILD
48
Derek Sollenberger2eb3b4d2016-01-11 14:41:40 -050049#if !defined(JSON_API)
50#define JSON_API
51#endif
Leon Scroggins IIIf59fb0e2014-05-28 15:19:42 -040052
Haibo Huangb0bee822021-02-24 15:40:15 -080053#if defined(_MSC_VER) && _MSC_VER < 1800
54#error \
55 "ERROR: Visual Studio 12 (2013) with _MSC_VER=1800 is the oldest supported compiler with sufficient C++11 capabilities"
56#endif
57
58#if defined(_MSC_VER) && _MSC_VER < 1900
59// As recommended at
60// https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
61extern JSON_API int msvc_pre1900_c99_snprintf(char* outBuf, size_t size,
62 const char* format, ...);
63#define jsoncpp_snprintf msvc_pre1900_c99_snprintf
64#else
65#define jsoncpp_snprintf std::snprintf
66#endif
67
Derek Sollenberger2eb3b4d2016-01-11 14:41:40 -050068// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for
69// integer
Leon Scroggins IIIf59fb0e2014-05-28 15:19:42 -040070// Storages, and 64 bits integer support is disabled.
71// #define JSON_NO_INT64 1
72
Haibo Huangb0bee822021-02-24 15:40:15 -080073// JSONCPP_OVERRIDE is maintained for backwards compatibility of external tools.
74// C++11 should be used directly in JSONCPP.
75#define JSONCPP_OVERRIDE override
Leon Scroggins IIIf59fb0e2014-05-28 15:19:42 -040076
Haibo Huangca86dbe2021-02-25 12:06:43 -080077#if 0 // Android change: b/170642246
Haibo Huangb0bee822021-02-24 15:40:15 -080078#ifdef __clang__
79#if __has_extension(attribute_deprecated_with_message)
80#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
Leon Scroggins IIIf59fb0e2014-05-28 15:19:42 -040081#endif
Haibo Huangb0bee822021-02-24 15:40:15 -080082#elif defined(__GNUC__) // not clang (gcc comes later since clang emulates gcc)
83#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
84#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
85#elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
86#define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
87#endif // GNUC version
88#elif defined(_MSC_VER) // MSVC (after clang because clang on Windows emulates
89 // MSVC)
90#define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
91#endif // __clang__ || __GNUC__ || _MSC_VER
Haibo Huangca86dbe2021-02-25 12:06:43 -080092#endif // Android change: b/170642246
Leon Scroggins IIIf59fb0e2014-05-28 15:19:42 -040093
94#if !defined(JSONCPP_DEPRECATED)
Derek Sollenberger2eb3b4d2016-01-11 14:41:40 -050095#define JSONCPP_DEPRECATED(message)
Leon Scroggins IIIf59fb0e2014-05-28 15:19:42 -040096#endif // if !defined(JSONCPP_DEPRECATED)
97
Haibo Huangb0bee822021-02-24 15:40:15 -080098#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 6))
99#define JSON_USE_INT64_DOUBLE_CONVERSION 1
100#endif
101
102#if !defined(JSON_IS_AMALGAMATION)
103
104#include "allocator.h"
105#include "version.h"
106
107#endif // if !defined(JSON_IS_AMALGAMATION)
108
Leon Scroggins IIIf59fb0e2014-05-28 15:19:42 -0400109namespace Json {
Haibo Huangb0bee822021-02-24 15:40:15 -0800110using Int = int;
111using UInt = unsigned int;
Derek Sollenberger2eb3b4d2016-01-11 14:41:40 -0500112#if defined(JSON_NO_INT64)
Haibo Huangb0bee822021-02-24 15:40:15 -0800113using LargestInt = int;
114using LargestUInt = unsigned int;
Derek Sollenberger2eb3b4d2016-01-11 14:41:40 -0500115#undef JSON_HAS_INT64
116#else // if defined(JSON_NO_INT64)
117// For Microsoft Visual use specific types as long long is not supported
118#if defined(_MSC_VER) // Microsoft Visual Studio
Haibo Huangb0bee822021-02-24 15:40:15 -0800119using Int64 = __int64;
120using UInt64 = unsigned __int64;
Derek Sollenberger2eb3b4d2016-01-11 14:41:40 -0500121#else // if defined(_MSC_VER) // Other platforms, use long long
Haibo Huangb0bee822021-02-24 15:40:15 -0800122using Int64 = int64_t;
123using UInt64 = uint64_t;
124#endif // if defined(_MSC_VER)
125using LargestInt = Int64;
126using LargestUInt = UInt64;
Derek Sollenberger2eb3b4d2016-01-11 14:41:40 -0500127#define JSON_HAS_INT64
128#endif // if defined(JSON_NO_INT64)
Haibo Huangb0bee822021-02-24 15:40:15 -0800129
130template <typename T>
131using Allocator =
132 typename std::conditional<JSONCPP_USING_SECURE_MEMORY, SecureAllocator<T>,
133 std::allocator<T>>::type;
134using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>;
135using IStringStream =
136 std::basic_istringstream<String::value_type, String::traits_type,
137 String::allocator_type>;
138using OStringStream =
139 std::basic_ostringstream<String::value_type, String::traits_type,
140 String::allocator_type>;
141using IStream = std::istream;
142using OStream = std::ostream;
143} // namespace Json
144
145// Legacy names (formerly macros).
146using JSONCPP_STRING = Json::String;
147using JSONCPP_ISTRINGSTREAM = Json::IStringStream;
148using JSONCPP_OSTRINGSTREAM = Json::OStringStream;
149using JSONCPP_ISTREAM = Json::IStream;
150using JSONCPP_OSTREAM = Json::OStream;
Leon Scroggins IIIf59fb0e2014-05-28 15:19:42 -0400151
Leon Scroggins IIIf59fb0e2014-05-28 15:19:42 -0400152#endif // JSON_CONFIG_H_INCLUDED