From cf81aa75b61ab8fab93471ca274f85e6798908aa Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 29 Sep 2023 09:45:55 +0200 Subject: [PATCH] using allocator for bson --- single_include/nlohmann/json.hpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index ac4a1d08b..580c70ef2 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -6903,7 +6903,10 @@ class json_sax_dom_parser /// the parsed JSON value BasicJsonType& root; /// stack to model hierarchy of values - std::vector ref_stack {}; + + + using allocator_type = typename BasicJsonType::allocator_type; + std::vector ref_stack {}; /// helper to hold the reference for the next object element BasicJsonType* object_element = nullptr; /// whether a syntax error occurred @@ -8915,8 +8918,10 @@ scan_number_done: position_t position {}; /// raw input token string (for error messages) - std::vector token_string {}; + using allocator_type = typename BasicJsonType::allocator_type; + + std::vector token_string {}; /// buffer for variable-length tokens (numbers, strings) string_t token_buffer {}; @@ -11791,7 +11796,7 @@ class binary_reader case token_type::value_unsigned: return sax->number_unsigned(number_lexer.get_number_unsigned()); case token_type::value_float: - return sax->number_float(number_lexer.get_number_float(), std::move(number_string)); + return sax->number_float(number_lexer.get_number_float(), std::move(static_cast(number_string))); case token_type::uninitialized: case token_type::literal_true: case token_type::literal_false: @@ -12165,7 +12170,7 @@ class parser using string_t = typename BasicJsonType::string_t; using lexer_t = lexer; using token_type = typename lexer_t::token_type; - + using allocator_type = typename BasicJsonType::string_t::allocator_type; public: /// a parser reading from an input adapter explicit parser(InputAdapterType&& adapter, @@ -12279,9 +12284,10 @@ class parser JSON_HEDLEY_NON_NULL(2) bool sax_parse_internal(SAX* sax) { + using allocator_type = typename BasicJsonType::allocator_type; // stack to remember the hierarchy of structured values we are parsing // true = array; false = object - std::vector states; + std::vector states; // value to avoid a goto (see comment where set to true) bool skip_to_state_evaluation = false; @@ -14950,7 +14956,10 @@ class output_adapter public: template> output_adapter(std::vector& vec) - : oa(std::make_shared>(vec)) {} + { + AllocatorType alloc; + oa = std::allocate_shared>(alloc ,vec); + } #ifndef JSON_NO_IO output_adapter(std::basic_ostream& s) @@ -16061,7 +16070,7 @@ class binary_writer const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), static_cast(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type & el) { - return result + calc_bson_element_size(std::to_string(array_index++), el); + return result + calc_bson_element_size(static_cast(std::to_string(array_index++)), el); }); return sizeof(std::int32_t) + embedded_document_size + 1ul; @@ -16088,7 +16097,7 @@ class binary_writer for (const auto& el : value) { - write_bson_element(std::to_string(array_index++), el); + write_bson_element(static_cast(std::to_string(array_index++)), el); } oa->write_character(to_char_type(0x00)); @@ -19780,7 +19789,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec if (t == value_t::array || t == value_t::object) { // flatten the current json_value to a heap-allocated stack - std::vector stack; + std::vector> stack; // move the top-level items to stack if (t == value_t::array)