blob: 541d168b097b19915135517ee6fff7ba60ff7c6c [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
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 Jacobs9fa4e842014-07-01 08:48:54 +100022/// If defined, indicates that cpptl vector based map should be used instead of
23/// std::map
Christopher Dunn6d135cb2007-06-13 15:51:04 +000024/// as Value container.
25//# define JSON_USE_CPPTL_SMALLMAP 1
Christopher Dunn6d135cb2007-06-13 15:51:04 +000026
Aaron Jacobs7c507d72011-09-14 08:41:37 +000027// If non-zero, the library uses exceptions to report bad input instead of C
28// assertion macros. The default is to use exceptions.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100029#ifndef JSON_USE_EXCEPTION
30#define JSON_USE_EXCEPTION 1
31#endif
Christopher Dunn6d135cb2007-06-13 15:51:04 +000032
Josh Sorefe6a588a2017-12-03 11:54:29 -050033/// If defined, indicates that the source file is amalgamated
Baptiste Lepilleur64e40aa2011-05-01 20:13:40 +000034/// to prevent private header inclusion.
Josh Sorefe6a588a2017-12-03 11:54:29 -050035/// Remarks: it is automatically defined in the generated amalgamated header.
Baptiste Lepilleureadc4782011-05-02 21:09:30 +000036// #define JSON_IS_AMALGAMATION
Baptiste Lepilleur64e40aa2011-05-01 20:13:40 +000037
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100038#ifdef JSON_IN_CPPTL
39#include <cpptl/config.h>
40#ifndef JSON_USE_CPPTL
41#define JSON_USE_CPPTL 1
42#endif
43#endif
Baptiste Lepilleur64e40aa2011-05-01 20:13:40 +000044
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100045#ifdef JSON_IN_CPPTL
46#define JSON_API CPPTL_API
47#elif defined(JSON_DLL_BUILD)
Gaurav8aabf932016-03-08 17:34:22 +053048#if defined(_MSC_VER) || defined(__MINGW32__)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100049#define JSON_API __declspec(dllexport)
50#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
51#endif // if defined(_MSC_VER)
52#elif defined(JSON_DLL)
Gaurav8aabf932016-03-08 17:34:22 +053053#if defined(_MSC_VER) || defined(__MINGW32__)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100054#define JSON_API __declspec(dllimport)
55#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
56#endif // if defined(_MSC_VER)
57#endif // ifdef JSON_IN_CPPTL
58#if !defined(JSON_API)
59#define JSON_API
60#endif
Christopher Dunn6d135cb2007-06-13 15:51:04 +000061
Hans Johnson31d65712019-01-11 14:13:08 -060062#if defined(_MSC_VER) && _MSC_VER < 1800
Billy Donahuedc4a7f92019-01-17 11:07:53 -050063#error \
64 "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 -060065#endif
66
Hans Johnson5c8e5392018-12-12 13:31:55 -060067#if defined(_MSC_VER) && _MSC_VER < 1900
Billy Donahuedc4a7f92019-01-17 11:07:53 -050068// As recommended at
69// https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
70extern JSON_API int
71msvc_pre1900_c99_snprintf(char* outBuf, size_t size, const char* format, ...);
72#define jsoncpp_snprintf msvc_pre1900_c99_snprintf
Hans Johnson5c8e5392018-12-12 13:31:55 -060073#else
Billy Donahuedc4a7f92019-01-17 11:07:53 -050074#define jsoncpp_snprintf std::snprintf
Hans Johnson5c8e5392018-12-12 13:31:55 -060075#endif
76
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100077// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for
78// integer
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +000079// Storages, and 64 bits integer support is disabled.
Baptiste Lepilleur201fb2c2010-04-19 07:37:41 +000080// #define JSON_NO_INT64 1
81
Billy Donahuedc4a7f92019-01-17 11:07:53 -050082// JSONCPP_OVERRIDE is maintained for backwards compatibility of external tools.
83// C++11 should be used directly in JSONCPP.
84#define JSONCPP_OVERRIDE override
85
Christopher Dunne0f9aab2016-06-26 17:52:19 -050086#if __cplusplus >= 201103L
Billy Donahueb5e1fe82018-05-20 16:55:27 -040087#define JSONCPP_NOEXCEPT noexcept
88#define JSONCPP_OP_EXPLICIT explicit
Hans Johnson31d65712019-01-11 14:13:08 -060089#elif defined(_MSC_VER) && _MSC_VER < 1900
Billy Donahueb5e1fe82018-05-20 16:55:27 -040090#define JSONCPP_NOEXCEPT throw()
Billy Donahueb5e1fe82018-05-20 16:55:27 -040091#define JSONCPP_OP_EXPLICIT explicit
Billy Donahueb5e1fe82018-05-20 16:55:27 -040092#elif defined(_MSC_VER) && _MSC_VER >= 1900
Billy Donahueb5e1fe82018-05-20 16:55:27 -040093#define JSONCPP_NOEXCEPT noexcept
94#define JSONCPP_OP_EXPLICIT explicit
95#else
Billy Donahueb5e1fe82018-05-20 16:55:27 -040096#define JSONCPP_NOEXCEPT throw()
97#define JSONCPP_OP_EXPLICIT
Jean-Christophe Fillion-Robinba6fa482016-04-25 17:35:12 -040098#endif
Motti2b008912015-04-20 17:44:47 +030099
100#ifndef JSON_HAS_RVALUE_REFERENCES
101
Hans Johnson31d65712019-01-11 14:13:08 -0600102#if defined(_MSC_VER)
Motti2b008912015-04-20 17:44:47 +0300103#define JSON_HAS_RVALUE_REFERENCES 1
Hans Johnson31d65712019-01-11 14:13:08 -0600104#endif // MSVC >= 2013
Motti2b008912015-04-20 17:44:47 +0300105
106#ifdef __clang__
107#if __has_feature(cxx_rvalue_references)
108#define JSON_HAS_RVALUE_REFERENCES 1
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400109#endif // has_feature
Motti2b008912015-04-20 17:44:47 +0300110
111#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
112#if defined(__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L)
113#define JSON_HAS_RVALUE_REFERENCES 1
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400114#endif // GXX_EXPERIMENTAL
Motti2b008912015-04-20 17:44:47 +0300115
116#endif // __clang__ || __GNUC__
117
118#endif // not defined JSON_HAS_RVALUE_REFERENCES
119
120#ifndef JSON_HAS_RVALUE_REFERENCES
121#define JSON_HAS_RVALUE_REFERENCES 0
Dani-Hub50039832015-03-08 18:48:24 +0100122#endif
Motti2b008912015-04-20 17:44:47 +0300123
124#ifdef __clang__
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400125#if __has_extension(attribute_deprecated_with_message)
126#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
127#endif
Motti2b008912015-04-20 17:44:47 +0300128#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400129#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
130#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
131#elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
132#define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
133#endif // GNUC version
Marcel Raad36d8cfd2019-02-25 15:24:03 +0100134#elif defined(_MSC_VER) // MSVC (after clang because clang on Windows emulates MSVC)
135#define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
136#endif // __clang__ || __GNUC__ || _MSC_VER
Baptiste Lepilleurb2e8ccc2011-05-01 16:27:55 +0000137
138#if !defined(JSONCPP_DEPRECATED)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000139#define JSONCPP_DEPRECATED(message)
Baptiste Lepilleurb2e8ccc2011-05-01 16:27:55 +0000140#endif // if !defined(JSONCPP_DEPRECATED)
Baptiste Lepilleur201fb2c2010-04-19 07:37:41 +0000141
Christopher Dunn95f120f2016-02-07 11:09:41 -0600142#if __GNUC__ >= 6
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400143#define JSON_USE_INT64_DOUBLE_CONVERSION 1
Christopher Dunn95f120f2016-02-07 11:09:41 -0600144#endif
145
Christopher Dunn12c67e82016-03-21 20:33:15 -0500146#if !defined(JSON_IS_AMALGAMATION)
dawescf8674c62016-03-06 11:42:11 -0600147
Billy Donahue1c2ed7a2019-01-17 16:35:29 -0500148#include "allocator.h"
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400149#include "version.h"
Christopher Dunn12c67e82016-03-21 20:33:15 -0500150
Christopher Dunn12c67e82016-03-21 20:33:15 -0500151#endif // if !defined(JSON_IS_AMALGAMATION)
dawescf8674c62016-03-06 11:42:11 -0600152
Baptiste Lepilleur201fb2c2010-04-19 07:37:41 +0000153namespace Json {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000154typedef int Int;
155typedef unsigned int UInt;
156#if defined(JSON_NO_INT64)
157typedef int LargestInt;
158typedef unsigned int LargestUInt;
159#undef JSON_HAS_INT64
160#else // if defined(JSON_NO_INT64)
161// For Microsoft Visual use specific types as long long is not supported
162#if defined(_MSC_VER) // Microsoft Visual Studio
163typedef __int64 Int64;
164typedef unsigned __int64 UInt64;
165#else // if defined(_MSC_VER) // Other platforms, use long long
Christopher Dunnb9afdf12016-08-21 19:58:43 -0500166typedef int64_t Int64;
167typedef uint64_t UInt64;
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400168#endif // if defined(_MSC_VER)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000169typedef Int64 LargestInt;
170typedef UInt64 LargestUInt;
171#define JSON_HAS_INT64
172#endif // if defined(JSON_NO_INT64)
Billy Donahue1c2ed7a2019-01-17 16:35:29 -0500173
174template <typename T>
175using Allocator = typename std::conditional<JSONCPP_USING_SECURE_MEMORY,
176 SecureAllocator<T>,
Billy Donahue2b593a92019-01-18 03:46:57 -0500177 std::allocator<T>>::type;
178using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>;
Billy Donahue1c2ed7a2019-01-17 16:35:29 -0500179using IStringStream = std::basic_istringstream<String::value_type,
180 String::traits_type,
181 String::allocator_type>;
182using OStringStream = std::basic_ostringstream<String::value_type,
183 String::traits_type,
184 String::allocator_type>;
185using IStream = std::istream;
186using OStream = std::ostream;
187} // namespace Json
188
189// Legacy names (formerly macros).
190using JSONCPP_STRING = Json::String;
191using JSONCPP_ISTRINGSTREAM = Json::IStringStream;
192using JSONCPP_OSTRINGSTREAM = Json::OStringStream;
193using JSONCPP_ISTREAM = Json::IStream;
194using JSONCPP_OSTREAM = Json::OStream;
Baptiste Lepilleur201fb2c2010-04-19 07:37:41 +0000195
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000196#endif // JSON_CONFIG_H_INCLUDED