• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <istream>
10 #include <memory>
11 #include <ostream>
12 #include <sstream>
13 #include <string>
14 
15 #if JSONCPP_CXX_STD_11
16 #include <cstddef> // typedef ptrdiff_t
17 #include <cstdint> // typedef int64_t, uint64_t
18 #else
19 #include <stddef.h>
20 #include <stdint.h>
21 #endif
22 
23 // If non-zero, the library uses exceptions to report bad input instead of C
24 // assertion macros. The default is to use exceptions.
25 #ifndef JSON_USE_EXCEPTION
26 #define JSON_USE_EXCEPTION 1
27 #endif
28 
29 // Temporary, tracked for removal with issue #982.
30 #ifndef JSON_USE_NULLREF
31 #define JSON_USE_NULLREF 1
32 #endif
33 
34 /// If defined, indicates that the source file is amalgamated
35 /// to prevent private header inclusion.
36 /// Remarks: it is automatically defined in the generated amalgamated header.
37 // #define JSON_IS_AMALGAMATION
38 
39 // Export macros for DLL visibility
40 #if defined(JSON_DLL_BUILD)
41 #if defined(_MSC_VER) || defined(__MINGW32__)
42 #define JSON_API __declspec(dllexport)
43 #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
44 #elif defined(__GNUC__) || defined(__clang__)
45 #define JSON_API __attribute__((visibility("default")))
46 #endif // if defined(_MSC_VER)
47 
48 #elif defined(JSON_DLL)
49 #if defined(_MSC_VER) || defined(__MINGW32__)
50 #define JSON_API __declspec(dllimport)
51 #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
52 #endif // if defined(_MSC_VER)
53 #endif // ifdef JSON_DLL_BUILD
54 
55 #if !defined(JSON_API)
56 #define JSON_API
57 #endif
58 
59 #if defined(_MSC_VER) && _MSC_VER < 1900
60 // As recommended at
61 // https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
62 extern JSON_API int msvc_pre1900_c99_snprintf(char* outBuf, size_t size,
63                                               const char* format, ...);
64 #define jsoncpp_snprintf msvc_pre1900_c99_snprintf
65 #else
66 #define jsoncpp_snprintf std::snprintf
67 #endif
68 
69 // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for
70 // integer
71 // Storages, and 64 bits integer support is disabled.
72 // #define JSON_NO_INT64 1
73 
74 #if __cplusplus >= 201103L || defined(_MSC_VER)
75 #define JSONCPP_OP_EXPLICIT explicit
76 #else
77 #define JSONCPP_OP_EXPLICIT
78 #endif
79 
80 // These Macros are maintained for backwards compatibility of external tools.
81 #if (defined(_MSC_VER) && _MSC_VER >= 1900) ||                                 \
82     (defined(__GNUC__) && __cplusplus >= 201103L) ||                           \
83     (defined(__clang__) && __clang_major__ == 3 && __clang_minor__ >= 3)
84 
85 #define JSONCPP_CXX_STD_11 1
86 #else
87 #define JSONCPP_CXX_STD_11 0
88 #endif
89 
90 #if JSONCPP_CXX_STD_11
91 #define JSONCPP_NULL nullptr
92 #define JSONCPP_CONST constexpr
93 #define JSONCPP_CTOR_DELETE = delete
94 #define JSONCPP_NOEXCEPT noexcept
95 #define JSONCPP_OVERRIDE override
96 #define JSONCPP_MOVE(value) std::move(value)
97 #else
98 #define JSONCPP_NULL NULL
99 #define JSONCPP_CONST const
100 #define JSONCPP_CTOR_DELETE
101 #define JSONCPP_NOEXCEPT throw()
102 #define JSONCPP_OVERRIDE
103 #define JSONCPP_MOVE(value) value
104 #endif
105 
106 // Define *deprecated* attribute
107 // [[deprecated]] is in C++14 or in Visual Studio 2015 and later
108 // For compatibility, [[deprecated]] is not used
109 #ifdef __clang__
110 #if __has_extension(attribute_deprecated_with_message)
111 #define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
112 #endif
113 #elif defined(__GNUC__) // not clang (gcc comes later since clang emulates gcc)
114 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
115 #define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
116 #elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
117 #define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
118 #endif                  // GNUC version
119 #elif defined(_MSC_VER) // MSVC (after clang because clang on Windows emulates
120                         // MSVC)
121 #define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
122 #endif // __clang__ || __GNUC__ || _MSC_VER
123 
124 #if !defined(JSONCPP_DEPRECATED)
125 #define JSONCPP_DEPRECATED(message)
126 #endif // if !defined(JSONCPP_DEPRECATED)
127 
128 #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 6))
129 #define JSON_USE_INT64_DOUBLE_CONVERSION 1
130 #endif
131 
132 #if !defined(JSON_IS_AMALGAMATION)
133 #if JSONCPP_CXX_STD_11
134 #include "allocator.h"
135 #endif
136 #include "version.h"
137 
138 #endif // if !defined(JSON_IS_AMALGAMATION)
139 
140 namespace Json {
141 
142 typedef int Int;
143 typedef unsigned int UInt;
144 #if defined(JSON_NO_INT64)
145 typedef int LargestInt;
146 typedef unsigned int LargestUInt;
147 #undef JSON_HAS_INT64
148 #else                 // if defined(JSON_NO_INT64)
149 // For Microsoft Visual use specific types as long long is not supported
150 #if defined(_MSC_VER) // Microsoft Visual Studio
151 typedef __int64 Int64;
152 typedef unsigned __int64 UInt64;
153 #else                 // if defined(_MSC_VER) // Other platforms, use long long
154 typedef int64_t Int64;
155 typedef uint64_t UInt64;
156 #endif                // if defined(_MSC_VER)
157 typedef Int64 LargestInt;
158 typedef UInt64 LargestUInt;
159 #define JSON_HAS_INT64
160 #endif // if defined(JSON_NO_INT64)
161 
162 #if JSONCPP_CXX_STD_11
163 template <typename T>
164 using Allocator =
165     typename std::conditional<JSONCPP_USING_SECURE_MEMORY, SecureAllocator<T>,
166                               std::allocator<T>>::type;
167 using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>;
168 using IStringStream =
169     std::basic_istringstream<String::value_type, String::traits_type,
170                              String::allocator_type>;
171 using OStringStream =
172     std::basic_ostringstream<String::value_type, String::traits_type,
173                              String::allocator_type>;
174 using IStream = std::istream;
175 using OStream = std::ostream;
176 #else
177 typedef std::string String;
178 typedef std::istringstream IStringStream;
179 typedef std::ostringstream OStringStream;
180 typedef std::istream IStream;
181 typedef std::ostream OStream;
182 #endif // JSONCPP_CXX_STD_11
183 } // namespace Json
184 
185 // Legacy names (formerly macros).
186 typedef Json::String JSONCPP_STRING;
187 typedef Json::IStringStream JSONCPP_ISTRINGSTREAM;
188 typedef Json::OStringStream JSONCPP_OSTRINGSTREAM;
189 typedef Json::IStream JSONCPP_ISTREAM;
190 typedef Json::OStream JSONCPP_OSTREAM;
191 
192 #endif // JSON_CONFIG_H_INCLUDED
193