blob: 6359273a2228f822b1e9634a9221cc82f18bd491 [file] [log] [blame]
Devin Jeanpierre59e4d352017-07-21 03:44:36 -07001// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
Baptiste Lepilleur7469f1d2010-04-20 21:35:19 +00002// 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 Dunn6d135cb2007-06-13 15:51:04 +00006#ifndef JSON_CONFIG_H_INCLUDED
Aaron Jacobs9fa4e842014-07-01 08:48:54 +10007#define JSON_CONFIG_H_INCLUDED
Hans Johnsone50bfef2018-12-12 13:34:37 -06008#include <cstddef>
Billy Donahue1c2ed7a2019-01-17 16:35:29 -05009#include <cstdint>
10#include <istream>
11#include <memory>
12#include <ostream>
13#include <sstream>
14#include <string>
15#include <type_traits>
Christopher Dunn6d135cb2007-06-13 15:51:04 +000016
Aaron Jacobs7c507d72011-09-14 08:41:37 +000017// If non-zero, the library uses exceptions to report bad input instead of C
18// assertion macros. The default is to use exceptions.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100019#ifndef JSON_USE_EXCEPTION
20#define JSON_USE_EXCEPTION 1
21#endif
Christopher Dunn6d135cb2007-06-13 15:51:04 +000022
Jordan Bayles25c57812019-07-11 14:27:29 -070023// Temporary, tracked for removal with issue #982.
24#ifndef JSON_USE_NULLREF
25#define JSON_USE_NULLREF 1
26#endif
27
Josh Sorefe6a588a2017-12-03 11:54:29 -050028/// If defined, indicates that the source file is amalgamated
Baptiste Lepilleur64e40aa2011-05-01 20:13:40 +000029/// to prevent private header inclusion.
Josh Sorefe6a588a2017-12-03 11:54:29 -050030/// Remarks: it is automatically defined in the generated amalgamated header.
Baptiste Lepilleureadc4782011-05-02 21:09:30 +000031// #define JSON_IS_AMALGAMATION
Baptiste Lepilleur64e40aa2011-05-01 20:13:40 +000032
Jordan Baylesa4812012019-11-14 10:15:49 -080033// 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 Jacobs9fa4e842014-07-01 08:48:54 +100049#if !defined(JSON_API)
50#define JSON_API
51#endif
Christopher Dunn6d135cb2007-06-13 15:51:04 +000052
Hans Johnson31d65712019-01-11 14:13:08 -060053#if defined(_MSC_VER) && _MSC_VER < 1800
Billy Donahuedc4a7f92019-01-17 11:07:53 -050054#error \
55 "ERROR: Visual Studio 12 (2013) with _MSC_VER=1800 is the oldest supported compiler with sufficient C++11 capabilities"
Hans Johnson31d65712019-01-11 14:13:08 -060056#endif
57
Hans Johnson5c8e5392018-12-12 13:31:55 -060058#if defined(_MSC_VER) && _MSC_VER < 1900
Billy Donahuedc4a7f92019-01-17 11:07:53 -050059// As recommended at
60// https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
Jordan Baylesf34bf242019-10-11 11:19:00 -070061extern JSON_API int msvc_pre1900_c99_snprintf(char* outBuf, size_t size,
62 const char* format, ...);
Billy Donahuedc4a7f92019-01-17 11:07:53 -050063#define jsoncpp_snprintf msvc_pre1900_c99_snprintf
Hans Johnson5c8e5392018-12-12 13:31:55 -060064#else
Billy Donahuedc4a7f92019-01-17 11:07:53 -050065#define jsoncpp_snprintf std::snprintf
Hans Johnson5c8e5392018-12-12 13:31:55 -060066#endif
67
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100068// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for
69// integer
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +000070// Storages, and 64 bits integer support is disabled.
Baptiste Lepilleur201fb2c2010-04-19 07:37:41 +000071// #define JSON_NO_INT64 1
72
Billy Donahuedc4a7f92019-01-17 11:07:53 -050073// 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 Baylesf34bf242019-10-11 11:19:00 -070077#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 Donahueb5e1fe82018-05-20 16:55:27 -040097#define JSON_USE_INT64_DOUBLE_CONVERSION 1
Christopher Dunn95f120f2016-02-07 11:09:41 -060098#endif
99
Christopher Dunn12c67e82016-03-21 20:33:15 -0500100#if !defined(JSON_IS_AMALGAMATION)
dawescf8674c62016-03-06 11:42:11 -0600101
Billy Donahue1c2ed7a2019-01-17 16:35:29 -0500102#include "allocator.h"
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400103#include "version.h"
Christopher Dunn12c67e82016-03-21 20:33:15 -0500104
Christopher Dunn12c67e82016-03-21 20:33:15 -0500105#endif // if !defined(JSON_IS_AMALGAMATION)
dawescf8674c62016-03-06 11:42:11 -0600106
Baptiste Lepilleur201fb2c2010-04-19 07:37:41 +0000107namespace Json {
Chen2983f5a2019-12-04 09:08:45 +0800108using Int = int;
109using UInt = unsigned int;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000110#if defined(JSON_NO_INT64)
Chen2983f5a2019-12-04 09:08:45 +0800111using LargestInt = int;
112using LargestUInt = unsigned int;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000113#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
Chen2983f5a2019-12-04 09:08:45 +0800117using Int64 = __int64;
118using UInt64 = unsigned __int64;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000119#else // if defined(_MSC_VER) // Other platforms, use long long
Chen2983f5a2019-12-04 09:08:45 +0800120using Int64 = int64_t;
121using UInt64 = uint64_t;
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400122#endif // if defined(_MSC_VER)
Chen2983f5a2019-12-04 09:08:45 +0800123using LargestInt = Int64;
124using LargestUInt = UInt64;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000125#define JSON_HAS_INT64
126#endif // if defined(JSON_NO_INT64)
Billy Donahue1c2ed7a2019-01-17 16:35:29 -0500127
128template <typename T>
Jordan Baylesf34bf242019-10-11 11:19:00 -0700129using Allocator =
130 typename std::conditional<JSONCPP_USING_SECURE_MEMORY, SecureAllocator<T>,
131 std::allocator<T>>::type;
Billy Donahue2b593a92019-01-18 03:46:57 -0500132using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>;
Jordan Baylesf34bf242019-10-11 11:19:00 -0700133using IStringStream =
134 std::basic_istringstream<String::value_type, String::traits_type,
135 String::allocator_type>;
136using OStringStream =
137 std::basic_ostringstream<String::value_type, String::traits_type,
138 String::allocator_type>;
Billy Donahue1c2ed7a2019-01-17 16:35:29 -0500139using IStream = std::istream;
140using OStream = std::ostream;
141} // namespace Json
142
143// Legacy names (formerly macros).
144using JSONCPP_STRING = Json::String;
145using JSONCPP_ISTRINGSTREAM = Json::IStringStream;
146using JSONCPP_OSTRINGSTREAM = Json::OStringStream;
147using JSONCPP_ISTREAM = Json::IStream;
148using JSONCPP_OSTREAM = Json::OStream;
Baptiste Lepilleur201fb2c2010-04-19 07:37:41 +0000149
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000150#endif // JSON_CONFIG_H_INCLUDED