config.h 5.3 KB

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