blob: 2b4392c2ba4efa859d1c32c7b08d31f68643274e [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
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100033#if !defined(JSON_API)
34#define JSON_API
35#endif
Christopher Dunn6d135cb2007-06-13 15:51:04 +000036
Hans Johnson31d65712019-01-11 14:13:08 -060037#if defined(_MSC_VER) && _MSC_VER < 1800
Billy Donahuedc4a7f92019-01-17 11:07:53 -050038#error \
39 "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 -060040#endif
41
Hans Johnson5c8e5392018-12-12 13:31:55 -060042#if defined(_MSC_VER) && _MSC_VER < 1900
Billy Donahuedc4a7f92019-01-17 11:07:53 -050043// As recommended at
44// https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
Jordan Baylesf34bf242019-10-11 11:19:00 -070045extern JSON_API int msvc_pre1900_c99_snprintf(char* outBuf, size_t size,
46 const char* format, ...);
Billy Donahuedc4a7f92019-01-17 11:07:53 -050047#define jsoncpp_snprintf msvc_pre1900_c99_snprintf
Hans Johnson5c8e5392018-12-12 13:31:55 -060048#else
Billy Donahuedc4a7f92019-01-17 11:07:53 -050049#define jsoncpp_snprintf std::snprintf
Hans Johnson5c8e5392018-12-12 13:31:55 -060050#endif
51
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100052// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for
53// integer
Baptiste Lepilleur842e9ac2010-12-27 17:45:23 +000054// Storages, and 64 bits integer support is disabled.
Baptiste Lepilleur201fb2c2010-04-19 07:37:41 +000055// #define JSON_NO_INT64 1
56
Billy Donahuedc4a7f92019-01-17 11:07:53 -050057// JSONCPP_OVERRIDE is maintained for backwards compatibility of external tools.
58// C++11 should be used directly in JSONCPP.
59#define JSONCPP_OVERRIDE override
60
Christopher Dunne0f9aab2016-06-26 17:52:19 -050061#if __cplusplus >= 201103L
Billy Donahueb5e1fe82018-05-20 16:55:27 -040062#define JSONCPP_NOEXCEPT noexcept
63#define JSONCPP_OP_EXPLICIT explicit
Hans Johnson31d65712019-01-11 14:13:08 -060064#elif defined(_MSC_VER) && _MSC_VER < 1900
Billy Donahueb5e1fe82018-05-20 16:55:27 -040065#define JSONCPP_NOEXCEPT throw()
Billy Donahueb5e1fe82018-05-20 16:55:27 -040066#define JSONCPP_OP_EXPLICIT explicit
Billy Donahueb5e1fe82018-05-20 16:55:27 -040067#elif defined(_MSC_VER) && _MSC_VER >= 1900
Billy Donahueb5e1fe82018-05-20 16:55:27 -040068#define JSONCPP_NOEXCEPT noexcept
69#define JSONCPP_OP_EXPLICIT explicit
70#else
Billy Donahueb5e1fe82018-05-20 16:55:27 -040071#define JSONCPP_NOEXCEPT throw()
72#define JSONCPP_OP_EXPLICIT
Jean-Christophe Fillion-Robinba6fa482016-04-25 17:35:12 -040073#endif
Motti2b008912015-04-20 17:44:47 +030074
Jordan Baylesf34bf242019-10-11 11:19:00 -070075#ifdef __clang__
76#if __has_extension(attribute_deprecated_with_message)
77#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
78#endif
79#elif defined(__GNUC__) // not clang (gcc comes later since clang emulates gcc)
80#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
81#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
82#elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
83#define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
84#endif // GNUC version
85#elif defined(_MSC_VER) // MSVC (after clang because clang on Windows emulates
86 // MSVC)
87#define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
88#endif // __clang__ || __GNUC__ || _MSC_VER
89
90#if !defined(JSONCPP_DEPRECATED)
91#define JSONCPP_DEPRECATED(message)
92#endif // if !defined(JSONCPP_DEPRECATED)
93
94#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 6))
Billy Donahueb5e1fe82018-05-20 16:55:27 -040095#define JSON_USE_INT64_DOUBLE_CONVERSION 1
Christopher Dunn95f120f2016-02-07 11:09:41 -060096#endif
97
Christopher Dunn12c67e82016-03-21 20:33:15 -050098#if !defined(JSON_IS_AMALGAMATION)
dawescf8674c62016-03-06 11:42:11 -060099
Billy Donahue1c2ed7a2019-01-17 16:35:29 -0500100#include "allocator.h"
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400101#include "version.h"
Christopher Dunn12c67e82016-03-21 20:33:15 -0500102
Christopher Dunn12c67e82016-03-21 20:33:15 -0500103#endif // if !defined(JSON_IS_AMALGAMATION)
dawescf8674c62016-03-06 11:42:11 -0600104
Baptiste Lepilleur201fb2c2010-04-19 07:37:41 +0000105namespace Json {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000106typedef int Int;
107typedef unsigned int UInt;
108#if defined(JSON_NO_INT64)
109typedef int LargestInt;
110typedef unsigned int LargestUInt;
111#undef JSON_HAS_INT64
112#else // if defined(JSON_NO_INT64)
113// For Microsoft Visual use specific types as long long is not supported
114#if defined(_MSC_VER) // Microsoft Visual Studio
115typedef __int64 Int64;
116typedef unsigned __int64 UInt64;
117#else // if defined(_MSC_VER) // Other platforms, use long long
Christopher Dunnb9afdf12016-08-21 19:58:43 -0500118typedef int64_t Int64;
119typedef uint64_t UInt64;
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400120#endif // if defined(_MSC_VER)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000121typedef Int64 LargestInt;
122typedef UInt64 LargestUInt;
123#define JSON_HAS_INT64
124#endif // if defined(JSON_NO_INT64)
Billy Donahue1c2ed7a2019-01-17 16:35:29 -0500125
126template <typename T>
Jordan Baylesf34bf242019-10-11 11:19:00 -0700127using Allocator =
128 typename std::conditional<JSONCPP_USING_SECURE_MEMORY, SecureAllocator<T>,
129 std::allocator<T>>::type;
Billy Donahue2b593a92019-01-18 03:46:57 -0500130using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>;
Jordan Baylesf34bf242019-10-11 11:19:00 -0700131using IStringStream =
132 std::basic_istringstream<String::value_type, String::traits_type,
133 String::allocator_type>;
134using OStringStream =
135 std::basic_ostringstream<String::value_type, String::traits_type,
136 String::allocator_type>;
Billy Donahue1c2ed7a2019-01-17 16:35:29 -0500137using IStream = std::istream;
138using OStream = std::ostream;
139} // namespace Json
140
141// Legacy names (formerly macros).
142using JSONCPP_STRING = Json::String;
143using JSONCPP_ISTRINGSTREAM = Json::IStringStream;
144using JSONCPP_OSTRINGSTREAM = Json::OStringStream;
145using JSONCPP_ISTREAM = Json::IStream;
146using JSONCPP_OSTREAM = Json::OStream;
Baptiste Lepilleur201fb2c2010-04-19 07:37:41 +0000147
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000148#endif // JSON_CONFIG_H_INCLUDED