remove no_limit constant and default values

This commit is contained in:
Théo DELRIEU 2018-07-24 13:09:08 +02:00
parent 442886d040
commit 9bbb133094
No known key found for this signature in database
GPG key ID: 7D6E00D1DF01DEAF
4 changed files with 30 additions and 36 deletions

View file

@ -25,9 +25,6 @@ struct json_sax
/// type for strings
using string_t = typename BasicJsonType::string_t;
/// constant to indicate that no size limit is given for array or object
static constexpr auto no_limit = std::size_t(-1);
/*!
@brief a null value was read
@return whether parsing should proceed
@ -72,11 +69,11 @@ struct json_sax
/*!
@brief the beginning of an object was read
@param[in] elements number of object elements or no_limit if unknown
@param[in] elements number of object elements or -1 if unknown
@return whether parsing should proceed
@note binary formats may report the number of elements
*/
virtual bool start_object(std::size_t elements = no_limit) = 0;
virtual bool start_object(std::size_t elements) = 0;
/*!
@brief an object key was read
@ -93,11 +90,11 @@ struct json_sax
/*!
@brief the beginning of an array was read
@param[in] elements number of array elements or no_limit if unknown
@param[in] elements number of array elements or -1 if unknown
@return whether parsing should proceed
@note binary formats may report the number of elements
*/
virtual bool start_array(std::size_t elements = no_limit) = 0;
virtual bool start_array(std::size_t elements) = 0;
/*!
@brief the end of an array was read
@ -189,11 +186,11 @@ class json_sax_dom_parser
return true;
}
bool start_object(std::size_t len = -1)
bool start_object(std::size_t len)
{
ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
if (JSON_UNLIKELY(len != json_sax<BasicJsonType>::no_limit and len > ref_stack.back()->max_size()))
if (JSON_UNLIKELY(len != -1 and len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len)));
@ -215,11 +212,11 @@ class json_sax_dom_parser
return true;
}
bool start_array(std::size_t len = -1)
bool start_array(std::size_t len)
{
ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
if (JSON_UNLIKELY(len != json_sax<BasicJsonType>::no_limit and len > ref_stack.back()->max_size()))
if (JSON_UNLIKELY(len != -1 and len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len)));
@ -364,7 +361,7 @@ class json_sax_dom_callback_parser
return true;
}
bool start_object(std::size_t len = -1)
bool start_object(std::size_t len)
{
// check callback for object start
const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);
@ -376,7 +373,7 @@ class json_sax_dom_callback_parser
// check object limit
if (ref_stack.back())
{
if (JSON_UNLIKELY(len != json_sax<BasicJsonType>::no_limit and len > ref_stack.back()->max_size()))
if (JSON_UNLIKELY(len != -1 and len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len)));
@ -438,7 +435,7 @@ class json_sax_dom_callback_parser
return true;
}
bool start_array(std::size_t len = -1)
bool start_array(std::size_t len)
{
const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);
keep_stack.push_back(keep);
@ -449,7 +446,7 @@ class json_sax_dom_callback_parser
// check array limit
if (ref_stack.back())
{
if (JSON_UNLIKELY(len != json_sax<BasicJsonType>::no_limit and len > ref_stack.back()->max_size()))
if (JSON_UNLIKELY(len != -1 and len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len)));

View file

@ -3589,9 +3589,6 @@ struct json_sax
/// type for strings
using string_t = typename BasicJsonType::string_t;
/// constant to indicate that no size limit is given for array or object
static constexpr auto no_limit = std::size_t(-1);
/*!
@brief a null value was read
@return whether parsing should proceed
@ -3636,11 +3633,11 @@ struct json_sax
/*!
@brief the beginning of an object was read
@param[in] elements number of object elements or no_limit if unknown
@param[in] elements number of object elements or -1 if unknown
@return whether parsing should proceed
@note binary formats may report the number of elements
*/
virtual bool start_object(std::size_t elements = no_limit) = 0;
virtual bool start_object(std::size_t elements) = 0;
/*!
@brief an object key was read
@ -3657,11 +3654,11 @@ struct json_sax
/*!
@brief the beginning of an array was read
@param[in] elements number of array elements or no_limit if unknown
@param[in] elements number of array elements or -1 if unknown
@return whether parsing should proceed
@note binary formats may report the number of elements
*/
virtual bool start_array(std::size_t elements = no_limit) = 0;
virtual bool start_array(std::size_t elements) = 0;
/*!
@brief the end of an array was read
@ -3753,11 +3750,11 @@ class json_sax_dom_parser
return true;
}
bool start_object(std::size_t len = -1)
bool start_object(std::size_t len)
{
ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
if (JSON_UNLIKELY(len != json_sax<BasicJsonType>::no_limit and len > ref_stack.back()->max_size()))
if (JSON_UNLIKELY(len != -1 and len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len)));
@ -3779,11 +3776,11 @@ class json_sax_dom_parser
return true;
}
bool start_array(std::size_t len = -1)
bool start_array(std::size_t len)
{
ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
if (JSON_UNLIKELY(len != json_sax<BasicJsonType>::no_limit and len > ref_stack.back()->max_size()))
if (JSON_UNLIKELY(len != -1 and len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len)));
@ -3928,7 +3925,7 @@ class json_sax_dom_callback_parser
return true;
}
bool start_object(std::size_t len = -1)
bool start_object(std::size_t len)
{
// check callback for object start
const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);
@ -3940,7 +3937,7 @@ class json_sax_dom_callback_parser
// check object limit
if (ref_stack.back())
{
if (JSON_UNLIKELY(len != json_sax<BasicJsonType>::no_limit and len > ref_stack.back()->max_size()))
if (JSON_UNLIKELY(len != -1 and len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len)));
@ -4002,7 +3999,7 @@ class json_sax_dom_callback_parser
return true;
}
bool start_array(std::size_t len = -1)
bool start_array(std::size_t len)
{
const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);
keep_stack.push_back(keep);
@ -4013,7 +4010,7 @@ class json_sax_dom_callback_parser
// check array limit
if (ref_stack.back())
{
if (JSON_UNLIKELY(len != json_sax<BasicJsonType>::no_limit and len > ref_stack.back()->max_size()))
if (JSON_UNLIKELY(len != -1 and len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len)));

View file

@ -74,7 +74,7 @@ class SaxEventLogger
return true;
}
bool start_object(std::size_t elements = -1)
bool start_object(std::size_t elements)
{
if (elements == std::size_t(-1))
{
@ -99,7 +99,7 @@ class SaxEventLogger
return true;
}
bool start_array(std::size_t elements = -1)
bool start_array(std::size_t elements)
{
if (elements == std::size_t(-1))
{
@ -165,7 +165,7 @@ class SaxCountdown
return events_left-- > 0;
}
bool start_object(std::size_t = -1)
bool start_object(std::size_t)
{
return events_left-- > 0;
}
@ -180,7 +180,7 @@ class SaxCountdown
return events_left-- > 0;
}
bool start_array(std::size_t = -1)
bool start_array(std::size_t)
{
return events_left-- > 0;
}

View file

@ -70,7 +70,7 @@ class SaxCountdown
return events_left-- > 0;
}
bool start_object(std::size_t = -1)
bool start_object(std::size_t)
{
return events_left-- > 0;
}
@ -85,7 +85,7 @@ class SaxCountdown
return events_left-- > 0;
}
bool start_array(std::size_t = -1)
bool start_array(std::size_t)
{
return events_left-- > 0;
}