config.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #ifdef __clang__
  66. #if __has_extension(attribute_deprecated_with_message)
  67. #define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
  68. #endif
  69. #elif defined(__GNUC__) // not clang (gcc comes later since clang emulates gcc)
  70. #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
  71. #define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
  72. #elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
  73. #define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
  74. #endif // GNUC version
  75. #elif defined(_MSC_VER) // MSVC (after clang because clang on Windows emulates
  76. // MSVC)
  77. #define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
  78. #endif // __clang__ || __GNUC__ || _MSC_VER
  79. #if !defined(JSONCPP_DEPRECATED)
  80. #define JSONCPP_DEPRECATED(message)
  81. #endif // if !defined(JSONCPP_DEPRECATED)
  82. #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 6))
  83. #define JSON_USE_INT64_DOUBLE_CONVERSION 1
  84. #endif
  85. #if !defined(JSON_IS_AMALGAMATION)
  86. #include "allocator.h"
  87. #include "version.h"
  88. #endif // if !defined(JSON_IS_AMALGAMATION)
  89. namespace Json {
  90. using Int = int;
  91. using UInt = unsigned int;
  92. #if defined(JSON_NO_INT64)
  93. using LargestInt = int;
  94. using LargestUInt = unsigned int;
  95. #undef JSON_HAS_INT64
  96. #else // if defined(JSON_NO_INT64)
  97. // For Microsoft Visual use specific types as long long is not supported
  98. #if defined(_MSC_VER) // Microsoft Visual Studio
  99. using Int64 = __int64;
  100. using UInt64 = unsigned __int64;
  101. #else // if defined(_MSC_VER) // Other platforms, use long long
  102. using Int64 = int64_t;
  103. using UInt64 = uint64_t;
  104. #endif // if defined(_MSC_VER)
  105. using LargestInt = Int64;
  106. using LargestUInt = UInt64;
  107. #define JSON_HAS_INT64
  108. #endif // if defined(JSON_NO_INT64)
  109. template <typename T>
  110. using Allocator =
  111. typename std::conditional<JSONCPP_USING_SECURE_MEMORY, SecureAllocator<T>,
  112. std::allocator<T>>::type;
  113. using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>;
  114. using IStringStream =
  115. std::basic_istringstream<String::value_type, String::traits_type,
  116. String::allocator_type>;
  117. using OStringStream =
  118. std::basic_ostringstream<String::value_type, String::traits_type,
  119. String::allocator_type>;
  120. using IStream = std::istream;
  121. using OStream = std::ostream;
  122. } // namespace Json
  123. // Legacy names (formerly macros).
  124. using JSONCPP_STRING = Json::String;
  125. using JSONCPP_ISTRINGSTREAM = Json::IStringStream;
  126. using JSONCPP_OSTRINGSTREAM = Json::OStringStream;
  127. using JSONCPP_ISTREAM = Json::IStream;
  128. using JSONCPP_OSTREAM = Json::OStream;
  129. #endif // JSON_CONFIG_H_INCLUDED