From 1d055261b4144dbf86b2658437015b15d4dd9bff Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 4 Sep 2022 00:32:56 +0100 Subject: initial --- include/jsoncons/config/jsoncons_config.hpp | 308 ++++++++++++++++++++++++++++ 1 file changed, 308 insertions(+) create mode 100644 include/jsoncons/config/jsoncons_config.hpp (limited to 'include/jsoncons/config/jsoncons_config.hpp') diff --git a/include/jsoncons/config/jsoncons_config.hpp b/include/jsoncons/config/jsoncons_config.hpp new file mode 100644 index 0000000..63c437b --- /dev/null +++ b/include/jsoncons/config/jsoncons_config.hpp @@ -0,0 +1,308 @@ +// Copyright 2019 Daniel Parker +// Distributed under the Boost license, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See https://github.com/danielaparker/jsoncons for latest version + +#ifndef JSONCONS_CONFIG_JSONCONS_CONFIG_HPP +#define JSONCONS_CONFIG_JSONCONS_CONFIG_HPP + +#include +#include +#include +#include + +#if !defined(JSONCONS_HAS_STD_STRING_VIEW) +#include +namespace jsoncons { +using jsoncons::detail::basic_string_view; +using string_view = basic_string_view>; +using wstring_view = basic_string_view>; +} +#else +#include +namespace jsoncons { +using std::basic_string_view; +using std::string_view; +using std::wstring_view; +} +#endif + +#if !defined(JSONCONS_HAS_STD_SPAN) +#include +namespace jsoncons { +using jsoncons::detail::span; +} +#else +#include +namespace jsoncons { +using std::span; +} +#endif + +#if defined(JSONCONS_HAS_STD_OPTIONAL) + #include + namespace jsoncons { + using std::optional; + } +#elif defined(JSONCONS_HAS_BOOST_OPTIONAL) + #include + namespace jsoncons { + using boost::optional; + } +#else + #include + namespace jsoncons { + using jsoncons::detail::optional; +} +#endif // !defined(JSONCONS_HAS_STD_OPTIONAL) + +#if !defined(JSONCONS_HAS_STD_ENDIAN) +#include +namespace jsoncons { +using jsoncons::detail::endian; +} +#else +#include +namespace jsoncons +{ + using std::endian; +} +#endif + +#if !defined(JSONCONS_HAS_STD_MAKE_UNIQUE) + +#include +#include +#include +#include + +namespace jsoncons { + + template + struct unique_if + { + using value_is_not_array = std::unique_ptr; + }; + + template + struct unique_if + { + typedef std::unique_ptr value_is_array_of_unknown_bound; + }; + + template + struct unique_if { + using value_is_array_of_known_bound = void; + }; + + template + typename unique_if::value_is_not_array + make_unique(Args&&... args) + { + return std::unique_ptr(new T(std::forward(args)...)); + } + + template + typename unique_if::value_is_array_of_unknown_bound + make_unique(std::size_t n) + { + using U = typename std::remove_extent::type; + return std::unique_ptr(new U[n]()); + } + + template + typename unique_if::value_is_array_of_known_bound + make_unique(Args&&...) = delete; +} // jsoncons + +#else + +#include +namespace jsoncons +{ + using std::make_unique; +} + +#endif // !defined(JSONCONS_HAS_STD_MAKE_UNIQUE) + +namespace jsoncons { +namespace binary { + + // native_to_big + + template + typename std::enable_if::type + native_to_big(T val, OutputIt d_first) + { + uint8_t buf[sizeof(T)]; + std::memcpy(buf, &val, sizeof(T)); + for (auto item : buf) + { + *d_first++ = item; + } + } + + template + typename std::enable_if::type + native_to_big(T val, OutputIt d_first) + { + T val2 = byte_swap(val); + uint8_t buf[sizeof(T)]; + std::memcpy(buf, &val2, sizeof(T)); + for (auto item : buf) + { + *d_first++ = item; + } + } + + // native_to_little + + template + typename std::enable_if::type + native_to_little(T val, OutputIt d_first) + { + uint8_t buf[sizeof(T)]; + std::memcpy(buf, &val, sizeof(T)); + for (auto item : buf) + { + *d_first++ = item; + } + } + + template + typename std::enable_if::type + native_to_little(T val, OutputIt d_first) + { + T val2 = byte_swap(val); + uint8_t buf[sizeof(T)]; + std::memcpy(buf, &val2, sizeof(T)); + for (auto item : buf) + { + *d_first++ = item; + } + } + + // big_to_native + + template + typename std::enable_if::type + big_to_native(const uint8_t* first, std::size_t count) + { + if (sizeof(T) > count) + { + return T{}; + } + T val; + std::memcpy(&val,first,sizeof(T)); + return val; + } + + template + typename std::enable_if::type + big_to_native(const uint8_t* first, std::size_t count) + { + if (sizeof(T) > count) + { + return T{}; + } + T val; + std::memcpy(&val,first,sizeof(T)); + return byte_swap(val); + } + + // little_to_native + + template + typename std::enable_if::type + little_to_native(const uint8_t* first, std::size_t count) + { + if (sizeof(T) > count) + { + return T{}; + } + T val; + std::memcpy(&val,first,sizeof(T)); + return val; + } + + template + typename std::enable_if::type + little_to_native(const uint8_t* first, std::size_t count) + { + if (sizeof(T) > count) + { + return T{}; + } + T val; + std::memcpy(&val,first,sizeof(T)); + return byte_swap(val); + } + +} // binary +} // jsoncons + +namespace jsoncons { + + template + constexpr const CharT* cstring_constant_of_type(const char* c, const wchar_t* w); + + template<> inline + constexpr const char* cstring_constant_of_type(const char* c, const wchar_t*) + { + return c; + } + template<> inline + constexpr const wchar_t* cstring_constant_of_type(const char*, const wchar_t* w) + { + return w; + } + + template + std::basic_string string_constant_of_type(const char* c, const wchar_t* w); + + template<> inline + std::string string_constant_of_type(const char* c, const wchar_t*) + { + return std::string(c); + } + template<> inline + std::wstring string_constant_of_type(const char*, const wchar_t* w) + { + return std::wstring(w); + } + + template + jsoncons::basic_string_view string_view_constant_of_type(const char* c, const wchar_t* w); + + template<> inline + jsoncons::string_view string_view_constant_of_type(const char* c, const wchar_t*) + { + return jsoncons::string_view(c); + } + template<> inline + jsoncons::wstring_view string_view_constant_of_type(const char*, const wchar_t* w) + { + return jsoncons::wstring_view(w); + } + +} // jsoncons + +#define JSONCONS_EXPAND(X) X +#define JSONCONS_QUOTE(Prefix, A) JSONCONS_EXPAND(Prefix ## #A) + +#define JSONCONS_CSTRING_CONSTANT(CharT, Str) cstring_constant_of_type(Str, JSONCONS_QUOTE(L, Str)) +#define JSONCONS_STRING_CONSTANT(CharT, Str) string_constant_of_type(Str, JSONCONS_QUOTE(L, Str)) +#define JSONCONS_STRING_VIEW_CONSTANT(CharT, Str) string_view_constant_of_type(Str, JSONCONS_QUOTE(L, Str)) + +#if defined(__clang__) +#define JSONCONS_HAS_STD_REGEX 1 +#elif (defined(__GNUC__) && (__GNUC__ == 4)) && (defined(__GNUC__) && __GNUC_MINOR__ < 9) +// GCC 4.8 has broken regex support: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631 +#else +#define JSONCONS_HAS_STD_REGEX 1 +#endif + +#endif // JSONCONS_CONFIG_JSONCONS_CONFIG_HPP + + -- cgit v1.2.3