JsonCpp project page Classes Namespace JsonCpp home page

config.h
Go to the documentation of this file.
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 #include <cstddef>
9 #include <cstdint>
10 #include <istream>
11 #include <memory>
12 #include <ostream>
13 #include <sstream>
14 #include <string>
15 #include <type_traits>
16 
17 // If non-zero, the library uses exceptions to report bad input instead of C
18 // assertion macros. The default is to use exceptions.
19 #ifndef JSON_USE_EXCEPTION
20 #define JSON_USE_EXCEPTION 1
21 #endif
22 
23 // Temporary, tracked for removal with issue #982.
24 #ifndef JSON_USE_NULLREF
25 #define JSON_USE_NULLREF 1
26 #endif
27 
31 // #define JSON_IS_AMALGAMATION
32 
33 // 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(__OS2__)
39 #define JSON_API __declspec(dllexport)
40 #elif defined(__GNUC__) || defined(__clang__)
41 #define JSON_API __attribute__((visibility("default")))
42 #endif // if defined(_MSC_VER)
43 
44 #elif defined(JSON_DLL)
45 #if defined(_MSC_VER) || defined(__MINGW32__)
46 #define JSON_API __declspec(dllimport)
47 #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
48 #endif // if defined(_MSC_VER)
49 #endif // ifdef JSON_DLL_BUILD
50 
51 #if !defined(JSON_API)
52 #define JSON_API
53 #endif
54 
55 #if defined(_MSC_VER) && _MSC_VER < 1800
56 #error \
57  "ERROR: Visual Studio 12 (2013) with _MSC_VER=1800 is the oldest supported compiler with sufficient C++11 capabilities"
58 #endif
59 
60 #if defined(_MSC_VER) && _MSC_VER < 1900
61 // As recommended at
62 // https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
63 extern JSON_API int msvc_pre1900_c99_snprintf(char* outBuf, size_t size,
64  const char* format, ...);
65 #define jsoncpp_snprintf msvc_pre1900_c99_snprintf
66 #else
67 #define jsoncpp_snprintf std::snprintf
68 #endif
69 
70 // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for
71 // integer
72 // Storages, and 64 bits integer support is disabled.
73 // #define JSON_NO_INT64 1
74 
75 // JSONCPP_OVERRIDE is maintained for backwards compatibility of external tools.
76 // C++11 should be used directly in JSONCPP.
77 #define JSONCPP_OVERRIDE override
78 
79 #ifdef __clang__
80 #if __has_extension(attribute_deprecated_with_message)
81 #define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
82 #endif
83 #elif defined(__GNUC__) // not clang (gcc comes later since clang emulates gcc)
84 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
85 #define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
86 #elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
87 #define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
88 #endif // GNUC version
89 #elif defined(_MSC_VER) // MSVC (after clang because clang on Windows emulates
90  // MSVC)
91 #define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
92 #endif // __clang__ || __GNUC__ || _MSC_VER
93 
94 #if !defined(JSONCPP_DEPRECATED)
95 #define JSONCPP_DEPRECATED(message)
96 #endif // if !defined(JSONCPP_DEPRECATED)
97 
98 #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 
109 namespace Json {
110 using Int = int;
111 using UInt = unsigned int;
112 #if defined(JSON_NO_INT64)
113 using LargestInt = int;
114 using LargestUInt = unsigned int;
115 #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
119 using Int64 = __int64;
120 using UInt64 = unsigned __int64;
121 #else // if defined(_MSC_VER) // Other platforms, use long long
122 using Int64 = int64_t;
123 using UInt64 = uint64_t;
124 #endif // if defined(_MSC_VER)
127 #define JSON_HAS_INT64
128 #endif // if defined(JSON_NO_INT64)
129 
130 template <typename T>
131 using Allocator =
132  typename std::conditional<JSONCPP_USING_SECURE_MEMORY, SecureAllocator<T>,
133  std::allocator<T>>::type;
134 using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>;
135 using IStringStream =
136  std::basic_istringstream<String::value_type, String::traits_type,
137  String::allocator_type>;
138 using OStringStream =
139  std::basic_ostringstream<String::value_type, String::traits_type,
140  String::allocator_type>;
141 using IStream = std::istream;
142 using OStream = std::ostream;
143 } // namespace Json
144 
145 // Legacy names (formerly macros).
151 
152 #endif // JSON_CONFIG_H_INCLUDED
Json::OStringStream
std::basic_ostringstream< String::value_type, String::traits_type, String::allocator_type > OStringStream
Definition: config.h:140
Json::Int
int Int
Definition: config.h:110
JSONCPP_ISTRINGSTREAM
Json::IStringStream JSONCPP_ISTRINGSTREAM
Definition: config.h:147
Json::Allocator
typename std::conditional< 0, SecureAllocator< T >, std::allocator< T > >::type Allocator
Definition: config.h:133
Json::IStream
std::istream IStream
Definition: config.h:141
msvc_pre1900_c99_snprintf
int msvc_pre1900_c99_snprintf(char *outBuf, size_t size, const char *format,...)
Definition: json_value.cpp:33
JSONCPP_OSTREAM
Json::OStream JSONCPP_OSTREAM
Definition: config.h:150
Json::UInt64
unsigned __int64 UInt64
Definition: config.h:120
version.h
Json::UInt
unsigned int UInt
Definition: config.h:111
Json::IStringStream
std::basic_istringstream< String::value_type, String::traits_type, String::allocator_type > IStringStream
Definition: config.h:137
JSONCPP_ISTREAM
Json::IStream JSONCPP_ISTREAM
Definition: config.h:149
Json::OStream
std::ostream OStream
Definition: config.h:142
Json
JSON (JavaScript Object Notation).
Definition: allocator.h:14
Json::LargestUInt
UInt64 LargestUInt
Definition: config.h:126
JSON_API
#define JSON_API
If defined, indicates that the source file is amalgamated to prevent private header inclusion.
Definition: config.h:52
allocator.h
Json::Int64
__int64 Int64
Definition: config.h:119
JSONCPP_OSTRINGSTREAM
Json::OStringStream JSONCPP_OSTRINGSTREAM
Definition: config.h:148
Json::String
std::basic_string< char, std::char_traits< char >, Allocator< char > > String
Definition: config.h:134
JSONCPP_STRING
Json::String JSONCPP_STRING
Definition: config.h:146
Json::LargestInt
Int64 LargestInt
Definition: config.h:125