Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/no virtual sax #1153

Merged
merged 5 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ SRCS = include/nlohmann/json.hpp \
include/nlohmann/detail/json_ref.hpp \
include/nlohmann/detail/macro_scope.hpp \
include/nlohmann/detail/macro_unscope.hpp \
include/nlohmann/detail/meta.hpp \
include/nlohmann/detail/meta/cpp_future.hpp \
include/nlohmann/detail/meta/detected.hpp \
include/nlohmann/detail/meta/type_traits.hpp \
include/nlohmann/detail/meta/void_t.hpp \
include/nlohmann/detail/output/binary_writer.hpp \
include/nlohmann/detail/output/output_adapters.hpp \
include/nlohmann/detail/output/serializer.hpp \
Expand Down
3 changes: 2 additions & 1 deletion include/nlohmann/detail/conversions/from_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

#include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>
#include <nlohmann/detail/value_t.hpp>

namespace nlohmann
Expand Down
3 changes: 2 additions & 1 deletion include/nlohmann/detail/conversions/to_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include <valarray> // valarray
#include <vector> // vector

#include <nlohmann/detail/meta.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>
#include <nlohmann/detail/value_t.hpp>
#include <nlohmann/detail/iterators/iteration_proxy.hpp>

Expand Down
22 changes: 12 additions & 10 deletions include/nlohmann/detail/input/binary_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <nlohmann/detail/input/json_sax.hpp>
#include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/is_sax.hpp>
#include <nlohmann/detail/value_t.hpp>

namespace nlohmann
Expand All @@ -30,14 +31,14 @@ namespace detail
/*!
@brief deserialization of CBOR, MessagePack, and UBJSON values
*/
template<typename BasicJsonType>
template<typename BasicJsonType, typename SAX = json_sax_dom_parser<BasicJsonType>>
class binary_reader
{
using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
using json_sax_t = json_sax<BasicJsonType>;
using json_sax_t = SAX;

public:
/*!
Expand All @@ -47,6 +48,7 @@ class binary_reader
*/
explicit binary_reader(input_adapter_t adapter) : ia(std::move(adapter))
{
(void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
assert(ia);
}

Expand Down Expand Up @@ -321,7 +323,7 @@ class binary_reader
}

case 0x9F: // array (indefinite length)
return get_cbor_array(json_sax_t::no_limit);
return get_cbor_array(std::size_t(-1));

// map (0x00..0x17 pairs of data items follow)
case 0xA0:
Expand Down Expand Up @@ -375,7 +377,7 @@ class binary_reader
}

case 0xBF: // map (indefinite length)
return get_cbor_object(json_sax_t::no_limit);
return get_cbor_object(std::size_t(-1));

case 0xF4: // false
return sax->boolean(false);
Expand Down Expand Up @@ -1020,7 +1022,7 @@ class binary_reader
}

/*!
@param[in] len the length of the array or json_sax_t::no_limit for an
@param[in] len the length of the array or std::size_t(-1) for an
array of indefinite size
@return whether array creation completed
*/
Expand All @@ -1031,7 +1033,7 @@ class binary_reader
return false;
}

if (len != json_sax_t::no_limit)
if (len != std::size_t(-1))
for (std::size_t i = 0; i < len; ++i)
{
if (JSON_UNLIKELY(not parse_cbor_internal()))
Expand All @@ -1054,7 +1056,7 @@ class binary_reader
}

/*!
@param[in] len the length of the object or json_sax_t::no_limit for an
@param[in] len the length of the object or std::size_t(-1) for an
object of indefinite size
@return whether object creation completed
*/
Expand All @@ -1066,7 +1068,7 @@ class binary_reader
}

string_t key;
if (len != json_sax_t::no_limit)
if (len != std::size_t(-1))
{
for (std::size_t i = 0; i < len; ++i)
{
Expand Down Expand Up @@ -1558,7 +1560,7 @@ class binary_reader
}
else
{
if (JSON_UNLIKELY(not sax->start_array()))
if (JSON_UNLIKELY(not sax->start_array(-1)))
{
return false;
}
Expand Down Expand Up @@ -1628,7 +1630,7 @@ class binary_reader
}
else
{
if (JSON_UNLIKELY(not sax->start_object()))
if (JSON_UNLIKELY(not sax->start_object(-1)))
{
return false;
}
Expand Down
Loading