use templates in the sax interface instead of virtuals
This commit is contained in:
parent
f6febbe359
commit
442886d040
10 changed files with 207 additions and 209 deletions
|
|
@ -136,7 +136,7 @@ constructor contains the parsed value.
|
|||
@tparam BasicJsonType the JSON type
|
||||
*/
|
||||
template<typename BasicJsonType>
|
||||
class json_sax_dom_parser : public json_sax<BasicJsonType>
|
||||
class json_sax_dom_parser
|
||||
{
|
||||
public:
|
||||
using number_integer_t = typename BasicJsonType::number_integer_t;
|
||||
|
|
@ -153,43 +153,43 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
|
|||
: root(r), allow_exceptions(allow_exceptions_)
|
||||
{}
|
||||
|
||||
bool null() override
|
||||
bool null()
|
||||
{
|
||||
handle_value(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool boolean(bool val) override
|
||||
bool boolean(bool val)
|
||||
{
|
||||
handle_value(val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool number_integer(number_integer_t val) override
|
||||
bool number_integer(number_integer_t val)
|
||||
{
|
||||
handle_value(val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool number_unsigned(number_unsigned_t val) override
|
||||
bool number_unsigned(number_unsigned_t val)
|
||||
{
|
||||
handle_value(val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool number_float(number_float_t val, const string_t&) override
|
||||
bool number_float(number_float_t val, const string_t&)
|
||||
{
|
||||
handle_value(val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool string(string_t& val) override
|
||||
bool string(string_t& val)
|
||||
{
|
||||
handle_value(val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool start_object(std::size_t len) override
|
||||
bool start_object(std::size_t len = -1)
|
||||
{
|
||||
ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
|
||||
|
||||
|
|
@ -202,20 +202,20 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
|
|||
return true;
|
||||
}
|
||||
|
||||
bool key(string_t& val) override
|
||||
bool key(string_t& val)
|
||||
{
|
||||
// add null at given key and store the reference for later
|
||||
object_element = &(ref_stack.back()->m_value.object->operator[](val));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool end_object() override
|
||||
bool end_object()
|
||||
{
|
||||
ref_stack.pop_back();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool start_array(std::size_t len) override
|
||||
bool start_array(std::size_t len = -1)
|
||||
{
|
||||
ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
|
||||
|
||||
|
|
@ -228,14 +228,14 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
|
|||
return true;
|
||||
}
|
||||
|
||||
bool end_array() override
|
||||
bool end_array()
|
||||
{
|
||||
ref_stack.pop_back();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_error(std::size_t, const std::string&,
|
||||
const detail::exception& ex) override
|
||||
const detail::exception& ex)
|
||||
{
|
||||
errored = true;
|
||||
if (allow_exceptions)
|
||||
|
|
@ -310,7 +310,7 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
|
|||
};
|
||||
|
||||
template<typename BasicJsonType>
|
||||
class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
|
||||
class json_sax_dom_callback_parser
|
||||
{
|
||||
public:
|
||||
using number_integer_t = typename BasicJsonType::number_integer_t;
|
||||
|
|
@ -328,43 +328,43 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
|
|||
keep_stack.push_back(true);
|
||||
}
|
||||
|
||||
bool null() override
|
||||
bool null()
|
||||
{
|
||||
handle_value(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool boolean(bool val) override
|
||||
bool boolean(bool val)
|
||||
{
|
||||
handle_value(val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool number_integer(number_integer_t val) override
|
||||
bool number_integer(number_integer_t val)
|
||||
{
|
||||
handle_value(val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool number_unsigned(number_unsigned_t val) override
|
||||
bool number_unsigned(number_unsigned_t val)
|
||||
{
|
||||
handle_value(val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool number_float(number_float_t val, const string_t&) override
|
||||
bool number_float(number_float_t val, const string_t&)
|
||||
{
|
||||
handle_value(val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool string(string_t& val) override
|
||||
bool string(string_t& val)
|
||||
{
|
||||
handle_value(val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool start_object(std::size_t len) override
|
||||
bool start_object(std::size_t len = -1)
|
||||
{
|
||||
// check callback for object start
|
||||
const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);
|
||||
|
|
@ -386,7 +386,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
|
|||
return true;
|
||||
}
|
||||
|
||||
bool key(string_t& val) override
|
||||
bool key(string_t& val)
|
||||
{
|
||||
BasicJsonType k = BasicJsonType(val);
|
||||
|
||||
|
|
@ -403,7 +403,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
|
|||
return true;
|
||||
}
|
||||
|
||||
bool end_object() override
|
||||
bool end_object()
|
||||
{
|
||||
if (ref_stack.back())
|
||||
{
|
||||
|
|
@ -438,7 +438,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
|
|||
return true;
|
||||
}
|
||||
|
||||
bool start_array(std::size_t len) override
|
||||
bool start_array(std::size_t len = -1)
|
||||
{
|
||||
const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);
|
||||
keep_stack.push_back(keep);
|
||||
|
|
@ -459,7 +459,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
|
|||
return true;
|
||||
}
|
||||
|
||||
bool end_array() override
|
||||
bool end_array()
|
||||
{
|
||||
bool keep = true;
|
||||
|
||||
|
|
@ -491,7 +491,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
|
|||
}
|
||||
|
||||
bool parse_error(std::size_t, const std::string&,
|
||||
const detail::exception& ex) override
|
||||
const detail::exception& ex)
|
||||
{
|
||||
errored = true;
|
||||
if (allow_exceptions)
|
||||
|
|
@ -614,7 +614,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
|
|||
};
|
||||
|
||||
template<typename BasicJsonType>
|
||||
class json_sax_acceptor : public json_sax<BasicJsonType>
|
||||
class json_sax_acceptor
|
||||
{
|
||||
public:
|
||||
using number_integer_t = typename BasicJsonType::number_integer_t;
|
||||
|
|
@ -622,62 +622,62 @@ class json_sax_acceptor : public json_sax<BasicJsonType>
|
|||
using number_float_t = typename BasicJsonType::number_float_t;
|
||||
using string_t = typename BasicJsonType::string_t;
|
||||
|
||||
bool null() override
|
||||
bool null()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool boolean(bool) override
|
||||
bool boolean(bool)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool number_integer(number_integer_t) override
|
||||
bool number_integer(number_integer_t)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool number_unsigned(number_unsigned_t) override
|
||||
bool number_unsigned(number_unsigned_t)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool number_float(number_float_t, const string_t&) override
|
||||
bool number_float(number_float_t, const string_t&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool string(string_t&) override
|
||||
bool string(string_t&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool start_object(std::size_t) override
|
||||
bool start_object(std::size_t = -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool key(string_t&) override
|
||||
bool key(string_t&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool end_object() override
|
||||
bool end_object()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool start_array(std::size_t) override
|
||||
bool start_array(std::size_t = -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool end_array() override
|
||||
bool end_array()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_error(std::size_t, const std::string&, const detail::exception&) override
|
||||
bool parse_error(std::size_t, const std::string&, const detail::exception&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue