From b8d3401089fed5cbed39cf3c4649bd70f134f5cf Mon Sep 17 00:00:00 2001 From: tang zhixiong Date: Sun, 15 Feb 2026 12:23:23 +0800 Subject: [PATCH 1/4] cleanup jsoncons --- include/jsoncons/decode_traits.hpp | 668 -------------- include/jsoncons/detail/parse_number.hpp | 1052 --------------------- include/jsoncons/detail/write_number.hpp | 572 ------------ include/jsoncons/encode_traits.hpp | 385 -------- include/jsoncons/json_traits_macros.hpp | 1068 ---------------------- include/jsoncons/ser_context.hpp | 47 - include/jsoncons/value_converter.hpp | 345 ------- 7 files changed, 4137 deletions(-) delete mode 100644 include/jsoncons/decode_traits.hpp delete mode 100644 include/jsoncons/detail/parse_number.hpp delete mode 100644 include/jsoncons/detail/write_number.hpp delete mode 100644 include/jsoncons/encode_traits.hpp delete mode 100644 include/jsoncons/json_traits_macros.hpp delete mode 100644 include/jsoncons/ser_context.hpp delete mode 100644 include/jsoncons/value_converter.hpp diff --git a/include/jsoncons/decode_traits.hpp b/include/jsoncons/decode_traits.hpp deleted file mode 100644 index 9c2e28a..0000000 --- a/include/jsoncons/decode_traits.hpp +++ /dev/null @@ -1,668 +0,0 @@ -// Copyright 2013-2025 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_DECODE_TRAITS_HPP -#define JSONCONS_DECODE_TRAITS_HPP - -#include -#include -#include -#include -#include -#include -#include // std::enable_if, std::true_type, std::false_type -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace jsoncons { - - // decode_traits - - template - struct decode_traits - { - template - static T decode(basic_staj_cursor& cursor, - json_decoder& decoder, - std::error_code& ec) - { - decoder.reset(); - cursor.read_to(decoder, ec); - if (JSONCONS_UNLIKELY(ec)) - { - JSONCONS_THROW(ser_error(ec, cursor.context().line(), cursor.context().column())); - } - else if (!decoder.is_valid()) - { - JSONCONS_THROW(ser_error(conv_errc::conversion_failed, cursor.context().line(), cursor.context().column())); - } - return decoder.get_result().template as(); - } - }; - - // specializations - - // primitive - - template - struct decode_traits::value - >::type> - { - template - static T decode(basic_staj_cursor& cursor, - json_decoder&, - std::error_code& ec) - { - T v = cursor.current().template get(ec); - return v; - } - }; - - // string - - template - struct decode_traits::value && - std::is_same::value - >::type> - { - template - static T decode(basic_staj_cursor& cursor, - json_decoder&, - std::error_code& ec) - { - T v = cursor.current().template get(ec); - return v; - } - }; - - template - struct decode_traits::value && - !std::is_same::value - >::type> - { - template - static T decode(basic_staj_cursor& cursor, - json_decoder&, - std::error_code& ec) - { - auto val = cursor.current().template get>(ec); - T s; - if (!ec) - { - unicode_traits::convert(val.data(), val.size(), s); - } - return s; - } - }; - - // std::pair - - template - struct decode_traits, CharT> - { - template - static std::pair decode(basic_staj_cursor& cursor, - json_decoder& decoder, - std::error_code& ec) - { - using value_type = std::pair; - cursor.array_expected(ec); - if (JSONCONS_UNLIKELY(ec)) - { - return value_type{}; - } - if (cursor.current().event_type() != staj_event_type::begin_array) - { - ec = conv_errc::not_pair; - return value_type(); - } - cursor.next(ec); // skip past array - if (JSONCONS_UNLIKELY(ec)) - { - return value_type(); - } - - T1 v1 = decode_traits::decode(cursor, decoder, ec); - if (JSONCONS_UNLIKELY(ec)) {return value_type();} - cursor.next(ec); - if (JSONCONS_UNLIKELY(ec)) {return value_type();} - T2 v2 = decode_traits::decode(cursor, decoder, ec); - if (JSONCONS_UNLIKELY(ec)) {return value_type();} - cursor.next(ec); - - if (cursor.current().event_type() != staj_event_type::end_array) - { - ec = conv_errc::not_pair; - return value_type(); - } - return std::make_pair(v1, v2); - } - }; - - // vector like - template - struct decode_traits::value && - ext_traits::is_array_like::value && - ext_traits::is_back_insertable::value && - !ext_traits::is_typed_array::value - >::type> - { - using value_type = typename T::value_type; - - template - static T decode(basic_staj_cursor& cursor, - json_decoder& decoder, - std::error_code& ec) - { - T v; - - cursor.array_expected(ec); - if (JSONCONS_UNLIKELY(ec)) - { - return T{}; - } - if (cursor.current().event_type() != staj_event_type::begin_array) - { - ec = conv_errc::not_vector; - return v; - } - cursor.next(ec); - while (cursor.current().event_type() != staj_event_type::end_array && !ec) - { - v.push_back(decode_traits::decode(cursor, decoder, ec)); - if (JSONCONS_UNLIKELY(ec)) {return T{};} - //std::cout << "read next 10\n"; - cursor.next(ec); - } - return v; - } - }; - - template - struct typed_array_visitor : public default_json_visitor - { - T& v_; - int level_{0}; - public: - using value_type = typename T::value_type; - - typed_array_visitor(T& v) - : default_json_visitor(), v_(v) - { - } - private: - JSONCONS_VISITOR_RETURN_TYPE visit_begin_array(semantic_tag, - const ser_context&, - std::error_code& ec) override - { - if (++level_ != 1) - { - ec = conv_errc::not_vector; - JSONCONS_VISITOR_RETURN; - } - JSONCONS_VISITOR_RETURN; - } - - JSONCONS_VISITOR_RETURN_TYPE visit_begin_array(std::size_t size, - semantic_tag, - const ser_context&, - std::error_code& ec) override - { - if (++level_ != 1) - { - ec = conv_errc::not_vector; - JSONCONS_VISITOR_RETURN; - } - if (size > 0) - { - reserve_storage(typename std::integral_constant::value>::type(), v_, size); - } - JSONCONS_VISITOR_RETURN; - } - - JSONCONS_VISITOR_RETURN_TYPE visit_end_array(const ser_context&, - std::error_code& ec) override - { - if (level_ != 1) - { - ec = conv_errc::not_vector; - JSONCONS_VISITOR_RETURN; - } - JSONCONS_VISITOR_RETURN; - } - - JSONCONS_VISITOR_RETURN_TYPE visit_uint64(uint64_t value, - semantic_tag, - const ser_context&, - std::error_code&) override - { - v_.push_back(static_cast(value)); - JSONCONS_VISITOR_RETURN; - } - - JSONCONS_VISITOR_RETURN_TYPE visit_int64(int64_t value, - semantic_tag, - const ser_context&, - std::error_code&) override - { - v_.push_back(static_cast(value)); - JSONCONS_VISITOR_RETURN; - } - - JSONCONS_VISITOR_RETURN_TYPE visit_half(uint16_t value, - semantic_tag, - const ser_context&, - std::error_code&) override - { - visit_half_(typename std::integral_constant::value>::type(), value); - JSONCONS_VISITOR_RETURN; - } - - void visit_half_(std::true_type, uint16_t value) - { - v_.push_back(static_cast(value)); - } - - void visit_half_(std::false_type, uint16_t value) - { - v_.push_back(static_cast(binary::decode_half(value))); - } - - JSONCONS_VISITOR_RETURN_TYPE visit_double(double value, - semantic_tag, - const ser_context&, - std::error_code&) override - { - v_.push_back(static_cast(value)); - JSONCONS_VISITOR_RETURN; - } - - JSONCONS_VISITOR_RETURN_TYPE visit_typed_array(const jsoncons::span& data, - semantic_tag, - const ser_context&, - std::error_code&) override - { - v_ = std::vector(data.begin(),data.end()); - JSONCONS_VISITOR_RETURN; - } - - static - void reserve_storage(std::true_type, T& v, std::size_t new_cap) - { - v.reserve(new_cap); - } - - static - void reserve_storage(std::false_type, T&, std::size_t) - { - } - }; - - template - struct decode_traits::value && - ext_traits::is_array_like::value && - ext_traits::is_back_insertable_byte_container::value && - ext_traits::is_typed_array::value - >::type> - { - using value_type = typename T::value_type; - - template - static T decode(basic_staj_cursor& cursor, - json_decoder&, - std::error_code& ec) - { - cursor.array_expected(ec); - if (JSONCONS_UNLIKELY(ec)) - { - return T{}; - } - switch (cursor.current().event_type()) - { - case staj_event_type::byte_string_value: - { - auto bytes = cursor.current().template get(ec); - if (!ec) - { - T v; - if (cursor.current().size() > 0) - { - reserve_storage(typename std::integral_constant::value>::type(), v, cursor.current().size()); - } - for (auto ch : bytes) - { - v.push_back(static_cast(ch)); - } - cursor.next(ec); - return v; - } - else - { - return T{}; - } - } - case staj_event_type::begin_array: - { - T v; - if (cursor.current().size() > 0) - { - reserve_storage(typename std::integral_constant::value>::type(), v, cursor.current().size()); - } - typed_array_visitor visitor(v); - cursor.read_to(visitor, ec); - return v; - } - default: - { - ec = conv_errc::not_vector; - return T{}; - } - } - } - - static void reserve_storage(std::true_type, T& v, std::size_t new_cap) - { - v.reserve(new_cap); - } - - static void reserve_storage(std::false_type, T&, std::size_t) - { - } - }; - - template - struct decode_traits::value && - ext_traits::is_array_like::value && - ext_traits::is_back_insertable::value && - !ext_traits::is_back_insertable_byte_container::value && - ext_traits::is_typed_array::value - >::type> - { - using value_type = typename T::value_type; - - template - static T decode(basic_staj_cursor& cursor, - json_decoder&, - std::error_code& ec) - { - cursor.array_expected(ec); - if (JSONCONS_UNLIKELY(ec)) - { - return T{}; - } - switch (cursor.current().event_type()) - { - case staj_event_type::begin_array: - { - T v; - if (cursor.current().size() > 0) - { - reserve_storage(typename std::integral_constant::value>::type(), v, cursor.current().size()); - } - typed_array_visitor visitor(v); - cursor.read_to(visitor, ec); - return v; - } - default: - { - ec = conv_errc::not_vector; - return T{}; - } - } - } - - static void reserve_storage(std::true_type, T& v, std::size_t new_cap) - { - v.reserve(new_cap); - } - - static void reserve_storage(std::false_type, T&, std::size_t) - { - } - }; - - // set like - template - struct decode_traits::value && - ext_traits::is_array_like::value && - !ext_traits::is_back_insertable::value && - ext_traits::is_insertable::value - >::type> - { - using value_type = typename T::value_type; - - template - static T decode(basic_staj_cursor& cursor, - json_decoder& decoder, - std::error_code& ec) - { - T v; - - cursor.array_expected(ec); - if (JSONCONS_UNLIKELY(ec)) - { - return T{}; - } - if (cursor.current().event_type() != staj_event_type::begin_array) - { - ec = conv_errc::not_vector; - return v; - } - if (cursor.current().size() > 0) - { - reserve_storage(typename std::integral_constant::value>::type(), v, cursor.current().size()); - } - cursor.next(ec); - while (cursor.current().event_type() != staj_event_type::end_array && !ec) - { - v.insert(decode_traits::decode(cursor, decoder, ec)); - if (JSONCONS_UNLIKELY(ec)) {return T{};} - //std::cout << "cursor.next 20\n"; - cursor.next(ec); - if (JSONCONS_UNLIKELY(ec)) {return T{};} - } - return v; - } - - static void reserve_storage(std::true_type, T& v, std::size_t new_cap) - { - v.reserve(new_cap); - } - - static void reserve_storage(std::false_type, T&, std::size_t) - { - } - }; - - // std::array - - template - struct decode_traits,CharT> - { - using value_type = typename std::array::value_type; - - template - static std::array decode(basic_staj_cursor& cursor, - json_decoder& decoder, - std::error_code& ec) - { - std::array v; - cursor.array_expected(ec); - if (JSONCONS_UNLIKELY(ec)) - { - v.fill(T()); - return v; - } - v.fill(T{}); - if (cursor.current().event_type() != staj_event_type::begin_array) - { - ec = conv_errc::not_vector; - return v; - } - cursor.next(ec); - for (std::size_t i = 0; i < N && cursor.current().event_type() != staj_event_type::end_array && !ec; ++i) - { - v[i] = decode_traits::decode(cursor, decoder, ec); - if (JSONCONS_UNLIKELY(ec)) {return v;} - //std::cout << "cursor.next 100\n"; - cursor.next(ec); - if (JSONCONS_UNLIKELY(ec)) {return v;} - } - return v; - } - }; - - // map like - - template - struct decode_traits::value && - ext_traits::is_map_like::value && - ext_traits::is_constructible_from_const_pointer_and_size::value - >::type> - { - using mapped_type = typename T::mapped_type; - using value_type = typename T::value_type; - using key_type = typename T::key_type; - - template - static T decode(basic_staj_cursor& cursor, - json_decoder& decoder, - std::error_code& ec) - { - T val; - if (cursor.current().event_type() != staj_event_type::begin_object) - { - ec = conv_errc::not_map; - return val; - } - if (cursor.current().size() > 0) - { - reserve_storage(typename std::integral_constant::value>::type(), val, cursor.current().size()); - } - cursor.next(ec); - - while (cursor.current().event_type() != staj_event_type::end_object && !ec) - { - if (cursor.current().event_type() != staj_event_type::key) - { - ec = json_errc::expected_key; - return val; - } - auto key = cursor.current().template get(ec); - if (JSONCONS_UNLIKELY(ec)) {return val;} - //std::cout << "cursor.next 200\n"; - cursor.next(ec); - if (JSONCONS_UNLIKELY(ec)) {return val;} - val.emplace(std::move(key),decode_traits::decode(cursor, decoder, ec)); - if (JSONCONS_UNLIKELY(ec)) {return val;} - //std::cout << "cursor.next 300\n"; - cursor.next(ec); - if (JSONCONS_UNLIKELY(ec)) {return val;} - } - return val; - } - - static void reserve_storage(std::true_type, T& v, std::size_t new_cap) - { - v.reserve(new_cap); - } - - static void reserve_storage(std::false_type, T&, std::size_t) - { - } - }; - - template - struct decode_traits::value && - ext_traits::is_map_like::value && - std::is_integral::value - >::type> - { - using mapped_type = typename T::mapped_type; - using value_type = typename T::value_type; - using key_type = typename T::key_type; - - template - static T decode(basic_staj_cursor& cursor, - json_decoder& decoder, - std::error_code& ec) - { - T val; - if (cursor.current().event_type() != staj_event_type::begin_object) - { - ec = conv_errc::not_map; - return val; - } - if (cursor.current().size() > 0) - { - reserve_storage(typename std::integral_constant::value>::type(), val, cursor.current().size()); - } - cursor.next(ec); - - while (cursor.current().event_type() != staj_event_type::end_object && !ec) - { - if (cursor.current().event_type() != staj_event_type::key) - { - ec = json_errc::expected_key; - return val; - } - auto s = cursor.current().template get>(ec); - if (JSONCONS_UNLIKELY(ec)) {return val;} - key_type n{0}; - auto r = jsoncons::detail::to_integer(s.data(), s.size(), n); - if (r.ec != jsoncons::detail::to_integer_errc()) - { - ec = json_errc::invalid_number; - return val; - } - //std::cout << "cursor.next 500\n"; - cursor.next(ec); - if (JSONCONS_UNLIKELY(ec)) {return val;} - val.emplace(n, decode_traits::decode(cursor, decoder, ec)); - if (JSONCONS_UNLIKELY(ec)) {return val;} - //std::cout << "cursor.next 600\n"; - cursor.next(ec); - if (JSONCONS_UNLIKELY(ec)) {return val;} - } - return val; - } - - static void reserve_storage(std::true_type, T& v, std::size_t new_cap) - { - v.reserve(new_cap); - } - - static void reserve_storage(std::false_type, T&, std::size_t) - { - } - }; - -} // namespace jsoncons - -#endif // JSONCONS_DECODE_TRAITS_HPP - diff --git a/include/jsoncons/detail/parse_number.hpp b/include/jsoncons/detail/parse_number.hpp deleted file mode 100644 index 95fb402..0000000 --- a/include/jsoncons/detail/parse_number.hpp +++ /dev/null @@ -1,1052 +0,0 @@ -// Copyright 2013-2025 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_DETAIL_PARSE_NUMBER_HPP -#define JSONCONS_DETAIL_PARSE_NUMBER_HPP - -#include -#include -#include -#include -#include -#include -#include -#include // std::enable_if -#include - -#include -#include -#include -#include - -namespace jsoncons { -namespace detail { - - enum class to_integer_errc : uint8_t {success=0, overflow, invalid_digit, invalid_number}; - - class to_integer_error_category_impl - : public std::error_category - { - public: - const char* name() const noexcept override - { - return "jsoncons/to_integer_unchecked"; - } - std::string message(int ev) const override - { - switch (static_cast(ev)) - { - case to_integer_errc::overflow: - return "Integer overflow"; - case to_integer_errc::invalid_digit: - return "Invalid digit"; - case to_integer_errc::invalid_number: - return "Invalid number"; - default: - return "Unknown to_integer_unchecked error"; - } - } - }; - - inline - const std::error_category& to_integer_error_category() noexcept - { - static to_integer_error_category_impl instance; - return instance; - } - - inline - std::error_code make_error_code(to_integer_errc e) noexcept - { - return std::error_code(static_cast(e),to_integer_error_category()); - } - -} // namespace detail -} // namespace jsoncons - -namespace std { - template<> - struct is_error_code_enum : public true_type - { - }; -} // namespace std - -namespace jsoncons { -namespace detail { - -template -struct to_integer_result -{ - const CharT* ptr; - to_integer_errc ec; - constexpr to_integer_result(const CharT* ptr_) - : ptr(ptr_), ec(to_integer_errc()) - { - } - constexpr to_integer_result(const CharT* ptr_, to_integer_errc ec_) - : ptr(ptr_), ec(ec_) - { - } - - to_integer_result(const to_integer_result&) = default; - - to_integer_result& operator=(const to_integer_result&) = default; - - constexpr explicit operator bool() const noexcept - { - return ec == to_integer_errc(); - } - std::error_code error_code() const - { - return make_error_code(ec); - } -}; - -enum class integer_chars_format : uint8_t {decimal=1,hex}; -enum class integer_chars_state {initial,minus,integer,binary,octal,decimal,base16}; - -template -bool is_base10(const CharT* s, std::size_t length) -{ - integer_chars_state state = integer_chars_state::initial; - - const CharT* end = s + length; - for (;s < end; ++s) - { - switch(state) - { - case integer_chars_state::initial: - { - switch(*s) - { - case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': - state = integer_chars_state::decimal; - break; - case '-': - state = integer_chars_state::minus; - break; - default: - return false; - } - break; - } - case integer_chars_state::minus: - { - switch(*s) - { - case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': - state = integer_chars_state::decimal; - break; - default: - return false; - } - break; - } - case integer_chars_state::decimal: - { - switch(*s) - { - case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': - break; - default: - return false; - } - break; - } - default: - break; - } - } - return state == integer_chars_state::decimal ? true : false; -} - -template -bool is_base16(const CharT* s, std::size_t length) -{ - integer_chars_state state = integer_chars_state::initial; - - const CharT* end = s + length; - for (;s < end; ++s) - { - switch(state) - { - case integer_chars_state::initial: - { - switch(*s) - { - case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': // Must be base16 - case 'a':case 'b':case 'c':case 'd':case 'e':case 'f': - case 'A':case 'B':case 'C':case 'D':case 'E':case 'F': - state = integer_chars_state::base16; - break; - default: - return false; - } - break; - } - case integer_chars_state::base16: - { - switch(*s) - { - case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': // Must be base16 - case 'a':case 'b':case 'c':case 'd':case 'e':case 'f': - case 'A':case 'B':case 'C':case 'D':case 'E':case 'F': - state = integer_chars_state::base16; - break; - default: - return false; - } - break; - } - default: - break; - } - } - return state == integer_chars_state::base16 ? true : false; -} - -template -typename std::enable_if::is_specialized && !ext_traits::integer_limits::is_signed,to_integer_result>::type -dec_to_integer(const CharT* s, std::size_t length, T& n) -{ - n = 0; - - integer_chars_state state = integer_chars_state::initial; - - const CharT* end = s + length; - while (s < end) - { - switch(state) - { - case integer_chars_state::initial: - { - switch(*s) - { - case '0': - if (++s == end) - { - return (++s == end) ? to_integer_result(s) : to_integer_result(s, to_integer_errc()); - } - else - { - return to_integer_result(s, to_integer_errc::invalid_digit); - } - case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': // Must be decimal - state = integer_chars_state::decimal; - break; - default: - return to_integer_result(s, to_integer_errc::invalid_digit); - } - break; - } - case integer_chars_state::decimal: - { - static constexpr T max_value = (ext_traits::integer_limits::max)(); - static constexpr T max_value_div_10 = max_value / 10; - for (; s < end; ++s) - { - T x = 0; - switch(*s) - { - case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': - x = static_cast(*s) - static_cast('0'); - break; - default: - return to_integer_result(s, to_integer_errc::invalid_digit); - } - if (n > max_value_div_10) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n = n * 10; - if (n > max_value - x) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n += x; - } - break; - } - default: - JSONCONS_UNREACHABLE(); - break; - } - } - return (state == integer_chars_state::initial) ? to_integer_result(s, to_integer_errc::invalid_number) : to_integer_result(s, to_integer_errc()); -} - -template -typename std::enable_if::is_specialized && ext_traits::integer_limits::is_signed,to_integer_result>::type -dec_to_integer(const CharT* s, std::size_t length, T& n) -{ - n = 0; - - if (length == 0) - { - return to_integer_result(s, to_integer_errc::invalid_number); - } - - bool is_negative = *s == '-' ? true : false; - if (is_negative) - { - ++s; - --length; - } - - using U = typename ext_traits::make_unsigned::type; - - U u; - auto ru = dec_to_integer(s, length, u); - if (ru.ec != to_integer_errc()) - { - return to_integer_result(ru.ptr, ru.ec); - } - if (is_negative) - { - if (u > static_cast(-((ext_traits::integer_limits::lowest)()+T(1))) + U(1)) - { - return to_integer_result(ru.ptr, to_integer_errc::overflow); - } - else - { - n = static_cast(U(0) - u); - return to_integer_result(ru.ptr, to_integer_errc()); - } - } - else - { - if (u > static_cast((ext_traits::integer_limits::max)())) - { - return to_integer_result(ru.ptr, to_integer_errc::overflow); - } - else - { - n = static_cast(u); - return to_integer_result(ru.ptr, to_integer_errc()); - } - } -} - -template -typename std::enable_if::is_specialized && !ext_traits::integer_limits::is_signed,to_integer_result>::type -to_integer(const CharT* s, std::size_t length, T& n) -{ - n = 0; - - integer_chars_state state = integer_chars_state::initial; - - const CharT* end = s + length; - while (s < end) - { - switch(state) - { - case integer_chars_state::initial: - { - switch(*s) - { - case '0': - state = integer_chars_state::integer; // Could be binary, octal, hex - ++s; - break; - case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': // Must be decimal - state = integer_chars_state::decimal; - break; - default: - return to_integer_result(s, to_integer_errc::invalid_digit); - } - break; - } - case integer_chars_state::integer: - { - switch(*s) - { - case 'b':case 'B': - { - state = integer_chars_state::binary; - ++s; - break; - } - case 'x':case 'X': - { - state = integer_chars_state::base16; - ++s; - break; - } - case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': - { - state = integer_chars_state::octal; - break; - } - default: - return to_integer_result(s, to_integer_errc::invalid_digit); - } - break; - } - case integer_chars_state::binary: - { - static constexpr T max_value = (ext_traits::integer_limits::max)(); - static constexpr T max_value_div_2 = max_value / 2; - for (; s < end; ++s) - { - T x = 0; - switch(*s) - { - case '0':case '1': - x = static_cast(*s) - static_cast('0'); - break; - default: - return to_integer_result(s, to_integer_errc::invalid_digit); - } - if (n > max_value_div_2) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n = n * 2; - if (n > max_value - x) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n += x; - } - break; - } - case integer_chars_state::octal: - { - static constexpr T max_value = (ext_traits::integer_limits::max)(); - static constexpr T max_value_div_8 = max_value / 8; - for (; s < end; ++s) - { - T x = 0; - switch(*s) - { - case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7': - x = static_cast(*s) - static_cast('0'); - break; - default: - return to_integer_result(s, to_integer_errc::invalid_digit); - } - if (n > max_value_div_8) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n = n * 8; - if (n > max_value - x) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n += x; - } - break; - } - case integer_chars_state::decimal: - { - static constexpr T max_value = (ext_traits::integer_limits::max)(); - static constexpr T max_value_div_10 = max_value / 10; - for (; s < end; ++s) - { - T x = 0; - switch(*s) - { - case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': - x = static_cast(*s) - static_cast('0'); - break; - default: - return to_integer_result(s, to_integer_errc::invalid_digit); - } - if (n > max_value_div_10) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n = n * 10; - if (n > max_value - x) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n += x; - } - break; - } - case integer_chars_state::base16: - { - static constexpr T max_value = (ext_traits::integer_limits::max)(); - static constexpr T max_value_div_16 = max_value / 16; - for (; s < end; ++s) - { - CharT c = *s; - T x = 0; - switch (c) - { - case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': - x = c - '0'; - break; - case 'a':case 'b':case 'c':case 'd':case 'e':case 'f': - x = c - ('a' - 10); - break; - case 'A':case 'B':case 'C':case 'D':case 'E':case 'F': - x = c - ('A' - 10); - break; - default: - return to_integer_result(s, to_integer_errc::invalid_digit); - } - if (n > max_value_div_16) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n = n * 16; - if (n > max_value - x) - { - return to_integer_result(s, to_integer_errc::overflow); - } - - n += x; - } - break; - } - default: - JSONCONS_UNREACHABLE(); - break; - } - } - return (state == integer_chars_state::initial) ? to_integer_result(s, to_integer_errc::invalid_number) : to_integer_result(s, to_integer_errc()); -} - -template -typename std::enable_if::is_specialized && ext_traits::integer_limits::is_signed,to_integer_result>::type -to_integer(const CharT* s, std::size_t length, T& n) -{ - n = 0; - - if (length == 0) - { - return to_integer_result(s, to_integer_errc::invalid_number); - } - - bool is_negative = *s == '-' ? true : false; - if (is_negative) - { - ++s; - --length; - } - - using U = typename ext_traits::make_unsigned::type; - - U u; - auto ru = to_integer(s, length, u); - if (ru.ec != to_integer_errc()) - { - return to_integer_result(ru.ptr, ru.ec); - } - if (is_negative) - { - if (u > static_cast(-((ext_traits::integer_limits::lowest)()+T(1))) + U(1)) - { - return to_integer_result(ru.ptr, to_integer_errc::overflow); - } - else - { - n = static_cast(U(0) - u); - return to_integer_result(ru.ptr, to_integer_errc()); - } - } - else - { - if (u > static_cast((ext_traits::integer_limits::max)())) - { - return to_integer_result(ru.ptr, to_integer_errc::overflow); - } - else - { - n = static_cast(u); - return to_integer_result(ru.ptr, to_integer_errc()); - } - } -} - -template -typename std::enable_if::is_specialized,to_integer_result>::type -to_integer(const CharT* s, T& n) -{ - return to_integer(s, std::char_traits::length(s), n); -} - -// Precondition: s satisfies - -// digit -// digit1-digits -// - digit -// - digit1-digits - -template -typename std::enable_if::is_specialized && !ext_traits::integer_limits::is_signed,to_integer_result>::type -to_integer_unchecked(const CharT* s, std::size_t length, T& n) -{ - static_assert(ext_traits::integer_limits::is_specialized, "Integer type not specialized"); - JSONCONS_ASSERT(length > 0); - - n = 0; - const CharT* end = s + length; - if (*s == '-') - { - static constexpr T min_value = (ext_traits::integer_limits::lowest)(); - static constexpr T min_value_div_10 = min_value / 10; - ++s; - for (; s < end; ++s) - { - T x = (T)*s - (T)('0'); - if (n < min_value_div_10) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n = n * 10; - if (n < min_value + x) - { - return to_integer_result(s, to_integer_errc::overflow); - } - - n -= x; - } - } - else - { - static constexpr T max_value = (ext_traits::integer_limits::max)(); - static constexpr T max_value_div_10 = max_value / 10; - for (; s < end; ++s) - { - T x = static_cast(*s) - static_cast('0'); - if (n > max_value_div_10) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n = n * 10; - if (n > max_value - x) - { - return to_integer_result(s, to_integer_errc::overflow); - } - - n += x; - } - } - - return to_integer_result(s, to_integer_errc()); -} - -// Precondition: s satisfies - -// digit -// digit1-digits -// - digit -// - digit1-digits - -template -typename std::enable_if::is_specialized && ext_traits::integer_limits::is_signed,to_integer_result>::type -to_integer_unchecked(const CharT* s, std::size_t length, T& n) -{ - static_assert(ext_traits::integer_limits::is_specialized, "Integer type not specialized"); - JSONCONS_ASSERT(length > 0); - - n = 0; - - const CharT* end = s + length; - if (*s == '-') - { - static constexpr T min_value = (ext_traits::integer_limits::lowest)(); - static constexpr T min_value_div_10 = min_value / 10; - ++s; - for (; s < end; ++s) - { - T x = (T)*s - (T)('0'); - if (n < min_value_div_10) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n = n * 10; - if (n < min_value + x) - { - return to_integer_result(s, to_integer_errc::overflow); - } - - n -= x; - } - } - else - { - static constexpr T max_value = (ext_traits::integer_limits::max)(); - static constexpr T max_value_div_10 = max_value / 10; - for (; s < end; ++s) - { - T x = static_cast(*s) - static_cast('0'); - if (n > max_value_div_10) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n = n * 10; - if (n > max_value - x) - { - return to_integer_result(s, to_integer_errc::overflow); - } - - n += x; - } - } - - return to_integer_result(s, to_integer_errc()); -} - -// hex_to_integer - -template -typename std::enable_if::is_specialized && ext_traits::integer_limits::is_signed,to_integer_result>::type -hex_to_integer(const CharT* s, std::size_t length, T& n) -{ - static_assert(ext_traits::integer_limits::is_specialized, "Integer type not specialized"); - JSONCONS_ASSERT(length > 0); - - n = 0; - - const CharT* end = s + length; - if (*s == '-') - { - static constexpr T min_value = (ext_traits::integer_limits::lowest)(); - static constexpr T min_value_div_16 = min_value / 16; - ++s; - for (; s < end; ++s) - { - CharT c = *s; - T x = 0; - switch (c) - { - case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': - x = c - '0'; - break; - case 'a':case 'b':case 'c':case 'd':case 'e':case 'f': - x = c - ('a' - 10); - break; - case 'A':case 'B':case 'C':case 'D':case 'E':case 'F': - x = c - ('A' - 10); - break; - default: - return to_integer_result(s, to_integer_errc::invalid_digit); - } - if (n < min_value_div_16) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n = n * 16; - if (n < min_value + x) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n -= x; - } - } - else - { - static constexpr T max_value = (ext_traits::integer_limits::max)(); - static constexpr T max_value_div_16 = max_value / 16; - for (; s < end; ++s) - { - CharT c = *s; - T x = 0; - switch (c) - { - case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': - x = c - '0'; - break; - case 'a':case 'b':case 'c':case 'd':case 'e':case 'f': - x = c - ('a' - 10); - break; - case 'A':case 'B':case 'C':case 'D':case 'E':case 'F': - x = c - ('A' - 10); - break; - default: - return to_integer_result(s, to_integer_errc::invalid_digit); - } - if (n > max_value_div_16) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n = n * 16; - if (n > max_value - x) - { - return to_integer_result(s, to_integer_errc::overflow); - } - - n += x; - } - } - - return to_integer_result(s, to_integer_errc()); -} - -template -typename std::enable_if::is_specialized && !ext_traits::integer_limits::is_signed,to_integer_result>::type -hex_to_integer(const CharT* s, std::size_t length, T& n) -{ - static_assert(ext_traits::integer_limits::is_specialized, "Integer type not specialized"); - JSONCONS_ASSERT(length > 0); - - n = 0; - const CharT* end = s + length; - - static constexpr T max_value = (ext_traits::integer_limits::max)(); - static constexpr T max_value_div_16 = max_value / 16; - for (; s < end; ++s) - { - CharT c = *s; - T x = *s; - switch (c) - { - case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': - x = c - '0'; - break; - case 'a':case 'b':case 'c':case 'd':case 'e':case 'f': - x = c - ('a' - 10); - break; - case 'A':case 'B':case 'C':case 'D':case 'E':case 'F': - x = c - ('A' - 10); - break; - default: - return to_integer_result(s, to_integer_errc::invalid_digit); - } - if (n > max_value_div_16) - { - return to_integer_result(s, to_integer_errc::overflow); - } - n = n * 16; - if (n > max_value - x) - { - return to_integer_result(s, to_integer_errc::overflow); - } - - n += x; - } - - return to_integer_result(s, to_integer_errc()); -} - - -#if defined(JSONCONS_HAS_STD_FROM_CHARS) && JSONCONS_HAS_STD_FROM_CHARS - -class chars_to -{ -public: - - char get_decimal_point() const - { - return '.'; - } - - template - typename std::enable_if::value,double>::type - operator()(const CharT* s, std::size_t len) const - { - double val = 0; - const auto res = std::from_chars(s, s+len, val); - if (res.ec != std::errc()) - { - JSONCONS_THROW(json_runtime_error("Convert chars to double failed")); - } - return val; - } - - template - typename std::enable_if::value,double>::type - operator()(const CharT* s, std::size_t len) const - { - std::string input(len,'0'); - for (size_t i = 0; i < len; ++i) - { - input[i] = static_cast(s[i]); - } - - double val = 0; - const auto res = std::from_chars(input.data(), input.data() + len, val); - if (res.ec != std::errc()) - { - JSONCONS_THROW(json_runtime_error("Convert chars to double failed")); - } - return val; - } -}; -#elif defined(JSONCONS_HAS_MSC_STRTOD_L) - -class chars_to -{ -private: - _locale_t locale_; -public: - chars_to() - { - locale_ = _create_locale(LC_NUMERIC, "C"); - } - ~chars_to() noexcept - { - _free_locale(locale_); - } - - chars_to(const chars_to&) - { - locale_ = _create_locale(LC_NUMERIC, "C"); - } - - chars_to& operator=(const chars_to&) - { - // Don't assign locale - return *this; - } - - char get_decimal_point() const - { - return '.'; - } - - template - typename std::enable_if::value,double>::type - operator()(const CharT* s, std::size_t) const - { - CharT *end = nullptr; - double val = _strtod_l(s, &end, locale_); - if (s == end) - { - JSONCONS_THROW(json_runtime_error("Convert string to double failed")); - } - return val; - } - - template - typename std::enable_if::value,double>::type - operator()(const CharT* s, std::size_t) const - { - CharT *end = nullptr; - double val = _wcstod_l(s, &end, locale_); - if (s == end) - { - JSONCONS_THROW(json_runtime_error("Convert string to double failed")); - } - return val; - } -}; - -#elif defined(JSONCONS_HAS_STRTOLD_L) - -class chars_to -{ -private: - locale_t locale_; -public: - chars_to() - { - locale_ = newlocale(LC_ALL_MASK, "C", (locale_t) 0); - } - ~chars_to() noexcept - { - freelocale(locale_); - } - - chars_to(const chars_to&) - { - locale_ = newlocale(LC_ALL_MASK, "C", (locale_t) 0); - } - - chars_to& operator=(const chars_to&) - { - return *this; - } - - char get_decimal_point() const - { - return '.'; - } - - template - typename std::enable_if::value,double>::type - operator()(const CharT* s, std::size_t) const - { - char *end = nullptr; - double val = strtold_l(s, &end, locale_); - if (s == end) - { - JSONCONS_THROW(json_runtime_error("Convert string to double failed")); - } - return val; - } - - template - typename std::enable_if::value,double>::type - operator()(const CharT* s, std::size_t) const - { - CharT *end = nullptr; - double val = wcstold_l(s, &end, locale_); - if (s == end) - { - JSONCONS_THROW(json_runtime_error("Convert string to double failed")); - } - return val; - } -}; - -#else -class chars_to -{ -private: - std::vector buffer_; - char decimal_point_; -public: - chars_to() - : buffer_() - { - struct lconv * lc = localeconv(); - if (lc != nullptr && lc->decimal_point[0] != 0) - { - decimal_point_ = lc->decimal_point[0]; - } - else - { - decimal_point_ = '.'; - } - buffer_.reserve(100); - } - - chars_to(const chars_to&) = default; - chars_to& operator=(const chars_to&) = default; - - char get_decimal_point() const - { - return decimal_point_; - } - - template - typename std::enable_if::value,double>::type - operator()(const CharT* s, std::size_t /*length*/) const - { - CharT *end = nullptr; - double val = strtod(s, &end); - if (s == end) - { - JSONCONS_THROW(json_runtime_error("Convert string to double failed")); - } - return val; - } - - template - typename std::enable_if::value,double>::type - operator()(const CharT* s, std::size_t /*length*/) const - { - CharT *end = nullptr; - double val = wcstod(s, &end); - if (s == end) - { - JSONCONS_THROW(json_runtime_error("Convert string to double failed")); - } - return val; - } -}; -#endif - -} // namespace detail -} // namespace jsoncons - -#endif // JSONCONS_DETAIL_PARSE_NUMBER_HPP diff --git a/include/jsoncons/detail/write_number.hpp b/include/jsoncons/detail/write_number.hpp deleted file mode 100644 index 4f7387a..0000000 --- a/include/jsoncons/detail/write_number.hpp +++ /dev/null @@ -1,572 +0,0 @@ -// Copyright 2013-2025 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_DETAIL_WRITE_NUMBER_HPP -#define JSONCONS_DETAIL_WRITE_NUMBER_HPP - -#include -#include -#include -#include -#include // std::numeric_limits -#include -#include -#include // snprintf -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace jsoncons { -namespace detail { - - inline - char to_hex_character(uint8_t c) - { - return (char)((c < 10) ? ('0' + c) : ('A' - 10 + c)); - } - - // from_integer - - template - typename std::enable_if::value,std::size_t>::type - from_integer(Integer value, Result& result) - { - using char_type = typename Result::value_type; - - char_type buf[255]; - char_type *p = buf; - const char_type* last = buf+255; - - bool is_negative = value < 0; - - if (value < 0) - { - do - { - *p++ = static_cast(48 - (value % 10)); - } - while ((value /= 10) && (p < last)); - } - else - { - - do - { - *p++ = static_cast(48 + value % 10); - } - while ((value /= 10) && (p < last)); - } - JSONCONS_ASSERT(p != last); - - std::size_t count = (p - buf); - if (is_negative) - { - result.push_back('-'); - ++count; - } - while (--p >= buf) - { - result.push_back(*p); - } - - return count; - } - - // integer_to_hex - - template - typename std::enable_if::value,std::size_t>::type - integer_to_hex(Integer value, Result& result) - { - using char_type = typename Result::value_type; - - char_type buf[255]; - char_type *p = buf; - const char_type* last = buf+255; - - bool is_negative = value < 0; - - if (value < 0) - { - do - { - *p++ = to_hex_character(0-(value % 16)); - } - while ((value /= 16) && (p < last)); - } - else - { - - do - { - *p++ = to_hex_character(value % 16); - } - while ((value /= 16) && (p < last)); - } - JSONCONS_ASSERT(p != last); - - std::size_t count = (p - buf); - if (is_negative) - { - result.push_back('-'); - ++count; - } - while (--p >= buf) - { - result.push_back(*p); - } - - return count; - } - - // write_double - - // fast exponent - template - void fill_exponent(int K, Result& result) - { - if (K < 0) - { - result.push_back('-'); - K = -K; - } - else - { - result.push_back('+'); // compatibility with sprintf - } - - if (K < 10) - { - result.push_back('0'); // compatibility with sprintf - result.push_back((char)('0' + K)); - } - else if (K < 100) - { - result.push_back((char)('0' + K / 10)); K %= 10; - result.push_back((char)('0' + K)); - } - else if (K < 1000) - { - result.push_back((char)('0' + K / 100)); K %= 100; - result.push_back((char)('0' + K / 10)); K %= 10; - result.push_back((char)('0' + K)); - } - else - { - jsoncons::detail::from_integer(K, result); - } - } - - template - void prettify_string(const char *buffer, std::size_t length, int k, int min_exp, int max_exp, Result& result) - { - int nb_digits = (int)length; - int offset; - /* v = buffer * 10^k - kk is such that 10^(kk-1) <= v < 10^kk - this way kk gives the position of the decimal point. - */ - int kk = nb_digits + k; - - if (nb_digits <= kk && kk <= max_exp) - { - /* the first digits are already in. Add some 0s and call it a day. */ - /* the max_exp is a personal choice. Only 16 digits could possibly be relevant. - * Basically we want to print 12340000000 rather than 1234.0e7 or 1.234e10 */ - for (int i = 0; i < nb_digits; ++i) - { - result.push_back(buffer[i]); - } - for (int i = nb_digits; i < kk; ++i) - { - result.push_back('0'); - } - result.push_back('.'); - result.push_back('0'); - } - else if (0 < kk && kk <= max_exp) - { - /* comma number. Just insert a '.' at the correct location. */ - for (int i = 0; i < kk; ++i) - { - result.push_back(buffer[i]); - } - result.push_back('.'); - for (int i = kk; i < nb_digits; ++i) - { - result.push_back(buffer[i]); - } - } - else if (min_exp < kk && kk <= 0) - { - offset = 2 - kk; - - result.push_back('0'); - result.push_back('.'); - for (int i = 2; i < offset; ++i) - result.push_back('0'); - for (int i = 0; i < nb_digits; ++i) - { - result.push_back(buffer[i]); - } - } - else if (nb_digits == 1) - { - result.push_back(buffer[0]); - result.push_back('e'); - fill_exponent(kk - 1, result); - } - else - { - result.push_back(buffer[0]); - result.push_back('.'); - for (int i = 1; i < nb_digits; ++i) - { - result.push_back(buffer[i]); - } - result.push_back('e'); - fill_exponent(kk - 1, result); - } - } - - template - void dump_buffer(const char *buffer, std::size_t length, char decimal_point, Result& result) - { - const char *sbeg = buffer; - const char *send = sbeg + length; - - if (sbeg != send) - { - bool needs_dot = true; - for (const char* q = sbeg; q < send; ++q) - { - switch (*q) - { - case '-': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '+': - result.push_back(*q); - break; - case 'e': - case 'E': - result.push_back('e'); - needs_dot = false; - break; - default: - if (*q == decimal_point) - { - needs_dot = false; - result.push_back('.'); - } - break; - } - } - if (needs_dot) - { - result.push_back('.'); - result.push_back('0'); - } - } - } - - template - bool dtoa_scientific(double val, char decimal_point, Result& result) - { - if (val == 0) - { - result.push_back('0'); - result.push_back('.'); - result.push_back('0'); - return true; - } - - const jsoncons::detail::chars_to to_double; - - char buffer[100]; - int precision = std::numeric_limits::digits10; - int length = snprintf(buffer, sizeof(buffer), "%1.*e", precision, val); - if (length < 0) - { - return false; - } - if (to_double(buffer, sizeof(buffer)) != val) - { - const int precision2 = std::numeric_limits::max_digits10; - length = snprintf(buffer, sizeof(buffer), "%1.*e", precision2, val); - if (length < 0) - { - return false; - } - } - dump_buffer(buffer, static_cast(length), decimal_point, result); - return true; - } - - template - bool dtoa_general(double val, char decimal_point, Result& result, std::false_type) - { - if (val == 0) - { - result.push_back('0'); - result.push_back('.'); - result.push_back('0'); - return true; - } - - const jsoncons::detail::chars_to to_double; - - char buffer[100]; - int precision = std::numeric_limits::digits10; - int length = snprintf(buffer, sizeof(buffer), "%1.*g", precision, val); - if (length < 0) - { - return false; - } - if (to_double(buffer, sizeof(buffer)) != val) - { - const int precision2 = std::numeric_limits::max_digits10; - length = snprintf(buffer, sizeof(buffer), "%1.*g", precision2, val); - if (length < 0) - { - return false; - } - } - dump_buffer(buffer, length, decimal_point, result); - return true; - } - - template - bool dtoa_general(double v, char decimal_point, Result& result, std::true_type) - { - if (v == 0) - { - result.push_back('0'); - result.push_back('.'); - result.push_back('0'); - return true; - } - - int length = 0; - int k; - - char buffer[100]; - - double u = std::signbit(v) ? -v : v; - if (jsoncons::detail::grisu3(u, buffer, &length, &k)) - { - if (std::signbit(v)) - { - result.push_back('-'); - } - // min exp: -4 is consistent with sprintf - // max exp: std::numeric_limits::max_digits10 - jsoncons::detail::prettify_string(buffer, length, k, -4, std::numeric_limits::max_digits10, result); - return true; - } - else - { - return dtoa_general(v, decimal_point, result, std::false_type()); - } - } - - template - bool dtoa_fixed(double val, char decimal_point, Result& result, std::false_type) - { - if (val == 0) - { - result.push_back('0'); - result.push_back('.'); - result.push_back('0'); - return true; - } - - const jsoncons::detail::chars_to to_double; - - char buffer[100]; - int precision = std::numeric_limits::digits10; - int length = snprintf(buffer, sizeof(buffer), "%1.*f", precision, val); - if (length < 0) - { - return false; - } - if (to_double(buffer, sizeof(buffer)) != val) - { - const int precision2 = std::numeric_limits::max_digits10; - length = snprintf(buffer, sizeof(buffer), "%1.*f", precision2, val); - if (length < 0) - { - return false; - } - } - dump_buffer(buffer, length, decimal_point, result); - return true; - } - - template - bool dtoa_fixed(double v, char decimal_point, Result& result, std::true_type) - { - if (v == 0) - { - result.push_back('0'); - result.push_back('.'); - result.push_back('0'); - return true; - } - - int length = 0; - int k; - - char buffer[100]; - - double u = std::signbit(v) ? -v : v; - if (jsoncons::detail::grisu3(u, buffer, &length, &k)) - { - if (std::signbit(v)) - { - result.push_back('-'); - } - jsoncons::detail::prettify_string(buffer, length, k, std::numeric_limits::lowest(), (std::numeric_limits::max)(), result); - return true; - } - else - { - return dtoa_fixed(v, decimal_point, result, std::false_type()); - } - } - - template - bool dtoa_fixed(double v, char decimal_point, Result& result) - { - return dtoa_fixed(v, decimal_point, result, std::integral_constant::is_iec559>()); - } - - template - bool dtoa_general(double v, char decimal_point, Result& result) - { - return dtoa_general(v, decimal_point, result, std::integral_constant::is_iec559>()); - } - - class write_double - { - private: - chars_to to_double_; - float_chars_format float_format_; - int precision_; - char decimal_point_; - public: - write_double(float_chars_format float_format, int precision) - : float_format_(float_format), precision_(precision), decimal_point_('.') - { - #if !defined(JSONCONS_NO_LOCALECONV) - struct lconv *lc = localeconv(); - if (lc != nullptr && lc->decimal_point[0] != 0) - { - decimal_point_ = lc->decimal_point[0]; - } - #endif - } - write_double(const write_double&) = default; - - write_double& operator=(const write_double&) = default; - - template - std::size_t operator()(double val, Result& result) - { - std::size_t count = 0; - - char number_buffer[200]; - int length = 0; - - switch (float_format_) - { - case float_chars_format::fixed: - { - if (precision_ > 0) - { - length = snprintf(number_buffer, sizeof(number_buffer), "%1.*f", precision_, val); - if (length < 0) - { - JSONCONS_THROW(json_runtime_error("write_double failed.")); - } - dump_buffer(number_buffer, length, decimal_point_, result); - } - else - { - if (!dtoa_fixed(val, decimal_point_, result)) - { - JSONCONS_THROW(json_runtime_error("write_double failed.")); - } - } - } - break; - case float_chars_format::scientific: - { - if (precision_ > 0) - { - length = snprintf(number_buffer, sizeof(number_buffer), "%1.*e", precision_, val); - if (length < 0) - { - JSONCONS_THROW(json_runtime_error("write_double failed.")); - } - dump_buffer(number_buffer, length, decimal_point_, result); - } - else - { - if (!dtoa_scientific(val, decimal_point_, result)) - { - JSONCONS_THROW(json_runtime_error("write_double failed.")); - } - } - } - break; - case float_chars_format::general: - { - if (precision_ > 0) - { - length = snprintf(number_buffer, sizeof(number_buffer), "%1.*g", precision_, val); - if (length < 0) - { - JSONCONS_THROW(json_runtime_error("write_double failed.")); - } - dump_buffer(number_buffer, length, decimal_point_, result); - } - else - { - if (!dtoa_general(val, decimal_point_, result)) - { - JSONCONS_THROW(json_runtime_error("write_double failed.")); - } - } - break; - } - default: - JSONCONS_THROW(json_runtime_error("write_double failed.")); - break; - } - return count; - } - }; - -} // namespace detail -} // namespace jsoncons - -#endif // JSONCONS_DETAIL_WRITE_NUMBER_HPP diff --git a/include/jsoncons/encode_traits.hpp b/include/jsoncons/encode_traits.hpp deleted file mode 100644 index 57e1a7c..0000000 --- a/include/jsoncons/encode_traits.hpp +++ /dev/null @@ -1,385 +0,0 @@ -// Copyright 2013-2025 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_ENCODE_TRAITS_HPP -#define JSONCONS_ENCODE_TRAITS_HPP - -#include -#include -#include -#include -#include -#include -#include -#include // std::enable_if, std::true_type, std::false_type - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace jsoncons { - - // encode_traits - - template - struct encode_traits - { - template - static void encode(const T& val, - basic_json_visitor& encoder, - const Json& proto, - std::error_code& ec) - { - encode(std::integral_constant::is_always_equal::value>(), - val, encoder, proto, ec); - } - private: - template - static void encode(std::true_type, - const T& val, - basic_json_visitor& encoder, - const Json& /*proto*/, - std::error_code& ec) - { - auto j = json_type_traits::to_json(val); - j.dump(encoder, ec); - } - template - static void encode(std::false_type, - const T& val, - basic_json_visitor& encoder, - const Json& proto, - std::error_code& ec) - { - auto j = json_type_traits::to_json(val, proto.get_allocator()); - j.dump(encoder, ec); - } - }; - - // specializations - - // bool - template - struct encode_traits::value - >::type> - { - template - static void encode(const T& val, - basic_json_visitor& encoder, - const Json&, - std::error_code& ec) - { - encoder.bool_value(val,semantic_tag::none,ser_context(),ec); - } - }; - - // uint - template - struct encode_traits::value - >::type> - { - template - static void encode(const T& val, - basic_json_visitor& encoder, - const Json&, - std::error_code& ec) - { - encoder.uint64_value(val,semantic_tag::none,ser_context(),ec); - } - }; - - // int - template - struct encode_traits::value - >::type> - { - template - static void encode(const T& val, - basic_json_visitor& encoder, - const Json&, - std::error_code& ec) - { - encoder.int64_value(val,semantic_tag::none,ser_context(),ec); - } - }; - - // float or double - template - struct encode_traits::value - >::type> - { - template - static void encode(const T& val, - basic_json_visitor& encoder, - const Json&, - std::error_code& ec) - { - encoder.double_value(val,semantic_tag::none,ser_context(),ec); - } - }; - - // string - template - struct encode_traits::value && - std::is_same::value - >::type> - { - template - static void encode(const T& val, - basic_json_visitor& encoder, - const Json&, - std::error_code& ec) - { - encoder.string_value(val,semantic_tag::none,ser_context(),ec); - } - }; - template - struct encode_traits::value && - !std::is_same::value - >::type> - { - template - static void encode(const T& val, - basic_json_visitor& encoder, - const Json&, - std::error_code& ec) - { - std::basic_string s; - unicode_traits::convert(val.data(), val.size(), s); - encoder.string_value(s,semantic_tag::none,ser_context(),ec); - } - }; - - // std::pair - - template - struct encode_traits, CharT> - { - using value_type = std::pair; - - template - static void encode(const value_type& val, - basic_json_visitor& encoder, - const Json& proto, - std::error_code& ec) - { - encoder.begin_array(2,semantic_tag::none,ser_context(),ec); - if (JSONCONS_UNLIKELY(ec)) {return;} - encode_traits::encode(val.first, encoder, proto, ec); - if (JSONCONS_UNLIKELY(ec)) {return;} - encode_traits::encode(val.second, encoder, proto, ec); - if (JSONCONS_UNLIKELY(ec)) {return;} - encoder.end_array(ser_context(),ec); - } - }; - - // std::tuple - - namespace detail - { - template - struct json_serialize_tuple_helper - { - using char_type = typename Json::char_type; - using element_type = typename std::tuple_element::type; - using next = json_serialize_tuple_helper; - - static void encode(const Tuple& tuple, - basic_json_visitor& encoder, - const Json& proto, - std::error_code& ec) - { - encode_traits::encode(std::get(tuple), encoder, proto, ec); - if (JSONCONS_UNLIKELY(ec)) {return;} - next::encode(tuple, encoder, proto, ec); - } - }; - - template - struct json_serialize_tuple_helper<0, Size, Json, Tuple> - { - using char_type = typename Json::char_type; - static void encode(const Tuple&, - basic_json_visitor&, - const Json&, - std::error_code&) - { - } - }; - } // namespace detail - - - template - struct encode_traits, CharT> - { - using value_type = std::tuple; - static constexpr std::size_t size = sizeof...(E); - - template - static void encode(const value_type& val, - basic_json_visitor& encoder, - const Json& proto, - std::error_code& ec) - { - using helper = jsoncons::detail::json_serialize_tuple_helper>; - encoder.begin_array(size,semantic_tag::none,ser_context(),ec); - if (JSONCONS_UNLIKELY(ec)) {return;} - helper::encode(val, encoder, proto, ec); - if (JSONCONS_UNLIKELY(ec)) {return;} - encoder.end_array(ser_context(),ec); - } - }; - - // vector like - template - struct encode_traits::value && - ext_traits::is_array_like::value && - !ext_traits::is_typed_array::value - >::type> - { - using value_type = typename T::value_type; - - template - static void encode(const T& val, - basic_json_visitor& encoder, - const Json& proto, - std::error_code& ec) - { - encoder.begin_array(val.size(),semantic_tag::none,ser_context(),ec); - if (JSONCONS_UNLIKELY(ec)) {return;} - for (auto it = std::begin(val); it != std::end(val); ++it) - { - encode_traits::encode(*it, encoder, proto, ec); - if (JSONCONS_UNLIKELY(ec)) {return;} - } - encoder.end_array(ser_context(), ec); - } - }; - - template - struct encode_traits::value && - ext_traits::is_array_like::value && - ext_traits::is_typed_array::value - >::type> - { - using value_type = typename T::value_type; - - template - static void encode(const T& val, - basic_json_visitor& encoder, - const Json&, - std::error_code& ec) - { - encoder.typed_array(jsoncons::span(val), semantic_tag::none, ser_context(), ec); - } - }; - - // std::array - - template - struct encode_traits,CharT> - { - using value_type = typename std::array::value_type; - - template - static void encode(const std::array& val, - basic_json_visitor& encoder, - const Json& proto, - std::error_code& ec) - { - encoder.begin_array(val.size(),semantic_tag::none,ser_context(),ec); - if (JSONCONS_UNLIKELY(ec)) {return;} - for (auto it = std::begin(val); it != std::end(val); ++it) - { - encode_traits::encode(*it, encoder, proto, ec); - if (JSONCONS_UNLIKELY(ec)) {return;} - } - encoder.end_array(ser_context(),ec); - } - }; - - // map like - - template - struct encode_traits::value && - ext_traits::is_map_like::value && - ext_traits::is_constructible_from_const_pointer_and_size::value - >::type> - { - using mapped_type = typename T::mapped_type; - using value_type = typename T::value_type; - using key_type = typename T::key_type; - - template - static void encode(const T& val, - basic_json_visitor& encoder, - const Json& proto, - std::error_code& ec) - { - encoder.begin_object(val.size(), semantic_tag::none, ser_context(), ec); - if (JSONCONS_UNLIKELY(ec)) {return;} - for (auto it = std::begin(val); it != std::end(val); ++it) - { - encoder.key((*it).first); - encode_traits::encode((*it).second, encoder, proto, ec); - if (JSONCONS_UNLIKELY(ec)) {return;} - } - encoder.end_object(ser_context(), ec); - if (JSONCONS_UNLIKELY(ec)) {return;} - } - }; - - template - struct encode_traits::value && - ext_traits::is_map_like::value && - std::is_integral::value - >::type> - { - using mapped_type = typename T::mapped_type; - using value_type = typename T::value_type; - using key_type = typename T::key_type; - - template - static void encode(const T& val, - basic_json_visitor& encoder, - const Json& proto, - std::error_code& ec) - { - encoder.begin_object(val.size(), semantic_tag::none, ser_context(), ec); - if (JSONCONS_UNLIKELY(ec)) {return;} - for (auto it = std::begin(val); it != std::end(val); ++it) - { - std::basic_string s; - jsoncons::detail::from_integer((*it).first,s); - encoder.key(s); - encode_traits::encode((*it).second, encoder, proto, ec); - if (JSONCONS_UNLIKELY(ec)) {return;} - } - encoder.end_object(ser_context(), ec); - if (JSONCONS_UNLIKELY(ec)) {return;} - } - }; - -} // namespace jsoncons - -#endif // JSONCONS_ENCODE_TRAITS_HPP - diff --git a/include/jsoncons/json_traits_macros.hpp b/include/jsoncons/json_traits_macros.hpp deleted file mode 100644 index 2d2e0e4..0000000 --- a/include/jsoncons/json_traits_macros.hpp +++ /dev/null @@ -1,1068 +0,0 @@ -// Copyright 2013-2025 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_JSON_TRAITS_MACROS_HPP -#define JSONCONS_JSON_TRAITS_MACROS_HPP - -#include - -#include -#include // JSONCONS_EXPAND, JSONCONS_QUOTE -#include -#include - -namespace jsoncons -{ - #define JSONCONS_RDONLY(X) - - #define JSONCONS_RDWR(X) X - - struct always_true - { - template< typename T> - constexpr bool operator()(const T&) const noexcept - { - return true; - } - }; - - struct identity - { - template< typename T> - constexpr T&& operator()(T&& val) const noexcept - { - return std::forward(val); - } - }; - - template - struct json_traits_macro_names - {}; - - template - struct json_traits_helper - { - using string_view_type = typename Json::string_view_type; - - template - static void set_udt_member(const Json&, const string_view_type&, const OutputType&) - { - } - template - static void set_udt_member(const Json& j, const string_view_type& key, OutputType& val) - { - val = j.at(key).template as(); - } - - template - static void set_udt_member(const Json&, const string_view_type&, From, const OutputType&) - { - } - template - static void set_udt_member(const Json& j, const string_view_type& key, From from, OutputType& val) - { - val = from(j.at(key).template as()); - } - template - static void set_optional_json_member(const string_view_type& key, const std::shared_ptr& val, Json& j) - { - if (val) j.try_emplace(key, val); - } - template - static void set_optional_json_member(const string_view_type& key, const std::unique_ptr& val, Json& j) - { - if (val) j.try_emplace(key, val); - } - template - static void set_optional_json_member(const string_view_type& key, const jsoncons::optional& val, Json& j) - { - if (val) j.try_emplace(key, val); - } - template - static void set_optional_json_member(const string_view_type& key, const U& val, Json& j) - { - j.try_emplace(key, val); - } - }; -} - -#if defined(_MSC_VER) -#pragma warning( disable : 4127) -#endif - -#define JSONCONS_CONCAT_IMPL(a, b) a ## b -#define JSONCONS_CONCAT(a, b) JSONCONS_CONCAT_IMPL(a, b) - -// Inspired by https://github.com/Loki-Astari/ThorsSerializer/blob/master/src/Serialize/Traits.h - -#define JSONCONS_NARGS(...) JSONCONS_NARG_(__VA_ARGS__, 70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0) -#define JSONCONS_NARG_(...) JSONCONS_EXPAND( JSONCONS_ARG_N(__VA_ARGS__) ) -#define JSONCONS_ARG_N(e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15,e16,e17,e18,e19,e20,e21,e22,e23,e24,e25,e26,e27,e28,e29,e30,e31,e32,e33,e34,e35,e36,e37,e38,e39,e40,e41,e42,e43,e44,e45,e46,e47,e48,e49,e50,e51,e52,e53,e54,e55,e56,e57,e58,e59,e60,e61,e62,e63,e64,e65,e66,e67,e68,e69,e70,N,...)N - -#define JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, Count) Call(P1, P2, P3, P4, Count) - -#define JSONKONS_VARIADIC_FOR_EACH(Call, P1, P2, P3, ...) JSONCONS_VARIADIC_REP_OF_N(Call, P1,P2, P3, JSONCONS_NARGS(__VA_ARGS__), __VA_ARGS__) -#define JSONCONS_VARIADIC_REP_OF_N(Call, P1, P2, P3, Count, ...) JSONCONS_VARIADIC_REP_OF_N_(Call, P1, P2, P3, Count, __VA_ARGS__) -#define JSONCONS_VARIADIC_REP_OF_N_(Call, P1, P2, P3, Count, ...) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_ ## Count(Call, P1, P2, P3, __VA_ARGS__)) - -#define JSONCONS_VARIADIC_REP_OF_70(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 70) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_69(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_69(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 69) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_68(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_68(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 68) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_67(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_67(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 67) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_66(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_66(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 66) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_65(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_65(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 65) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_64(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_64(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 64) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_63(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_63(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 63) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_62(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_62(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 62) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_61(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_61(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 61) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_60(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_60(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 60) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_59(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_59(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 59) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_58(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_58(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 58) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_57(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_57(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 57) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_56(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_56(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 56) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_55(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_55(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 55) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_54(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_54(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 54) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_53(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_53(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 53) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_52(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_52(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 52) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_51(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_51(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 51) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_50(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_50(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 50) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_49(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_49(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 49) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_48(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_48(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 48) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_47(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_47(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 47) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_46(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_46(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 46) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_45(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_45(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 45) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_44(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_44(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 44) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_43(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_43(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 43) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_42(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_42(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 42) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_41(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_41(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 41) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_40(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_40(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 40) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_39(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_39(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 39) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_38(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_38(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 38) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_37(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_37(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 37) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_36(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_36(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 36) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_35(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_35(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 35) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_34(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_34(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 34) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_33(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_33(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 33) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_32(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_32(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 32) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_31(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_31(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 31) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_30(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_30(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 30) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_29(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_29(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 29) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_28(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_28(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 28) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_27(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_27(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 27) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_26(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_26(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 26) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_25(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_25(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 25) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_24(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_24(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 24) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_23(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_23(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 23) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_22(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_22(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 22) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_21(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_21(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 21) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_20(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_20(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 20) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_19(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_19(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 19) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_18(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_18(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 18) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_17(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_17(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 17) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_16(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_16(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 16) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_15(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_15(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 15) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_14(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_14(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 14) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_13(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_13(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 13) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_12(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_12(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 12) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_11(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_11(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 11) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_10(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_10(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 10) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_9(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_9(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 9) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_8(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_8(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 8) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_7(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_7(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 7) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_6(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_6(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 6) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_5(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_5(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 5) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_4(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_4(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 4) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_3(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_3(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 3) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_2(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_2(Call, P1, P2, P3, P4, ...) JSONCONS_EXPAND_CALL5(Call, P1, P2, P3, P4, 2) JSONCONS_EXPAND(JSONCONS_VARIADIC_REP_OF_1(Call, P1, P2, P3, __VA_ARGS__)) -#define JSONCONS_VARIADIC_REP_OF_1(Call, P1, P2, P3, P4) JSONCONS_EXPAND(Call ## _LAST(P1, P2, P3, P4, 1)) - -#define JSONCONS_TYPE_TRAITS_FRIEND \ - template \ - friend struct jsoncons::json_type_traits; - -#define JSONCONS_EXPAND_CALL2(Call, Expr, Id) JSONCONS_EXPAND(Call(Expr, Id)) - -#define JSONCONS_REP_OF_N(Call, Expr, Pre, App, Count) JSONCONS_REP_OF_ ## Count(Call, Expr, Pre, App) - -#define JSONCONS_REP_OF_50(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 50) JSONCONS_REP_OF_49(Call, Expr, , App) -#define JSONCONS_REP_OF_49(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 49) JSONCONS_REP_OF_48(Call, Expr, , App) -#define JSONCONS_REP_OF_48(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 48) JSONCONS_REP_OF_47(Call, Expr, , App) -#define JSONCONS_REP_OF_47(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 47) JSONCONS_REP_OF_46(Call, Expr, , App) -#define JSONCONS_REP_OF_46(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 46) JSONCONS_REP_OF_45(Call, Expr, , App) -#define JSONCONS_REP_OF_45(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 45) JSONCONS_REP_OF_44(Call, Expr, , App) -#define JSONCONS_REP_OF_44(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 44) JSONCONS_REP_OF_43(Call, Expr, , App) -#define JSONCONS_REP_OF_43(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 43) JSONCONS_REP_OF_42(Call, Expr, , App) -#define JSONCONS_REP_OF_42(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 42) JSONCONS_REP_OF_41(Call, Expr, , App) -#define JSONCONS_REP_OF_41(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 41) JSONCONS_REP_OF_40(Call, Expr, , App) -#define JSONCONS_REP_OF_40(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 40) JSONCONS_REP_OF_39(Call, Expr, , App) -#define JSONCONS_REP_OF_39(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 39) JSONCONS_REP_OF_38(Call, Expr, , App) -#define JSONCONS_REP_OF_38(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 38) JSONCONS_REP_OF_37(Call, Expr, , App) -#define JSONCONS_REP_OF_37(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 37) JSONCONS_REP_OF_36(Call, Expr, , App) -#define JSONCONS_REP_OF_36(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 36) JSONCONS_REP_OF_35(Call, Expr, , App) -#define JSONCONS_REP_OF_35(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 35) JSONCONS_REP_OF_34(Call, Expr, , App) -#define JSONCONS_REP_OF_34(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 34) JSONCONS_REP_OF_33(Call, Expr, , App) -#define JSONCONS_REP_OF_33(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 33) JSONCONS_REP_OF_32(Call, Expr, , App) -#define JSONCONS_REP_OF_32(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 32) JSONCONS_REP_OF_31(Call, Expr, , App) -#define JSONCONS_REP_OF_31(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 31) JSONCONS_REP_OF_30(Call, Expr, , App) -#define JSONCONS_REP_OF_30(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 30) JSONCONS_REP_OF_29(Call, Expr, , App) -#define JSONCONS_REP_OF_29(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 29) JSONCONS_REP_OF_28(Call, Expr, , App) -#define JSONCONS_REP_OF_28(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 28) JSONCONS_REP_OF_27(Call, Expr, , App) -#define JSONCONS_REP_OF_27(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 27) JSONCONS_REP_OF_26(Call, Expr, , App) -#define JSONCONS_REP_OF_26(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 26) JSONCONS_REP_OF_25(Call, Expr, , App) -#define JSONCONS_REP_OF_25(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 25) JSONCONS_REP_OF_24(Call, Expr, , App) -#define JSONCONS_REP_OF_24(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 24) JSONCONS_REP_OF_23(Call, Expr, , App) -#define JSONCONS_REP_OF_23(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 23) JSONCONS_REP_OF_22(Call, Expr, , App) -#define JSONCONS_REP_OF_22(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 22) JSONCONS_REP_OF_21(Call, Expr, , App) -#define JSONCONS_REP_OF_21(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 21) JSONCONS_REP_OF_20(Call, Expr, , App) -#define JSONCONS_REP_OF_20(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 20) JSONCONS_REP_OF_19(Call, Expr, , App) -#define JSONCONS_REP_OF_19(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 19) JSONCONS_REP_OF_18(Call, Expr, , App) -#define JSONCONS_REP_OF_18(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 18) JSONCONS_REP_OF_17(Call, Expr, , App) -#define JSONCONS_REP_OF_17(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 17) JSONCONS_REP_OF_16(Call, Expr, , App) -#define JSONCONS_REP_OF_16(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 16) JSONCONS_REP_OF_15(Call, Expr, , App) -#define JSONCONS_REP_OF_15(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 15) JSONCONS_REP_OF_14(Call, Expr, , App) -#define JSONCONS_REP_OF_14(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 14) JSONCONS_REP_OF_13(Call, Expr, , App) -#define JSONCONS_REP_OF_13(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 13) JSONCONS_REP_OF_12(Call, Expr, , App) -#define JSONCONS_REP_OF_12(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 12) JSONCONS_REP_OF_11(Call, Expr, , App) -#define JSONCONS_REP_OF_11(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 11) JSONCONS_REP_OF_10(Call, Expr, , App) -#define JSONCONS_REP_OF_10(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 10) JSONCONS_REP_OF_9(Call, Expr, , App) -#define JSONCONS_REP_OF_9(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 9) JSONCONS_REP_OF_8(Call, Expr, , App) -#define JSONCONS_REP_OF_8(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 8) JSONCONS_REP_OF_7(Call, Expr, , App) -#define JSONCONS_REP_OF_7(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 7) JSONCONS_REP_OF_6(Call, Expr, , App) -#define JSONCONS_REP_OF_6(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 6) JSONCONS_REP_OF_5(Call, Expr, , App) -#define JSONCONS_REP_OF_5(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 5) JSONCONS_REP_OF_4(Call, Expr, , App) -#define JSONCONS_REP_OF_4(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 4) JSONCONS_REP_OF_3(Call, Expr, , App) -#define JSONCONS_REP_OF_3(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 3) JSONCONS_REP_OF_2(Call, Expr, , App) -#define JSONCONS_REP_OF_2(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call, Expr, 2) JSONCONS_REP_OF_1(Call, Expr, , App) -#define JSONCONS_REP_OF_1(Call, Expr, Pre, App) Pre JSONCONS_EXPAND_CALL2(Call ## _LAST, Expr, 1) App -#define JSONCONS_REP_OF_0(Call, Expr, Pre, App) - -#define JSONCONS_GENERATE_TPL_PARAMS(Call, Count) JSONCONS_REP_OF_N(Call, , , ,Count) -#define JSONCONS_GENERATE_TPL_ARGS(Call, Count) JSONCONS_REP_OF_N(Call, ,<,>,Count) -#define JSONCONS_GENERATE_TPL_PARAM(Expr, Id) typename T ## Id, -#define JSONCONS_GENERATE_TPL_PARAM_LAST(Expr, Id) typename T ## Id -#define JSONCONS_GENERATE_MORE_TPL_PARAM(Expr, Id) ,typename T ## Id -#define JSONCONS_GENERATE_MORE_TPL_PARAM_LAST(Expr, Id) ,typename T ## Id -#define JSONCONS_GENERATE_TPL_ARG(Expr, Id) T ## Id, -#define JSONCONS_GENERATE_TPL_ARG_LAST(Ex, Id) T ## Id - -#define JSONCONS_GENERATE_NAME_STR(Prefix, P2, P3, Member, Count) JSONCONS_GENERATE_NAME_STR_LAST(Prefix, P2, P3, Member, Count) -#define JSONCONS_GENERATE_NAME_STR_LAST(Prefix, P2, P3, Member, Count) \ - static inline const char* Member ## _str(char) {return JSONCONS_QUOTE(,Member);} \ - static inline const wchar_t* Member ## _str(wchar_t) {return JSONCONS_QUOTE(L,Member);} \ - /**/ - -#define JSONCONS_N_MEMBER_IS(Prefix, P2, P3, Member, Count) JSONCONS_N_MEMBER_IS_LAST(Prefix, P2, P3, Member, Count) -#define JSONCONS_N_MEMBER_IS_LAST(Prefix, P2, P3, Member, Count) if ((num_params-Count) < num_mandatory_params1 && !ajson.contains(json_traits_macro_names::Member##_str(char_type{}))) return false; - -#define JSONCONS_N_MEMBER_AS(Prefix,P2,P3, Member, Count) JSONCONS_N_MEMBER_AS_LAST(Prefix,P2,P3, Member, Count) -#define JSONCONS_N_MEMBER_AS_LAST(Prefix,P2,P3, Member, Count) \ - if ((num_params-Count) < num_mandatory_params2 || ajson.contains(json_traits_macro_names::Member##_str(char_type{}))) \ - {json_traits_helper::set_udt_member(ajson,json_traits_macro_names::Member##_str(char_type{}),class_instance.Member);} - -#define JSONCONS_ALL_MEMBER_AS(Prefix, P2,P3,Member, Count) JSONCONS_ALL_MEMBER_AS_LAST(Prefix,P2,P3, Member, Count) -#define JSONCONS_ALL_MEMBER_AS_LAST(Prefix,P2,P3, Member, Count) \ - json_traits_helper::set_udt_member(ajson,json_traits_macro_names::Member##_str(char_type{}),class_instance.Member); - -#define JSONCONS_TO_JSON(Prefix, P2, P3, Member, Count) JSONCONS_TO_JSON_LAST(Prefix, P2, P3, Member, Count) -#define JSONCONS_TO_JSON_LAST(Prefix, P2, P3, Member, Count) if ((num_params-Count) < num_mandatory_params2) \ - {ajson.try_emplace(json_traits_macro_names::Member##_str(char_type{}),class_instance.Member);} \ - else {json_traits_helper::set_optional_json_member(json_traits_macro_names::Member##_str(char_type{}),class_instance.Member, ajson);} - -#define JSONCONS_ALL_TO_JSON(Prefix, P2, P3, Member, Count) JSONCONS_ALL_TO_JSON_LAST(Prefix, P2, P3, Member, Count) -#define JSONCONS_ALL_TO_JSON_LAST(Prefix, P2, P3, Member, Count) \ - ajson.try_emplace(json_traits_macro_names::Member##_str(char_type{}),class_instance.Member); - -#define JSONCONS_MEMBER_TRAITS_BASE(AsT,ToJ,NumTemplateParams,ClassType,NumMandatoryParams1,NumMandatoryParams2, ...) \ -namespace jsoncons \ -{ \ - template \ - struct json_traits_macro_names \ - { \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_GENERATE_NAME_STR, ,,, __VA_ARGS__)\ - }; \ - template \ - struct json_type_traits \ - { \ - using class_type = ClassType JSONCONS_GENERATE_TPL_ARGS(JSONCONS_GENERATE_TPL_ARG, NumTemplateParams); \ - using allocator_type = typename Json::allocator_type; \ - using char_type = typename Json::char_type; \ - using string_view_type = typename Json::string_view_type; \ - constexpr static size_t num_params = JSONCONS_NARGS(__VA_ARGS__); \ - constexpr static size_t num_mandatory_params1 = NumMandatoryParams1; \ - constexpr static size_t num_mandatory_params2 = NumMandatoryParams2; \ - static bool is(const Json& ajson) noexcept \ - { \ - if (!ajson.is_object()) return false; \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_N_MEMBER_IS, ,,, __VA_ARGS__)\ - return true; \ - } \ - static class_type as(const Json& ajson) \ - { \ - if (!is(ajson)) JSONCONS_THROW(conv_error(conv_errc::conversion_failed, "Not a " # ClassType)); \ - class_type class_instance{}; \ - JSONKONS_VARIADIC_FOR_EACH(AsT, ,,, __VA_ARGS__) \ - return class_instance; \ - } \ - static Json to_json(const class_type& class_instance, allocator_type alloc=allocator_type()) \ - { \ - Json ajson(json_object_arg, semantic_tag::none, alloc); \ - JSONKONS_VARIADIC_FOR_EACH(ToJ, ,,, __VA_ARGS__) \ - return ajson; \ - } \ - }; \ -} \ - /**/ - -#define JSONCONS_N_MEMBER_TRAITS(ClassType,NumMandatoryParams,...) \ - JSONCONS_MEMBER_TRAITS_BASE(JSONCONS_N_MEMBER_AS, JSONCONS_TO_JSON,0, ClassType,NumMandatoryParams,NumMandatoryParams, __VA_ARGS__) \ - namespace jsoncons { template <> struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_TPL_N_MEMBER_TRAITS(NumTemplateParams, ClassType,NumMandatoryParams, ...) \ - JSONCONS_MEMBER_TRAITS_BASE(JSONCONS_N_MEMBER_AS, JSONCONS_TO_JSON,NumTemplateParams, ClassType,NumMandatoryParams,NumMandatoryParams, __VA_ARGS__) \ - namespace jsoncons { template struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_ALL_MEMBER_TRAITS(ClassType, ...) \ - JSONCONS_MEMBER_TRAITS_BASE(JSONCONS_ALL_MEMBER_AS,JSONCONS_ALL_TO_JSON,0,ClassType, JSONCONS_NARGS(__VA_ARGS__), JSONCONS_NARGS(__VA_ARGS__),__VA_ARGS__) \ - namespace jsoncons { template <> struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_TPL_ALL_MEMBER_TRAITS(NumTemplateParams, ClassType, ...) \ - JSONCONS_MEMBER_TRAITS_BASE(JSONCONS_ALL_MEMBER_AS,JSONCONS_ALL_TO_JSON,NumTemplateParams,ClassType, JSONCONS_NARGS(__VA_ARGS__), JSONCONS_NARGS(__VA_ARGS__),__VA_ARGS__) \ - namespace jsoncons { template struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_MEMBER_NAME_IS(P1, P2, P3, Seq, Count) JSONCONS_MEMBER_NAME_IS_LAST(P1, P2, P3, Seq, Count) -#define JSONCONS_MEMBER_NAME_IS_LAST(P1, P2, P3, Seq, Count) if ((num_params-Count) < num_mandatory_params1 && JSONCONS_EXPAND(JSONCONS_CONCAT(JSONCONS_MEMBER_NAME_IS_,JSONCONS_NARGS Seq) Seq) -#define JSONCONS_MEMBER_NAME_IS_2(Member, Name) !ajson.contains(Name)) return false; -#define JSONCONS_MEMBER_NAME_IS_3(Member, Name, Mode) JSONCONS_MEMBER_NAME_IS_2(Member, Name) -#define JSONCONS_MEMBER_NAME_IS_4(Member, Name, Mode, Match) JSONCONS_MEMBER_NAME_IS_6(Member, Name, Mode, Match, , ) -#define JSONCONS_MEMBER_NAME_IS_5(Member, Name, Mode, Match, Into) JSONCONS_MEMBER_NAME_IS_6(Member, Name, Mode, Match, Into, ) -#define JSONCONS_MEMBER_NAME_IS_6(Member, Name, Mode, Match, Into, From) !ajson.contains(Name)) return false; \ - JSONCONS_TRY{if (!Match(ajson.at(Name).template as())->Member))>::type>())) return false;} \ - JSONCONS_CATCH(...) {return false;} - -#define JSONCONS_N_MEMBER_NAME_AS(P1, P2, P3, Seq, Count) JSONCONS_N_MEMBER_NAME_AS_LAST(P1, P2, P3, Seq, Count) -#define JSONCONS_N_MEMBER_NAME_AS_LAST(P1, P2, P3, Seq, Count) JSONCONS_EXPAND(JSONCONS_CONCAT(JSONCONS_N_MEMBER_NAME_AS_,JSONCONS_NARGS Seq) Seq) -#define JSONCONS_N_MEMBER_NAME_AS_2(Member, Name) \ - if (ajson.contains(Name)) {json_traits_helper::set_udt_member(ajson,Name,class_instance.Member);} -#define JSONCONS_N_MEMBER_NAME_AS_3(Member, Name, Mode) Mode(JSONCONS_N_MEMBER_NAME_AS_2(Member, Name)) -#define JSONCONS_N_MEMBER_NAME_AS_4(Member, Name, Mode, Match) \ - Mode(if (ajson.contains(Name)) {json_traits_helper::set_udt_member(ajson,Name,class_instance.Member);}) -#define JSONCONS_N_MEMBER_NAME_AS_5(Member, Name, Mode, Match, Into) \ - Mode(if (ajson.contains(Name)) {json_traits_helper::template set_udt_member())->Member))>::type>(ajson,Name,class_instance.Member);}) -#define JSONCONS_N_MEMBER_NAME_AS_6(Member, Name, Mode, Match, Into, From) \ - Mode(if (ajson.contains(Name)) {json_traits_helper::template set_udt_member())->Member))>::type>(ajson,Name,From,class_instance.Member);}) - -#define JSONCONS_ALL_MEMBER_NAME_AS(P1, P2, P3, Seq, Count) JSONCONS_ALL_MEMBER_NAME_AS_LAST(P1, P2, P3, Seq, Count) -#define JSONCONS_ALL_MEMBER_NAME_AS_LAST(P1, P2, P3, Seq, Count) JSONCONS_EXPAND(JSONCONS_CONCAT(JSONCONS_ALL_MEMBER_NAME_AS_,JSONCONS_NARGS Seq) Seq) -#define JSONCONS_ALL_MEMBER_NAME_AS_2(Member, Name) \ - json_traits_helper::set_udt_member(ajson,Name,class_instance.Member); -#define JSONCONS_ALL_MEMBER_NAME_AS_3(Member, Name, Mode) Mode(JSONCONS_ALL_MEMBER_NAME_AS_2(Member, Name)) -#define JSONCONS_ALL_MEMBER_NAME_AS_4(Member, Name, Mode, Match) \ - Mode(json_traits_helper::set_udt_member(ajson,Name,class_instance.Member);) -#define JSONCONS_ALL_MEMBER_NAME_AS_5(Member, Name, Mode, Match, Into) \ - Mode(json_traits_helper::template set_udt_member())->Member))>::type>(ajson,Name,class_instance.Member);) -#define JSONCONS_ALL_MEMBER_NAME_AS_6(Member, Name, Mode, Match, Into, From) \ - Mode(json_traits_helper::template set_udt_member())->Member))>::type>(ajson,Name,From,class_instance.Member);) - -#define JSONCONS_N_MEMBER_NAME_TO_JSON(P1, P2, P3, Seq, Count) JSONCONS_N_MEMBER_NAME_TO_JSON_LAST(P1, P2, P3, Seq, Count) -#define JSONCONS_N_MEMBER_NAME_TO_JSON_LAST(P1, P2, P3, Seq, Count) if ((num_params-Count) < num_mandatory_params2) JSONCONS_EXPAND(JSONCONS_CONCAT(JSONCONS_N_MEMBER_NAME_TO_JSON_,JSONCONS_NARGS Seq) Seq) -#define JSONCONS_N_MEMBER_NAME_TO_JSON_2(Member, Name) \ - {ajson.try_emplace(Name,class_instance.Member);} \ -else \ - {json_traits_helper::set_optional_json_member(Name,class_instance.Member, ajson);} -#define JSONCONS_N_MEMBER_NAME_TO_JSON_3(Member, Name, Mode) JSONCONS_N_MEMBER_NAME_TO_JSON_2(Member, Name) -#define JSONCONS_N_MEMBER_NAME_TO_JSON_4(Member, Name, Mode, Match) JSONCONS_N_MEMBER_NAME_TO_JSON_6(Member, Name, Mode, Match,,) -#define JSONCONS_N_MEMBER_NAME_TO_JSON_5(Member, Name, Mode, Match, Into) JSONCONS_N_MEMBER_NAME_TO_JSON_6(Member, Name, Mode, Match, Into, ) -#define JSONCONS_N_MEMBER_NAME_TO_JSON_6(Member, Name, Mode, Match, Into, From) \ - {ajson.try_emplace(Name, Into(class_instance.Member));} \ -else \ - {json_traits_helper::set_optional_json_member(Name, Into(class_instance.Member), ajson);} - -#define JSONCONS_ALL_MEMBER_NAME_TO_JSON(P1, P2, P3, Seq, Count) JSONCONS_ALL_MEMBER_NAME_TO_JSON_LAST(P1, P2, P3, Seq, Count) -#define JSONCONS_ALL_MEMBER_NAME_TO_JSON_LAST(P1, P2, P3, Seq, Count) JSONCONS_EXPAND(JSONCONS_CONCAT(JSONCONS_ALL_MEMBER_NAME_TO_JSON_,JSONCONS_NARGS Seq) Seq) -#define JSONCONS_ALL_MEMBER_NAME_TO_JSON_2(Member, Name) ajson.try_emplace(Name,class_instance.Member); -#define JSONCONS_ALL_MEMBER_NAME_TO_JSON_3(Member, Name, Mode) JSONCONS_ALL_MEMBER_NAME_TO_JSON_2(Member, Name) -#define JSONCONS_ALL_MEMBER_NAME_TO_JSON_4(Member, Name, Mode, Match) JSONCONS_ALL_MEMBER_NAME_TO_JSON_6(Member, Name, Mode, Match,,) -#define JSONCONS_ALL_MEMBER_NAME_TO_JSON_5(Member, Name, Mode, Match, Into) JSONCONS_ALL_MEMBER_NAME_TO_JSON_6(Member, Name, Mode, Match, Into, ) -#define JSONCONS_ALL_MEMBER_NAME_TO_JSON_6(Member, Name, Mode, Match, Into, From) ajson.try_emplace(Name, Into(class_instance.Member)); - -#define JSONCONS_MEMBER_NAME_TRAITS_BASE(AsT,ToJ, NumTemplateParams, ClassType,NumMandatoryParams1,NumMandatoryParams2, ...) \ -namespace jsoncons \ -{ \ - template \ - struct json_type_traits \ - { \ - using class_type = ClassType JSONCONS_GENERATE_TPL_ARGS(JSONCONS_GENERATE_TPL_ARG, NumTemplateParams); \ - using allocator_type = typename Json::allocator_type; \ - using char_type = typename Json::char_type; \ - using string_view_type = typename Json::string_view_type; \ - constexpr static size_t num_params = JSONCONS_NARGS(__VA_ARGS__); \ - constexpr static size_t num_mandatory_params1 = NumMandatoryParams1; \ - constexpr static size_t num_mandatory_params2 = NumMandatoryParams2; \ - static bool is(const Json& ajson) noexcept \ - { \ - if (!ajson.is_object()) return false; \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_MEMBER_NAME_IS,,,, __VA_ARGS__)\ - return true; \ - } \ - static class_type as(const Json& ajson) \ - { \ - if (!is(ajson)) JSONCONS_THROW(conv_error(conv_errc::conversion_failed, "Not a " # ClassType)); \ - class_type class_instance{}; \ - JSONKONS_VARIADIC_FOR_EACH(AsT,,,, __VA_ARGS__) \ - return class_instance; \ - } \ - static Json to_json(const class_type& class_instance, allocator_type alloc=allocator_type()) \ - { \ - Json ajson(json_object_arg, semantic_tag::none, alloc); \ - JSONKONS_VARIADIC_FOR_EACH(ToJ,,,, __VA_ARGS__) \ - return ajson; \ - } \ - }; \ -} \ - /**/ - - -#define JSONCONS_N_MEMBER_NAME_TRAITS(ClassType,NumMandatoryParams, ...) \ - JSONCONS_MEMBER_NAME_TRAITS_BASE(JSONCONS_N_MEMBER_NAME_AS, JSONCONS_N_MEMBER_NAME_TO_JSON, 0, ClassType,NumMandatoryParams,NumMandatoryParams, __VA_ARGS__) \ - namespace jsoncons { template <> struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_TPL_N_MEMBER_NAME_TRAITS(NumTemplateParams, ClassType,NumMandatoryParams, ...) \ - JSONCONS_MEMBER_NAME_TRAITS_BASE(JSONCONS_N_MEMBER_NAME_AS, JSONCONS_N_MEMBER_NAME_TO_JSON, NumTemplateParams, ClassType,NumMandatoryParams,NumMandatoryParams, __VA_ARGS__) \ - namespace jsoncons { template struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_ALL_MEMBER_NAME_TRAITS(ClassType, ...) \ - JSONCONS_MEMBER_NAME_TRAITS_BASE(JSONCONS_ALL_MEMBER_NAME_AS, JSONCONS_ALL_MEMBER_NAME_TO_JSON, 0, ClassType, JSONCONS_NARGS(__VA_ARGS__), JSONCONS_NARGS(__VA_ARGS__), __VA_ARGS__) \ - namespace jsoncons { template <> struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_TPL_ALL_MEMBER_NAME_TRAITS(NumTemplateParams, ClassType, ...) \ - JSONCONS_MEMBER_NAME_TRAITS_BASE(JSONCONS_ALL_MEMBER_NAME_AS, JSONCONS_ALL_MEMBER_NAME_TO_JSON, NumTemplateParams, ClassType, JSONCONS_NARGS(__VA_ARGS__), JSONCONS_NARGS(__VA_ARGS__), __VA_ARGS__) \ - namespace jsoncons { template struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_CTOR_GETTER_IS(Prefix, P2, P3, Getter, Count) JSONCONS_CTOR_GETTER_IS_LAST(Prefix, P2, P3, Getter, Count) -#define JSONCONS_CTOR_GETTER_IS_LAST(Prefix, P2, P3, Getter, Count) if ((num_params-Count) < num_mandatory_params1 && !ajson.contains(json_traits_macro_names::Getter##_str(char_type{}))) return false; - -#define JSONCONS_CTOR_GETTER_AS(Prefix, P2, P3, Getter, Count) JSONCONS_CTOR_GETTER_AS_LAST(Prefix, P2, P3, Getter, Count), -#define JSONCONS_CTOR_GETTER_AS_LAST(Prefix, P2, P3, Getter, Count) ((num_params-Count) < num_mandatory_params2) ? (ajson.at(json_traits_macro_names::Getter##_str(char_type{}))).template as())->Getter())>::type>() : (ajson.contains(json_traits_macro_names::Getter##_str(char_type{})) ? (ajson.at(json_traits_macro_names::Getter##_str(char_type{}))).template as())->Getter())>::type>() : typename std::decay())->Getter())>::type()) - -#define JSONCONS_CTOR_GETTER_TO_JSON(Prefix, P2, P3, Getter, Count) JSONCONS_CTOR_GETTER_TO_JSON_LAST(Prefix, P2, P3, Getter, Count) - -#define JSONCONS_CTOR_GETTER_TO_JSON_LAST(Prefix, P2, P3, Getter, Count) \ -if ((num_params-Count) < num_mandatory_params2) { \ - ajson.try_emplace(json_traits_macro_names::Getter##_str(char_type{}),class_instance.Getter() ); \ - } \ -else { \ - json_traits_helper::set_optional_json_member(json_traits_macro_names::Getter##_str(char_type{}),class_instance.Getter(), ajson); \ -} - -#define JSONCONS_CTOR_GETTER_TRAITS_BASE(NumTemplateParams, ClassType,NumMandatoryParams1,NumMandatoryParams2, ...) \ -namespace jsoncons \ -{ \ - template \ - struct json_traits_macro_names \ - { \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_GENERATE_NAME_STR, ,,, __VA_ARGS__)\ - }; \ - template \ - struct json_type_traits \ - { \ - using class_type = ClassType JSONCONS_GENERATE_TPL_ARGS(JSONCONS_GENERATE_TPL_ARG, NumTemplateParams); \ - using allocator_type = typename Json::allocator_type; \ - using char_type = typename Json::char_type; \ - using string_view_type = typename Json::string_view_type; \ - constexpr static size_t num_params = JSONCONS_NARGS(__VA_ARGS__); \ - constexpr static size_t num_mandatory_params1 = NumMandatoryParams1; \ - constexpr static size_t num_mandatory_params2 = NumMandatoryParams2; \ - static bool is(const Json& ajson) noexcept \ - { \ - if (!ajson.is_object()) return false; \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_CTOR_GETTER_IS, ,,, __VA_ARGS__)\ - return true; \ - } \ - static class_type as(const Json& ajson) \ - { \ - if (!is(ajson)) JSONCONS_THROW(conv_error(conv_errc::conversion_failed, "Not a " # ClassType)); \ - return class_type ( JSONKONS_VARIADIC_FOR_EACH(JSONCONS_CTOR_GETTER_AS, ,,, __VA_ARGS__) ); \ - } \ - static Json to_json(const class_type& class_instance, allocator_type alloc=allocator_type()) \ - { \ - Json ajson(json_object_arg, semantic_tag::none, alloc); \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_CTOR_GETTER_TO_JSON, ,,, __VA_ARGS__) \ - return ajson; \ - } \ - }; \ -} \ - /**/ - -#define JSONCONS_ALL_CTOR_GETTER_TRAITS(ClassType, ...) \ - JSONCONS_CTOR_GETTER_TRAITS_BASE(0, ClassType, JSONCONS_NARGS(__VA_ARGS__), JSONCONS_NARGS(__VA_ARGS__), __VA_ARGS__) \ - namespace jsoncons { template <> struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_TPL_ALL_CTOR_GETTER_TRAITS(NumTemplateParams, ClassType, ...) \ - JSONCONS_CTOR_GETTER_TRAITS_BASE(NumTemplateParams, ClassType, JSONCONS_NARGS(__VA_ARGS__), JSONCONS_NARGS(__VA_ARGS__), __VA_ARGS__) \ - namespace jsoncons { template struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_N_CTOR_GETTER_TRAITS(ClassType,NumMandatoryParams, ...) \ - JSONCONS_CTOR_GETTER_TRAITS_BASE(0, ClassType,NumMandatoryParams,NumMandatoryParams, __VA_ARGS__) \ - namespace jsoncons { template <> struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_N_ALL_CTOR_GETTER_TRAITS(NumTemplateParams, ClassType,NumMandatoryParams, ...) \ - JSONCONS_CTOR_GETTER_TRAITS_BASE(NumTemplateParams, ClassType,NumMandatoryParams,NumMandatoryParams, __VA_ARGS__) \ - namespace jsoncons { template <> struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_CTOR_GETTER_NAME_IS(P1, P2, P3, Seq, Count) JSONCONS_CTOR_GETTER_NAME_IS_LAST(P1, P2, P3, Seq, Count) -#define JSONCONS_CTOR_GETTER_NAME_IS_LAST(P1, P2, P3, Seq, Count) if ((num_params-Count) < num_mandatory_params1 && JSONCONS_EXPAND(JSONCONS_CONCAT(JSONCONS_CTOR_GETTER_NAME_IS_,JSONCONS_NARGS Seq) Seq) -#define JSONCONS_CTOR_GETTER_NAME_IS_2(Getter, Name) !ajson.contains(Name)) return false; -#define JSONCONS_CTOR_GETTER_NAME_IS_3(Getter, Name, Mode) JSONCONS_CTOR_GETTER_NAME_IS_2(Getter, Name) -#define JSONCONS_CTOR_GETTER_NAME_IS_4(Getter, Name, Mode, Match) JSONCONS_CTOR_GETTER_NAME_IS_6(Getter, Name, Mode, Match, , ) -#define JSONCONS_CTOR_GETTER_NAME_IS_5(Getter, Name, Mode, Match, Into) JSONCONS_CTOR_GETTER_NAME_IS_6(Getter, Name, Mode, Match, Into, ) -#define JSONCONS_CTOR_GETTER_NAME_IS_6(Getter, Name, Mode, Match, Into, From) !ajson.contains(Name)) return false; \ - JSONCONS_TRY{if (!Match(ajson.at(Name).template as())->Getter()))>::type>())) return false;} \ - JSONCONS_CATCH(...) {return false;} - -#define JSONCONS_CTOR_GETTER_NAME_AS(P1, P2, P3, Seq, Count) JSONCONS_EXPAND(JSONCONS_CONCAT(JSONCONS_CTOR_GETTER_NAME_AS_,JSONCONS_NARGS Seq) Seq) -#define JSONCONS_CTOR_GETTER_NAME_AS_2(Getter, Name) JSONCONS_CTOR_GETTER_NAME_AS_LAST_2(Getter, Name) JSONCONS_COMMA -#define JSONCONS_CTOR_GETTER_NAME_AS_3(Getter, Name, Mode) Mode(JSONCONS_CTOR_GETTER_NAME_AS_LAST_2(Getter, Name)) Mode(JSONCONS_COMMA) -#define JSONCONS_CTOR_GETTER_NAME_AS_4(Getter, Name, Mode, Match) JSONCONS_CTOR_GETTER_NAME_AS_6(Getter, Name, Mode, Match,,) -#define JSONCONS_CTOR_GETTER_NAME_AS_5(Getter, Name, Mode, Match, Into) JSONCONS_CTOR_GETTER_NAME_AS_6(Getter, Name, Mode, Match, Into, ) -#define JSONCONS_CTOR_GETTER_NAME_AS_6(Getter, Name, Mode, Match, Into, From) JSONCONS_CTOR_GETTER_NAME_AS_LAST_6(Getter,Name,Mode,Match,Into,From) Mode(JSONCONS_COMMA) -#define JSONCONS_COMMA , - -#define JSONCONS_CTOR_GETTER_NAME_AS_LAST(P1, P2, P3, Seq, Count) JSONCONS_EXPAND(JSONCONS_CONCAT(JSONCONS_CTOR_GETTER_NAME_AS_LAST_,JSONCONS_NARGS Seq) Seq) -#define JSONCONS_CTOR_GETTER_NAME_AS_LAST_2(Getter, Name) (ajson.contains(Name)) ? (ajson.at(Name)).template as())->Getter())>::type>() : typename std::decay())->Getter())>::type() -#define JSONCONS_CTOR_GETTER_NAME_AS_LAST_3(Getter, Name, Mode) Mode(JSONCONS_CTOR_GETTER_NAME_AS_LAST_2(Getter, Name)) -#define JSONCONS_CTOR_GETTER_NAME_AS_LAST_4(Getter, Name, Mode, Match) JSONCONS_CTOR_GETTER_NAME_AS_LAST_6(Getter, Name, Mode, Match,,) -#define JSONCONS_CTOR_GETTER_NAME_AS_LAST_5(Getter, Name, Mode, Match, Into) JSONCONS_CTOR_GETTER_NAME_AS_LAST_6(Getter, Name, Mode, Match, Into, ) -#define JSONCONS_CTOR_GETTER_NAME_AS_LAST_6(Getter, Name, Mode, Match, Into, From) Mode(ajson.contains(Name) ? From(ajson.at(Name).template as())->Getter()))>::type>()) : From(typename std::decay())->Getter()))>::type())) - -#define JSONCONS_CTOR_GETTER_NAME_TO_JSON(P1, P2, P3, Seq, Count) JSONCONS_CTOR_GETTER_NAME_TO_JSON_LAST(P1, P2, P3, Seq, Count) -#define JSONCONS_CTOR_GETTER_NAME_TO_JSON_LAST(P1, P2, P3, Seq, Count) if ((num_params-Count) < num_mandatory_params2) JSONCONS_EXPAND(JSONCONS_CONCAT(JSONCONS_CTOR_GETTER_NAME_TO_JSON_,JSONCONS_NARGS Seq) Seq) -#define JSONCONS_CTOR_GETTER_NAME_TO_JSON_2(Getter, Name) \ -{ \ - ajson.try_emplace(Name,class_instance.Getter() ); \ -} \ -else { \ - json_traits_helper::set_optional_json_member(Name,class_instance.Getter(), ajson); \ -} -#define JSONCONS_CTOR_GETTER_NAME_TO_JSON_3(Getter, Name, Mode) JSONCONS_CTOR_GETTER_NAME_TO_JSON_2(Getter, Name) -#define JSONCONS_CTOR_GETTER_NAME_TO_JSON_4(Getter, Name, Mode, Match) JSONCONS_CTOR_GETTER_NAME_TO_JSON_2(Getter, Name) -#define JSONCONS_CTOR_GETTER_NAME_TO_JSON_5(Getter, Name, Mode, Match, Into) JSONCONS_CTOR_GETTER_NAME_TO_JSON_6(Getter, Name, Mode, Match, Into, ) -#define JSONCONS_CTOR_GETTER_NAME_TO_JSON_6(Getter, Name, Mode, Match, Into, From) \ -{ \ - ajson.try_emplace(Name, Into(class_instance.Getter()) ); \ -} \ -else { \ - json_traits_helper::set_optional_json_member(Name, Into(class_instance.Getter()), ajson); \ -} - -#define JSONCONS_CTOR_GETTER_NAME_TRAITS_BASE(NumTemplateParams, ClassType,NumMandatoryParams1,NumMandatoryParams2, ...) \ -namespace jsoncons \ -{ \ - template \ - struct json_type_traits \ - { \ - using class_type = ClassType JSONCONS_GENERATE_TPL_ARGS(JSONCONS_GENERATE_TPL_ARG, NumTemplateParams); \ - using allocator_type = typename Json::allocator_type; \ - using char_type = typename Json::char_type; \ - using string_view_type = typename Json::string_view_type; \ - constexpr static size_t num_params = JSONCONS_NARGS(__VA_ARGS__); \ - constexpr static size_t num_mandatory_params1 = NumMandatoryParams1; \ - constexpr static size_t num_mandatory_params2 = NumMandatoryParams2; \ - static bool is(const Json& ajson) noexcept \ - { \ - if (!ajson.is_object()) return false; \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_CTOR_GETTER_NAME_IS,,,, __VA_ARGS__)\ - return true; \ - } \ - static class_type as(const Json& ajson) \ - { \ - if (!is(ajson)) JSONCONS_THROW(conv_error(conv_errc::conversion_failed, "Not a " # ClassType)); \ - return class_type ( JSONKONS_VARIADIC_FOR_EACH(JSONCONS_CTOR_GETTER_NAME_AS,,,, __VA_ARGS__) ); \ - } \ - static Json to_json(const class_type& class_instance, allocator_type alloc=allocator_type()) \ - { \ - Json ajson(json_object_arg, semantic_tag::none, alloc); \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_CTOR_GETTER_NAME_TO_JSON,,,, __VA_ARGS__) \ - return ajson; \ - } \ - }; \ -} \ - /**/ - -#define JSONCONS_ALL_CTOR_GETTER_NAME_TRAITS(ClassType, ...) \ - JSONCONS_CTOR_GETTER_NAME_TRAITS_BASE(0, ClassType, JSONCONS_NARGS(__VA_ARGS__), JSONCONS_NARGS(__VA_ARGS__), __VA_ARGS__) \ - namespace jsoncons { template <> struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_TPL_ALL_CTOR_GETTER_NAME_TRAITS(NumTemplateParams, ClassType, ...) \ - JSONCONS_CTOR_GETTER_NAME_TRAITS_BASE(NumTemplateParams, ClassType, JSONCONS_NARGS(__VA_ARGS__), JSONCONS_NARGS(__VA_ARGS__), __VA_ARGS__) \ - namespace jsoncons { template struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_N_CTOR_GETTER_NAME_TRAITS(ClassType,NumMandatoryParams, ...) \ - JSONCONS_CTOR_GETTER_NAME_TRAITS_BASE(0, ClassType,NumMandatoryParams,NumMandatoryParams, __VA_ARGS__) \ - namespace jsoncons { template <> struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_TPL_N_CTOR_GETTER_NAME_TRAITS(NumTemplateParams, ClassType,NumMandatoryParams, ...) \ -JSONCONS_CTOR_GETTER_NAME_TRAITS_BASE(NumTemplateParams, ClassType,NumMandatoryParams,NumMandatoryParams, __VA_ARGS__) \ - namespace jsoncons { template struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_ENUM_PAIR(Prefix, P2, P3, Member, Count) JSONCONS_ENUM_PAIR_LAST(Prefix, P2, P3, Member, Count), -#define JSONCONS_ENUM_PAIR_LAST(Prefix, P2, P3, Member, Count) {enum_type::Member, json_traits_macro_names::Member##_str(char_type{})} - -#define JSONCONS_ENUM_TRAITS_BASE(EnumType, ...) \ -namespace jsoncons \ -{ \ - template \ - struct json_traits_macro_names \ - { \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_GENERATE_NAME_STR, ,,, __VA_ARGS__)\ - }; \ - template \ - struct json_type_traits \ - { \ - static_assert(std::is_enum::value, # EnumType " must be an enum"); \ - using enum_type = EnumType; \ - using char_type = typename Json::char_type; \ - using string_type = std::basic_string; \ - using string_view_type = jsoncons::basic_string_view; \ - using allocator_type = typename Json::allocator_type; \ - using mapped_type = std::pair; \ - \ - static std::pair get_values() \ - { \ - static const mapped_type v[] = { \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_ENUM_PAIR, ,,, __VA_ARGS__)\ - };\ - return std::make_pair(v,v+JSONCONS_NARGS(__VA_ARGS__)); \ - } \ - \ - static bool is(const Json& ajson) noexcept \ - { \ - if (!ajson.is_string()) return false; \ - auto first = get_values().first; \ - auto last = get_values().second; \ - const string_view_type s = ajson.template as(); \ - if (s.empty() && std::find_if(first, last, \ - [](const mapped_type& item) -> bool \ - { return item.first == enum_type(); }) == last) \ - { \ - return true; \ - } \ - auto it = std::find_if(first, last, \ - [&](const mapped_type& item) -> bool \ - { return item.second == s; }); \ - return it != last; \ - } \ - static enum_type as(const Json& ajson) \ - { \ - if (!is(ajson)) JSONCONS_THROW(conv_error(conv_errc::conversion_failed, "Not a " # EnumType)); \ - const string_view_type s = ajson.template as(); \ - auto first = get_values().first; \ - auto last = get_values().second; \ - if (s.empty() && std::find_if(first, last, \ - [](const mapped_type& item) -> bool \ - { return item.first == enum_type(); }) == last) \ - { \ - return enum_type(); \ - } \ - auto it = std::find_if(first, last, \ - [&](const mapped_type& item) -> bool \ - { return item.second == s; }); \ - if (it == last) \ - { \ - if (s.empty()) \ - { \ - return enum_type(); \ - } \ - else \ - { \ - JSONCONS_THROW(conv_error(conv_errc::conversion_failed, "Not an enum")); \ - } \ - } \ - return (*it).first; \ - } \ - static Json to_json(enum_type class_instance, allocator_type alloc=allocator_type()) \ - { \ - static constexpr char_type empty_string[] = {0}; \ - auto first = get_values().first; \ - auto last = get_values().second; \ - auto it = std::find_if(first, last, \ - [class_instance](const mapped_type& item) -> bool \ - { return item.first == class_instance; }); \ - if (it == last) \ - { \ - if (class_instance == enum_type()) \ - { \ - return Json(empty_string); \ - } \ - else \ - { \ - JSONCONS_THROW(conv_error(conv_errc::conversion_failed, "Not an enum")); \ - } \ - } \ - return Json((*it).second,alloc); \ - } \ - }; \ -} \ - /**/ - -#define JSONCONS_ENUM_TRAITS(EnumType, ...) \ - JSONCONS_ENUM_TRAITS_BASE(EnumType,__VA_ARGS__) \ - namespace jsoncons { template <> struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_NAME_ENUM_PAIR(P1, P2, P3, Seq, Count) JSONCONS_EXPAND(JSONCONS_NAME_ENUM_PAIR_ Seq), -#define JSONCONS_NAME_ENUM_PAIR_LAST(P1, P2, P3, Seq, Count) JSONCONS_EXPAND(JSONCONS_NAME_ENUM_PAIR_ Seq) -#define JSONCONS_NAME_ENUM_PAIR_(Member, Name) {enum_type::Member, Name} - -#define JSONCONS_ENUM_NAME_TRAITS(EnumType, ...) \ -namespace jsoncons \ -{ \ - template \ - struct json_type_traits \ - { \ - static_assert(std::is_enum::value, # EnumType " must be an enum"); \ - using enum_type = EnumType; \ - using char_type = typename Json::char_type; \ - using string_type = std::basic_string; \ - using string_view_type = jsoncons::basic_string_view; \ - using allocator_type = typename Json::allocator_type; \ - using mapped_type = std::pair; \ - \ - static std::pair get_values() \ - { \ - static const mapped_type v[] = { \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_NAME_ENUM_PAIR,,,, __VA_ARGS__)\ - };\ - return std::make_pair(v,v+JSONCONS_NARGS(__VA_ARGS__)); \ - } \ - \ - static bool is(const Json& ajson) noexcept \ - { \ - if (!ajson.is_string()) return false; \ - auto first = get_values().first; \ - auto last = get_values().second; \ - const string_view_type s = ajson.template as(); \ - if (s.empty() && std::find_if(first, last, \ - [](const mapped_type& item) -> bool \ - { return item.first == enum_type(); }) == last) \ - { \ - return true; \ - } \ - auto it = std::find_if(first, last, \ - [&](const mapped_type& item) -> bool \ - { return item.second == s; }); \ - return it != last; \ - } \ - static enum_type as(const Json& ajson) \ - { \ - if (!is(ajson)) JSONCONS_THROW(conv_error(conv_errc::conversion_failed, "Not a " # EnumType)); \ - const string_view_type s = ajson.template as(); \ - auto first = get_values().first; \ - auto last = get_values().second; \ - if (s.empty() && std::find_if(first, last, \ - [](const mapped_type& item) -> bool \ - { return item.first == enum_type(); }) == last) \ - { \ - return enum_type(); \ - } \ - auto it = std::find_if(first, last, \ - [&](const mapped_type& item) -> bool \ - { return item.second == s; }); \ - if (it == last) \ - { \ - if (s.empty()) \ - { \ - return enum_type(); \ - } \ - else \ - { \ - JSONCONS_THROW(conv_error(conv_errc::conversion_failed, "Not an enum")); \ - } \ - } \ - return (*it).first; \ - } \ - static Json to_json(enum_type class_instance, allocator_type alloc=allocator_type()) \ - { \ - static constexpr char_type empty_string[] = {0}; \ - auto first = get_values().first; \ - auto last = get_values().second; \ - auto it = std::find_if(first, last, \ - [class_instance](const mapped_type& item) -> bool \ - { return item.first == class_instance; }); \ - if (it == last) \ - { \ - if (class_instance == enum_type()) \ - { \ - return Json(empty_string); \ - } \ - else \ - { \ - JSONCONS_THROW(conv_error(conv_errc::conversion_failed, "Not an enum")); \ - } \ - } \ - return Json((*it).second,alloc); \ - } \ - }; \ - template <> struct is_json_type_traits_declared : public std::true_type {}; \ -} \ - /**/ - -#define JSONCONS_GETTER_SETTER_AS(Prefix, GetPrefix, SetPrefix, Property, Count) JSONCONS_GETTER_SETTER_AS_(Prefix, GetPrefix ## Property, SetPrefix ## Property, Property, Count) -#define JSONCONS_GETTER_SETTER_AS_LAST(Prefix, GetPrefix, SetPrefix, Property, Count) JSONCONS_GETTER_SETTER_AS_(Prefix, GetPrefix ## Property, SetPrefix ## Property, Property, Count) -#define JSONCONS_GETTER_SETTER_AS_(Prefix, Getter, Setter, Property, Count) if ((num_params-Count) < num_mandatory_params2 || ajson.contains(json_traits_macro_names::Property##_str(char_type{}))) {class_instance.Setter(ajson.at(json_traits_macro_names::Property##_str(char_type{})).template as::type>());} - -#define JSONCONS_ALL_GETTER_SETTER_AS(Prefix, GetPrefix, SetPrefix, Property, Count) JSONCONS_ALL_GETTER_SETTER_AS_(Prefix, GetPrefix ## Property, SetPrefix ## Property, Property, Count) -#define JSONCONS_ALL_GETTER_SETTER_AS_LAST(Prefix, GetPrefix, SetPrefix, Property, Count) JSONCONS_ALL_GETTER_SETTER_AS_(Prefix, GetPrefix ## Property, SetPrefix ## Property, Property, Count) -#define JSONCONS_ALL_GETTER_SETTER_AS_(Prefix, Getter, Setter, Property, Count) class_instance.Setter(ajson.at(json_traits_macro_names::Property##_str(char_type{})).template as::type>()); - -#define JSONCONS_GETTER_SETTER_TO_JSON(Prefix, GetPrefix, SetPrefix, Property, Count) JSONCONS_GETTER_SETTER_TO_JSON_(Prefix, GetPrefix ## Property, SetPrefix ## Property, Property, Count) -#define JSONCONS_GETTER_SETTER_TO_JSON_LAST(Prefix, GetPrefix, SetPrefix, Property, Count) JSONCONS_GETTER_SETTER_TO_JSON_(Prefix, GetPrefix ## Property, SetPrefix ## Property, Property, Count) -#define JSONCONS_GETTER_SETTER_TO_JSON_(Prefix, Getter, Setter, Property, Count) \ -if ((num_params-Count) < num_mandatory_params2) \ - {ajson.try_emplace(json_traits_macro_names::Property##_str(char_type{}),class_instance.Getter());} \ -else \ - {json_traits_helper::set_optional_json_member(json_traits_macro_names::Property##_str(char_type{}),class_instance.Getter(), ajson);} - -#define JSONCONS_ALL_GETTER_SETTER_TO_JSON(Prefix, GetPrefix, SetPrefix, Property, Count) JSONCONS_ALL_GETTER_SETTER_TO_JSON_(Prefix, GetPrefix ## Property, SetPrefix ## Property, Property, Count) -#define JSONCONS_ALL_GETTER_SETTER_TO_JSON_LAST(Prefix, GetPrefix, SetPrefix, Property, Count) JSONCONS_ALL_GETTER_SETTER_TO_JSON_(Prefix, GetPrefix ## Property, SetPrefix ## Property, Property, Count) -#define JSONCONS_ALL_GETTER_SETTER_TO_JSON_(Prefix, Getter, Setter, Property, Count) ajson.try_emplace(json_traits_macro_names::Property##_str(char_type{}),class_instance.Getter() ); - -#define JSONCONS_GETTER_SETTER_TRAITS_BASE(AsT,ToJ,NumTemplateParams, ClassType,GetPrefix,SetPrefix,NumMandatoryParams1,NumMandatoryParams2, ...) \ -namespace jsoncons \ -{ \ - template \ - struct json_traits_macro_names \ - { \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_GENERATE_NAME_STR, ,,, __VA_ARGS__)\ - }; \ - template \ - struct json_type_traits \ - { \ - using class_type = ClassType JSONCONS_GENERATE_TPL_ARGS(JSONCONS_GENERATE_TPL_ARG, NumTemplateParams); \ - using allocator_type = typename Json::allocator_type; \ - using char_type = typename Json::char_type; \ - using string_view_type = typename Json::string_view_type; \ - constexpr static size_t num_params = JSONCONS_NARGS(__VA_ARGS__); \ - constexpr static size_t num_mandatory_params1 = NumMandatoryParams1; \ - constexpr static size_t num_mandatory_params2 = NumMandatoryParams2; \ - static bool is(const Json& ajson) noexcept \ - { \ - if (!ajson.is_object()) return false; \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_N_MEMBER_IS, ,GetPrefix,SetPrefix, __VA_ARGS__)\ - return true; \ - } \ - static class_type as(const Json& ajson) \ - { \ - if (!is(ajson)) JSONCONS_THROW(conv_error(conv_errc::conversion_failed, "Not a " # ClassType)); \ - class_type class_instance{}; \ - JSONKONS_VARIADIC_FOR_EACH(AsT, ,GetPrefix,SetPrefix, __VA_ARGS__) \ - return class_instance; \ - } \ - static Json to_json(const class_type& class_instance, allocator_type alloc=allocator_type()) \ - { \ - Json ajson(json_object_arg, semantic_tag::none, alloc); \ - JSONKONS_VARIADIC_FOR_EACH(ToJ, ,GetPrefix,SetPrefix, __VA_ARGS__) \ - return ajson; \ - } \ - }; \ -} \ - /**/ - -#define JSONCONS_N_GETTER_SETTER_TRAITS(ClassType,GetPrefix,SetPrefix,NumMandatoryParams, ...) \ - JSONCONS_GETTER_SETTER_TRAITS_BASE(JSONCONS_GETTER_SETTER_AS, JSONCONS_GETTER_SETTER_TO_JSON,0, ClassType,GetPrefix,SetPrefix,NumMandatoryParams,NumMandatoryParams, __VA_ARGS__) \ - namespace jsoncons { template <> struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_TPL_N_GETTER_SETTER_TRAITS(NumTemplateParams, ClassType,GetPrefix,SetPrefix,NumMandatoryParams, ...) \ - JSONCONS_GETTER_SETTER_TRAITS_BASE(JSONCONS_GETTER_SETTER_AS, JSONCONS_GETTER_SETTER_TO_JSON,NumTemplateParams, ClassType,GetPrefix,SetPrefix,NumMandatoryParams,NumMandatoryParams, __VA_ARGS__) \ - namespace jsoncons { template struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_ALL_GETTER_SETTER_TRAITS(ClassType,GetPrefix,SetPrefix, ...) \ - JSONCONS_GETTER_SETTER_TRAITS_BASE(JSONCONS_ALL_GETTER_SETTER_AS, JSONCONS_ALL_GETTER_SETTER_TO_JSON,0,ClassType,GetPrefix,SetPrefix, JSONCONS_NARGS(__VA_ARGS__), JSONCONS_NARGS(__VA_ARGS__),__VA_ARGS__) \ - namespace jsoncons { template <> struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_TPL_ALL_GETTER_SETTER_TRAITS(NumTemplateParams, ClassType,GetPrefix,SetPrefix, ...) \ - JSONCONS_GETTER_SETTER_TRAITS_BASE(JSONCONS_ALL_GETTER_SETTER_AS, JSONCONS_ALL_GETTER_SETTER_TO_JSON,NumTemplateParams,ClassType,GetPrefix,SetPrefix, JSONCONS_NARGS(__VA_ARGS__), JSONCONS_NARGS(__VA_ARGS__),__VA_ARGS__) \ - namespace jsoncons { template struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_GETTER_SETTER_NAME_IS(P1, P2, P3, Seq, Count) JSONCONS_GETTER_SETTER_NAME_IS_LAST(P1, P2, P3, Seq, Count) -#define JSONCONS_GETTER_SETTER_NAME_IS_LAST(P1, P2, P3, Seq, Count) if ((num_params-Count) < num_mandatory_params1 && JSONCONS_EXPAND(JSONCONS_CONCAT(JSONCONS_GETTER_SETTER_NAME_IS_,JSONCONS_NARGS Seq) Seq) -#define JSONCONS_GETTER_SETTER_NAME_IS_3(Getter, Setter, Name) !ajson.contains(Name)) return false; -#define JSONCONS_GETTER_SETTER_NAME_IS_5(Getter, Setter, Name, Mode, Match) JSONCONS_GETTER_SETTER_NAME_IS_7(Getter, Setter, Name, Mode, Match,, ) -#define JSONCONS_GETTER_SETTER_NAME_IS_6(Getter, Setter, Name, Mode, Match, Into) JSONCONS_GETTER_SETTER_NAME_IS_7(Getter, Setter, Name, Mode, Match, Into, ) -#define JSONCONS_GETTER_SETTER_NAME_IS_7(Getter, Setter, Name, Mode, Match, Into, From) !ajson.contains(Name)) return false; \ - JSONCONS_TRY{if (!Match(ajson.at(Name).template as())->Getter()))>::type>())) return false;} \ - JSONCONS_CATCH(...) {return false;} - -#define JSONCONS_N_GETTER_SETTER_NAME_AS(P1, P2, P3, Seq, Count) JSONCONS_N_GETTER_SETTER_NAME_AS_LAST(P1, P2, P3, Seq, Count) -#define JSONCONS_N_GETTER_SETTER_NAME_AS_LAST(P1, P2, P3, Seq, Count) JSONCONS_EXPAND(JSONCONS_CONCAT(JSONCONS_N_GETTER_SETTER_NAME_AS_,JSONCONS_NARGS Seq) Seq) -#define JSONCONS_N_GETTER_SETTER_NAME_AS_3(Getter, Setter, Name) if (ajson.contains(Name)) class_instance.Setter(ajson.at(Name).template as::type>()); -#define JSONCONS_N_GETTER_SETTER_NAME_AS_4(Getter, Setter, Name, Mode) Mode(JSONCONS_N_GETTER_SETTER_NAME_AS_3(Getter, Setter, Name)) -#define JSONCONS_N_GETTER_SETTER_NAME_AS_5(Getter, Setter, Name, Mode, Match) JSONCONS_N_GETTER_SETTER_NAME_AS_7(Getter, Setter, Name, Mode, Match, , ) -#define JSONCONS_N_GETTER_SETTER_NAME_AS_6(Getter, Setter, Name, Mode, Match, Into) JSONCONS_N_GETTER_SETTER_NAME_AS_7(Getter, Setter, Name, Mode, Match, Into, ) -#define JSONCONS_N_GETTER_SETTER_NAME_AS_7(Getter, Setter, Name, Mode, Match, Into, From) Mode(if (ajson.contains(Name)) class_instance.Setter(From(ajson.at(Name).template as::type>()));) - -#define JSONCONS_N_GETTER_SETTER_NAME_TO_JSON(P1, P2, P3, Seq, Count) JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_LAST(P1, P2, P3, Seq, Count) -#define JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_LAST(P1, P2, P3, Seq, Count) JSONCONS_EXPAND(JSONCONS_CONCAT(JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_,JSONCONS_NARGS Seq) Seq) -#define JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_3(Getter, Setter, Name) ajson.try_emplace(Name,class_instance.Getter() ); -#define JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_5(Getter, Setter, Name, Mode, Match) JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_7(Getter, Setter, Name, Mode, Match, , ) -#define JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_6(Getter, Setter, Name, Mode, Match, Into) JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_7(Getter, Setter, Name, Mode, Match, Into, ) -#define JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_7(Getter, Setter, Name, Mode, Match, Into, From) ajson.try_emplace(Name, Into(class_instance.Getter()) ); - -#define JSONCONS_ALL_GETTER_SETTER_NAME_AS(P1, P2, P3, Seq, Count) JSONCONS_ALL_GETTER_SETTER_NAME_AS_LAST(P1, P2, P3, Seq, Count) -#define JSONCONS_ALL_GETTER_SETTER_NAME_AS_LAST(P1, P2, P3, Seq, Count) JSONCONS_EXPAND(JSONCONS_CONCAT(JSONCONS_ALL_GETTER_SETTER_NAME_AS_,JSONCONS_NARGS Seq) Seq) -#define JSONCONS_ALL_GETTER_SETTER_NAME_AS_3(Getter, Setter, Name) class_instance.Setter(ajson.at(Name).template as::type>()); -#define JSONCONS_ALL_GETTER_SETTER_NAME_AS_4(Getter, Setter, Name, Mode) Mode(JSONCONS_ALL_GETTER_SETTER_NAME_AS_3(Getter, Setter, Name)) -#define JSONCONS_ALL_GETTER_SETTER_NAME_AS_5(Getter, Setter, Name, Mode, Match) JSONCONS_ALL_GETTER_SETTER_NAME_AS_7(Getter, Setter, Name, Mode, Match, , ) -#define JSONCONS_ALL_GETTER_SETTER_NAME_AS_6(Getter, Setter, Name, Mode, Match, Into) JSONCONS_ALL_GETTER_SETTER_NAME_AS_7(Getter, Setter, Name, Mode, Match, Into, ) -#define JSONCONS_ALL_GETTER_SETTER_NAME_AS_7(Getter, Setter, Name, Mode, Match, Into, From) Mode(class_instance.Setter(From(ajson.at(Name).template as::type>()));) - -#define JSONCONS_ALL_GETTER_SETTER_NAME_TO_JSON(P1, P2, P3, Seq, Count) JSONCONS_ALL_GETTER_SETTER_NAME_TO_JSON_LAST(P1, P2, P3, Seq, Count) -#define JSONCONS_ALL_GETTER_SETTER_NAME_TO_JSON_LAST(P1, P2, P3, Seq, Count) if ((num_params-Count) < num_mandatory_params2) JSONCONS_EXPAND(JSONCONS_CONCAT(JSONCONS_ALL_GETTER_SETTER_NAME_TO_JSON_,JSONCONS_NARGS Seq) Seq) -#define JSONCONS_ALL_GETTER_SETTER_NAME_TO_JSON_3(Getter, Setter, Name) \ - ajson.try_emplace(Name,class_instance.Getter()); \ -else \ - {json_traits_helper::set_optional_json_member(Name,class_instance.Getter(), ajson);} -#define JSONCONS_ALL_GETTER_SETTER_NAME_TO_JSON_5(Getter, Setter, Name, Mode, Match) JSONCONS_ALL_GETTER_SETTER_NAME_TO_JSON_7(Getter, Setter, Name, Mode, Match, , ) -#define JSONCONS_ALL_GETTER_SETTER_NAME_TO_JSON_6(Getter, Setter, Name, Mode, Match, Into) JSONCONS_ALL_GETTER_SETTER_NAME_TO_JSON_7(Getter, Setter, Name, Mode, Match, Into, ) -#define JSONCONS_ALL_GETTER_SETTER_NAME_TO_JSON_7(Getter, Setter, Name, Mode, Match, Into, From) \ - ajson.try_emplace(Name, Into(class_instance.Getter())); \ -else \ - {json_traits_helper::set_optional_json_member(Name, Into(class_instance.Getter()), ajson);} - -#define JSONCONS_GETTER_SETTER_NAME_TRAITS_BASE(AsT,ToJ, NumTemplateParams, ClassType,NumMandatoryParams1,NumMandatoryParams2, ...) \ -namespace jsoncons \ -{ \ - template \ - struct json_type_traits \ - { \ - using class_type = ClassType JSONCONS_GENERATE_TPL_ARGS(JSONCONS_GENERATE_TPL_ARG, NumTemplateParams); \ - using allocator_type = typename Json::allocator_type; \ - using char_type = typename Json::char_type; \ - using string_view_type = typename Json::string_view_type; \ - constexpr static size_t num_params = JSONCONS_NARGS(__VA_ARGS__); \ - constexpr static size_t num_mandatory_params1 = NumMandatoryParams1; \ - constexpr static size_t num_mandatory_params2 = NumMandatoryParams2; \ - static bool is(const Json& ajson) noexcept \ - { \ - if (!ajson.is_object()) return false; \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_GETTER_SETTER_NAME_IS,,,, __VA_ARGS__)\ - return true; \ - } \ - static class_type as(const Json& ajson) \ - { \ - if (!is(ajson)) JSONCONS_THROW(conv_error(conv_errc::conversion_failed, "Not a " # ClassType)); \ - class_type class_instance{}; \ - JSONKONS_VARIADIC_FOR_EACH(AsT,,,, __VA_ARGS__) \ - return class_instance; \ - } \ - static Json to_json(const class_type& class_instance, allocator_type alloc=allocator_type()) \ - { \ - Json ajson(json_object_arg, semantic_tag::none, alloc); \ - JSONKONS_VARIADIC_FOR_EACH(ToJ,,,, __VA_ARGS__) \ - return ajson; \ - } \ - }; \ -} \ - /**/ - -#define JSONCONS_N_GETTER_SETTER_NAME_TRAITS(ClassType,NumMandatoryParams, ...) \ - JSONCONS_GETTER_SETTER_NAME_TRAITS_BASE(JSONCONS_N_GETTER_SETTER_NAME_AS,JSONCONS_N_GETTER_SETTER_NAME_TO_JSON, 0, ClassType,NumMandatoryParams,NumMandatoryParams, __VA_ARGS__) \ - namespace jsoncons { template <> struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_TPL_N_GETTER_SETTER_NAME_TRAITS(NumTemplateParams, ClassType,NumMandatoryParams, ...) \ - JSONCONS_GETTER_SETTER_NAME_TRAITS_BASE(JSONCONS_N_GETTER_SETTER_NAME_AS,JSONCONS_N_GETTER_SETTER_NAME_TO_JSON, NumTemplateParams, ClassType,NumMandatoryParams,NumMandatoryParams, __VA_ARGS__) \ - namespace jsoncons { template struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_ALL_GETTER_SETTER_NAME_TRAITS(ClassType, ...) \ - JSONCONS_GETTER_SETTER_NAME_TRAITS_BASE(JSONCONS_ALL_GETTER_SETTER_NAME_AS,JSONCONS_ALL_GETTER_SETTER_NAME_TO_JSON, 0, ClassType, JSONCONS_NARGS(__VA_ARGS__), JSONCONS_NARGS(__VA_ARGS__), __VA_ARGS__) \ - namespace jsoncons { template <> struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_TPL_ALL_GETTER_SETTER_NAME_TRAITS(NumTemplateParams, ClassType, ...) \ - JSONCONS_GETTER_SETTER_NAME_TRAITS_BASE(JSONCONS_ALL_GETTER_SETTER_NAME_AS,JSONCONS_ALL_GETTER_SETTER_NAME_TO_JSON, NumTemplateParams, ClassType, JSONCONS_NARGS(__VA_ARGS__), JSONCONS_NARGS(__VA_ARGS__), __VA_ARGS__) \ - namespace jsoncons { template struct is_json_type_traits_declared : public std::true_type {}; } \ - /**/ - -#define JSONCONS_POLYMORPHIC_IS(BaseClass, P2, P3, DerivedClass, Count) if (ajson.template is()) return true; -#define JSONCONS_POLYMORPHIC_IS_LAST(BaseClass, P2, P3, DerivedClass, Count) if (ajson.template is()) return true; - -#define JSONCONS_POLYMORPHIC_AS(BaseClass, P2, P3, DerivedClass, Count) if (ajson.template is()) return std::make_shared(ajson.template as()); -#define JSONCONS_POLYMORPHIC_AS_LAST(BaseClass, P2, P3, DerivedClass, Count) if (ajson.template is()) return std::make_shared(ajson.template as()); - -#define JSONCONS_POLYMORPHIC_AS_UNIQUE_PTR(BaseClass, P2, P3, DerivedClass, Count) if (ajson.template is()) return jsoncons::make_unique(ajson.template as()); -#define JSONCONS_POLYMORPHIC_AS_UNIQUE_PTR_LAST(BaseClass, P2, P3, DerivedClass, Count) if (ajson.template is()) return jsoncons::make_unique(ajson.template as()); - -#define JSONCONS_POLYMORPHIC_AS_SHARED_PTR(BaseClass, P2, P3, DerivedClass, Count) if (ajson.template is()) return std::make_shared(ajson.template as()); -#define JSONCONS_POLYMORPHIC_AS_SHARED_PTR_LAST(BaseClass, P2, P3, DerivedClass, Count) if (ajson.template is()) return std::make_shared(ajson.template as()); - -#define JSONCONS_POLYMORPHIC_TO_JSON(BaseClass, P2, P3, DerivedClass, Count) if (DerivedClass* p = dynamic_cast(ptr.get())) {return Json(*p);} -#define JSONCONS_POLYMORPHIC_TO_JSON_LAST(BaseClass, P2, P3, DerivedClass, Count) if (DerivedClass* p = dynamic_cast(ptr.get())) {return Json(*p);} - -#define JSONCONS_POLYMORPHIC_TRAITS(BaseClass, ...) \ -namespace jsoncons { \ - template \ - struct json_type_traits> { \ - static bool is(const Json& ajson) noexcept { \ - if (!ajson.is_object()) return false; \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_POLYMORPHIC_IS, BaseClass,,, __VA_ARGS__)\ - return false; \ - } \ -\ - static std::shared_ptr as(const Json& ajson) { \ - if (!ajson.is_object()) return std::shared_ptr(); \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_POLYMORPHIC_AS_SHARED_PTR, BaseClass,,, __VA_ARGS__)\ - return std::shared_ptr(); \ - } \ -\ - static Json to_json(const std::shared_ptr& ptr) { \ - if (ptr.get() == nullptr) {return Json::null();} \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_POLYMORPHIC_TO_JSON, BaseClass,,, __VA_ARGS__)\ - return Json::null(); \ - } \ - }; \ - template \ - struct json_type_traits> { \ - static bool is(const Json& ajson) noexcept { \ - if (!ajson.is_object()) return false; \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_POLYMORPHIC_IS, BaseClass,,, __VA_ARGS__)\ - return false; \ - } \ - static std::unique_ptr as(const Json& ajson) { \ - if (!ajson.is_object()) return std::unique_ptr(); \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_POLYMORPHIC_AS_UNIQUE_PTR, BaseClass,,, __VA_ARGS__)\ - return std::unique_ptr(); \ - } \ - static Json to_json(const std::unique_ptr& ptr) { \ - if (ptr.get() == nullptr) {return Json::null();} \ - JSONKONS_VARIADIC_FOR_EACH(JSONCONS_POLYMORPHIC_TO_JSON, BaseClass,,, __VA_ARGS__)\ - return Json::null(); \ - } \ - }; \ -} \ - /**/ - -#endif // JSONCONS_JSON_TRAITS_MACROS_HPP diff --git a/include/jsoncons/ser_context.hpp b/include/jsoncons/ser_context.hpp deleted file mode 100644 index 3148750..0000000 --- a/include/jsoncons/ser_context.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/// Copyright 2013-2025 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_SER_CONTEXT_HPP -#define JSONCONS_SER_CONTEXT_HPP - -#include - -namespace jsoncons { - -class ser_context -{ -public: - virtual ~ser_context() = default; - - virtual size_t line() const - { - return 0; - } - - virtual size_t column() const - { - return 0; - } - - virtual size_t position() const - { - return 0; - } - - virtual size_t begin_position() const - { - return 0; - } - - virtual size_t end_position() const - { - return 0; - } -}; - -} // namespace jsoncons - -#endif // JSONCONS_SER_CONTEXT_HPP diff --git a/include/jsoncons/value_converter.hpp b/include/jsoncons/value_converter.hpp deleted file mode 100644 index e1dc75e..0000000 --- a/include/jsoncons/value_converter.hpp +++ /dev/null @@ -1,345 +0,0 @@ -// Copyright 2013-2025 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_VALUE_CONVERTER_HPP -#define JSONCONS_VALUE_CONVERTER_HPP - -#include -#include -#include // std::error_code - -#include -#include -#include // from_integer -#include -#include -#include -#include -#include - -namespace jsoncons { - - template - class value_converter - { - }; - - template - class value_converter_base - { - public: - using allocator_type = typename std::conditional::value,typename Into::allocator_type, std::allocator>::type; - private: - allocator_type alloc_; - - public: - value_converter_base(const allocator_type& alloc = allocator_type()) - : alloc_(alloc) - { - } - - allocator_type get_allocator() const noexcept - { - return alloc_; - } - }; - - // From any byte sequence, Into string - template - class value_converter::value && !ext_traits::is_string_or_string_view::value && - ext_traits::is_string::value>::type> : value_converter_base - { - public: - using allocator_type = typename value_converter_base::allocator_type; - - template - typename std::enable_if::value,Into>::type - convert(const From& value, semantic_tag tag, std::error_code&) - { - Into s(this->get_allocator()); - switch (tag) - { - case semantic_tag::base64: - encode_base64(value.begin(), value.end(), s); - break; - case semantic_tag::base16: - encode_base16(value.begin(), value.end(), s); - break; - default: - encode_base64url(value.begin(), value.end(), s); - break; - } - return s; - } - template - typename std::enable_if::value,Into>::type - convert(const From& value, semantic_tag tag, std::error_code& ec) - { - std::string s; - switch (tag) - { - case semantic_tag::base64: - encode_base64(value.begin(), value.end(), s); - break; - case semantic_tag::base16: - encode_base16(value.begin(), value.end(), s); - break; - default: - encode_base64url(value.begin(), value.end(), s); - break; - } - - Into ws(this->get_allocator()); - auto retval = unicode_traits::convert(s.data(), s.size(), ws); - if (retval.ec != unicode_traits::conv_errc()) - { - ec = conv_errc::not_wide_char; - } - - return ws; - } - }; - - // From byte string, Into byte string - template - class value_converter::value && - !ext_traits::is_string_or_string_view::value && - !ext_traits::is_string_or_string_view::value && - ext_traits::is_back_insertable_byte_container::value>::type> : value_converter_base - { - public: - using allocator_type = typename value_converter_base::allocator_type; - - Into convert(const From& value, semantic_tag, std::error_code&) - { - Into s(value.begin(),value.end(),this->get_allocator()); - return s; - } - }; - - // From string or string_view, Into string, same character type - template - class value_converter::value && - ext_traits::is_string::value && - std::is_same::value>::type> : value_converter_base - { - public: - using allocator_type = typename value_converter_base::allocator_type; - - Into convert(const From& value, semantic_tag, std::error_code&) - { - return Into(value.begin(),value.end(),this->get_allocator()); - } - }; - - // From string or string_view, Into string, different character type - template - class value_converter::value && - ext_traits::is_string::value && - !std::is_same::value>::type> : value_converter_base - { - public: - using allocator_type = typename value_converter_base::allocator_type; - - Into convert(const From& value, semantic_tag, std::error_code& ec) - { - Into ws(this->get_allocator()); - auto retval = unicode_traits::convert(value.data(), value.size(), ws); - if (retval.ec != unicode_traits::conv_errc()) - { - ec = conv_errc::not_wide_char; - } - - return ws; - } - }; - - // From string, Into byte_string - template - class value_converter::value && - !ext_traits::is_string_or_string_view::value && - ext_traits::is_back_insertable_byte_container::value>::type> : value_converter_base - { - public: - using allocator_type = typename value_converter_base::allocator_type; - - template - typename std::enable_if::value,Into>::type - convert(const From& value, semantic_tag tag, std::error_code& ec) - { - Into bytes(this->get_allocator()); - switch (tag) - { - case semantic_tag::base16: - { - auto res = decode_base16(value.begin(), value.end(), bytes); - if (res.ec != conv_errc::success) - { - ec = conv_errc::not_byte_string; - } - break; - } - case semantic_tag::base64: - { - decode_base64(value.begin(), value.end(), bytes); - break; - } - case semantic_tag::base64url: - { - decode_base64url(value.begin(), value.end(), bytes); - break; - } - default: - { - ec = conv_errc::not_byte_string; - break; - } - } - return bytes; - } - - template - typename std::enable_if::value,Into>::type - convert(const From& value, semantic_tag tag, std::error_code& ec) - { - Into bytes(this->get_allocator()); - - std::string s(this->get_allocator()); - auto retval = unicode_traits::convert(value.data(), value.size(), s); - if (retval.ec != unicode_traits::conv_errc()) - { - ec = conv_errc::not_wide_char; - } - switch (tag) - { - case semantic_tag::base16: - { - auto res = decode_base16(s.begin(), s.end(), bytes); - if (res.ec != conv_errc::success) - { - ec = conv_errc::not_byte_string; - } - break; - } - case semantic_tag::base64: - { - decode_base64(s.begin(), s.end(), bytes); - break; - } - case semantic_tag::base64url: - { - decode_base64url(s.begin(), s.end(), bytes); - break; - } - default: - { - ec = conv_errc::not_byte_string; - break; - } - } - return bytes; - } - }; - - // From integer, Into string - template - class value_converter::value && - ext_traits::is_string::value>::type> : value_converter_base - { - public: - using allocator_type = typename value_converter_base::allocator_type; - - Into convert(From value, semantic_tag, std::error_code&) - { - Into s(this->get_allocator()); - jsoncons::detail::from_integer(value, s); - return s; - } - }; - - // From integer, Into string - template - class value_converter::value && - ext_traits::is_string::value>::type> : value_converter_base - { - public: - using allocator_type = typename value_converter_base::allocator_type; - - Into convert(From value, semantic_tag, std::error_code&) - { - Into s(this->get_allocator()); - jsoncons::detail::write_double f{float_chars_format::general,0}; - f(value, s); - return s; - } - }; - - // From half, Into string - template - class value_converter::value>::type> : value_converter_base - { - public: - using allocator_type = typename value_converter_base::allocator_type; - - Into convert(uint16_t value, semantic_tag, std::error_code&) - { - Into s(this->get_allocator()); - jsoncons::detail::write_double f{float_chars_format::general,0}; - double x = binary::decode_half(value); - f(x, s); - return s; - } - }; - - // From bool, Into string - template - class value_converter::value && - ext_traits::is_string::value>::type> : value_converter_base - { - public: - using allocator_type = typename value_converter_base::allocator_type; - using char_type = typename Into::value_type; - - JSONCONS_CPP14_CONSTEXPR - Into convert(From value, semantic_tag, std::error_code&) - { - constexpr const char_type* true_constant = JSONCONS_CSTRING_CONSTANT(char_type,"true"); - constexpr const char_type* false_constant = JSONCONS_CSTRING_CONSTANT(char_type,"false"); - - return value ? Into(true_constant,4) : Into(false_constant,5); - } - }; - - // From null, Into string - template - class value_converter : value_converter_base - { - public: - using allocator_type = typename value_converter_base::allocator_type; - using char_type = typename Into::value_type; - - JSONCONS_CPP14_CONSTEXPR - Into convert(semantic_tag, std::error_code&) - { - constexpr const char_type* null_constant = JSONCONS_CSTRING_CONSTANT(char_type,"null"); - - return Into(null_constant,4); - } - }; - -} // namespace jsoncons - -#endif // JSONCONS_VALUE_CONVERTER_HPP - From 94802fb388680466290fb8508a9e26cebc73c73e Mon Sep 17 00:00:00 2001 From: tang zhixiong Date: Sun, 15 Feb 2026 13:40:32 +0800 Subject: [PATCH 2/4] fix warning --- include/cubao/polyline_ruler.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/cubao/polyline_ruler.hpp b/include/cubao/polyline_ruler.hpp index 2638551..ce6b619 100644 --- a/include/cubao/polyline_ruler.hpp +++ b/include/cubao/polyline_ruler.hpp @@ -664,7 +664,8 @@ struct PolylineRuler } double minDist = std::numeric_limits::infinity(); Eigen::Vector3d minP(0.0, 0.0, 0.0); - double minI = 0., minT = 0.; + int minI = 0; + double minT = 0.0; for (int i = 0; i < N - 1; ++i) { double t = 0.; Eigen::Vector3d ab = line.row(i + 1) - line.row(i); From f1d14b271546638d0f6012786d0734a1d162be7c Mon Sep 17 00:00:00 2001 From: tang zhixiong Date: Mon, 16 Feb 2026 02:28:32 +0800 Subject: [PATCH 3/4] fix --- .github/workflows/wheels.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index db04a96..5f6f443 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -32,7 +32,7 @@ jobs: - name: Check metadata run: pipx run twine check dist/* - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: path: dist/*.tar.gz @@ -44,15 +44,16 @@ jobs: if: github.event_name == 'release' && github.event.action == 'published' steps: - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: "3.9" - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: artifact path: dist - uses: pypa/gh-action-pypi-publish@release/v1 with: - password: ${{ secrets.PYPI_PASSWORD }} + skip-existing: true + verbose: true From e184325d3d20c31eaf1fb65a27ffbaa6aadeca2b Mon Sep 17 00:00:00 2001 From: tang zhixiong Date: Mon, 16 Feb 2026 02:30:23 +0800 Subject: [PATCH 4/4] fix --- build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.py b/build.py index 84b8fb5..2f292a7 100644 --- a/build.py +++ b/build.py @@ -6,7 +6,7 @@ from setuptools import setup, find_packages name = "cubao_headers" -version = "0.1.0" +version = "0.1.1" pattern = ["*"]