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

templated input adapters #1950

Merged
merged 9 commits into from
May 14, 2020
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
35 changes: 18 additions & 17 deletions include/nlohmann/detail/input/binary_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,28 @@ namespace nlohmann
{
namespace detail
{

/*!
@brief determine system byte order

@return true if and only if system's byte order is little endian

@note from https://stackoverflow.com/a/1001328/266378
*/
static bool little_endianess(int num = 1) noexcept
{
return *reinterpret_cast<char*>(&num) == 1;
}


///////////////////
// binary reader //
///////////////////

/*!
@brief deserialization of CBOR, MessagePack, and UBJSON values
*/
template<typename BasicJsonType, typename SAX = json_sax_dom_parser<BasicJsonType>>
template<typename BasicJsonType, typename InputAdapterType, typename SAX = json_sax_dom_parser<BasicJsonType>>
class binary_reader
{
using number_integer_t = typename BasicJsonType::number_integer_t;
Expand All @@ -47,10 +61,9 @@ class binary_reader

@param[in] adapter input adapter to read from
*/
explicit binary_reader(input_adapter_t adapter) : ia(std::move(adapter))
explicit binary_reader(InputAdapterType&& adapter) : ia(std::move(adapter))
{
(void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
assert(ia);
}

// make class move-only
Expand Down Expand Up @@ -119,18 +132,6 @@ class binary_reader
return result;
}

/*!
@brief determine system byte order

@return true if and only if system's byte order is little endian

@note from https://stackoverflow.com/a/1001328/266378
*/
static constexpr bool little_endianess(int num = 1) noexcept
{
return *reinterpret_cast<char*>(&num) == 1;
}

private:
//////////
// BSON //
Expand Down Expand Up @@ -2085,7 +2086,7 @@ class binary_reader
int get()
{
++chars_read;
return current = ia->get_character();
return current = ia.get_character();
}

/*!
Expand Down Expand Up @@ -2273,7 +2274,7 @@ class binary_reader

private:
/// input adapter
input_adapter_t ia = nullptr;
InputAdapterType ia;

/// the current character
int current = std::char_traits<char>::eof();
Expand Down
Loading