config.h 5.5 KB

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