templated input adapters
This commit is contained in:
parent
973c52dd4a
commit
617b3cf42e
7 changed files with 623 additions and 310 deletions
|
|
@ -22,19 +22,9 @@ namespace detail
|
|||
// lexer //
|
||||
///////////
|
||||
|
||||
/*!
|
||||
@brief lexical analysis
|
||||
|
||||
This class organizes the lexical analysis during JSON deserialization.
|
||||
*/
|
||||
template<typename BasicJsonType>
|
||||
class lexer
|
||||
class lexer_base
|
||||
{
|
||||
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;
|
||||
|
||||
public:
|
||||
/// token types for the parser
|
||||
enum class token_type
|
||||
|
|
@ -75,9 +65,9 @@ class lexer
|
|||
return "null literal";
|
||||
case token_type::value_string:
|
||||
return "string literal";
|
||||
case lexer::token_type::value_unsigned:
|
||||
case lexer::token_type::value_integer:
|
||||
case lexer::token_type::value_float:
|
||||
case token_type::value_unsigned:
|
||||
case token_type::value_integer:
|
||||
case token_type::value_float:
|
||||
return "number literal";
|
||||
case token_type::begin_array:
|
||||
return "'['";
|
||||
|
|
@ -103,15 +93,33 @@ class lexer
|
|||
// LCOV_EXCL_STOP
|
||||
}
|
||||
}
|
||||
};
|
||||
/*!
|
||||
@brief lexical analysis
|
||||
|
||||
explicit lexer(detail::input_adapter_t&& adapter)
|
||||
This class organizes the lexical analysis during JSON deserialization.
|
||||
*/
|
||||
template<typename BasicJsonType, typename InputAdapterType = input_adapter_protocol>
|
||||
class lexer : public lexer_base<BasicJsonType>
|
||||
{
|
||||
using input_adapter_ptr_t = std::shared_ptr<InputAdapterType>;
|
||||
|
||||
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;
|
||||
|
||||
public:
|
||||
using token_type = typename lexer_base<BasicJsonType>::token_type;
|
||||
|
||||
explicit lexer(input_adapter_ptr_t&& adapter)
|
||||
: ia(std::move(adapter)), decimal_point_char(get_decimal_point()) {}
|
||||
|
||||
// delete because of pointer members
|
||||
lexer(const lexer&) = delete;
|
||||
lexer(lexer&&) = delete;
|
||||
lexer(lexer&&) = default;
|
||||
lexer& operator=(lexer&) = delete;
|
||||
lexer& operator=(lexer&&) = delete;
|
||||
lexer& operator=(lexer&&) = default;
|
||||
~lexer() = default;
|
||||
|
||||
private:
|
||||
|
|
@ -1480,7 +1488,7 @@ scan_number_done:
|
|||
|
||||
private:
|
||||
/// input adapter
|
||||
detail::input_adapter_t ia = nullptr;
|
||||
input_adapter_ptr_t ia = nullptr;
|
||||
|
||||
/// the current character
|
||||
std::char_traits<char>::int_type current = std::char_traits<char>::eof();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue