Commit d359684f by Théo DELRIEU

move enum class value_t outside of basic_json

parent 034d5ed9
...@@ -106,6 +106,46 @@ SOFTWARE. ...@@ -106,6 +106,46 @@ SOFTWARE.
*/ */
namespace nlohmann namespace nlohmann
{ {
///////////////////////////
// JSON type enumeration //
///////////////////////////
/*!
@brief the JSON type enumeration
This enumeration collects the different JSON types. It is internally used
to distinguish the stored values, and the functions @ref is_null(), @ref
is_object(), @ref is_array(), @ref is_string(), @ref is_boolean(), @ref
is_number() (with @ref is_number_integer(), @ref is_number_unsigned(), and
@ref is_number_float()), @ref is_discarded(), @ref is_primitive(), and
@ref is_structured() rely on it.
@note There are three enumeration entries (number_integer,
number_unsigned, and number_float), because the library distinguishes
these three types for numbers: @ref number_unsigned_t is used for unsigned
integers, @ref number_integer_t is used for signed integers, and @ref
number_float_t is used for floating-point numbers or to approximate
integers which do not fit in the limits of their respective type.
@sa @ref basic_json(const value_t value_type) -- create a JSON value with
the default value for a given type
@since version 1.0.0
*/
enum class value_t : uint8_t
{
null, ///< null value
object, ///< object (unordered set of name/value pairs)
array, ///< array (ordered collection of values)
string, ///< string value
boolean, ///< boolean value
number_integer, ///< number value (signed integer)
number_unsigned, ///< number value (unsigned integer)
number_float, ///< number value (floating-point)
discarded ///< discarded by the the parser callback function
};
// alias templates to reduce boilerplate // alias templates to reduce boilerplate
template <bool B, typename T = void> template <bool B, typename T = void>
using enable_if_t = typename std::enable_if<B, T>::type; using enable_if_t = typename std::enable_if<B, T>::type;
...@@ -552,6 +592,7 @@ class basic_json ...@@ -552,6 +592,7 @@ class basic_json
class primitive_iterator_t; class primitive_iterator_t;
public: public:
using value_t = ::nlohmann::value_t;
// forward declarations // forward declarations
template<typename U> class iter_impl; template<typename U> class iter_impl;
template<typename Base> class json_reverse_iterator; template<typename Base> class json_reverse_iterator;
...@@ -1102,47 +1143,6 @@ class basic_json ...@@ -1102,47 +1143,6 @@ class basic_json
/// @} /// @}
///////////////////////////
// JSON type enumeration //
///////////////////////////
/*!
@brief the JSON type enumeration
This enumeration collects the different JSON types. It is internally used
to distinguish the stored values, and the functions @ref is_null(), @ref
is_object(), @ref is_array(), @ref is_string(), @ref is_boolean(), @ref
is_number() (with @ref is_number_integer(), @ref is_number_unsigned(), and
@ref is_number_float()), @ref is_discarded(), @ref is_primitive(), and
@ref is_structured() rely on it.
@note There are three enumeration entries (number_integer,
number_unsigned, and number_float), because the library distinguishes
these three types for numbers: @ref number_unsigned_t is used for unsigned
integers, @ref number_integer_t is used for signed integers, and @ref
number_float_t is used for floating-point numbers or to approximate
integers which do not fit in the limits of their respective type.
@sa @ref basic_json(const value_t value_type) -- create a JSON value with
the default value for a given type
@since version 1.0.0
*/
enum class value_t : uint8_t
{
null, ///< null value
object, ///< object (unordered set of name/value pairs)
array, ///< array (ordered collection of values)
string, ///< string value
boolean, ///< boolean value
number_integer, ///< number value (signed integer)
number_unsigned, ///< number value (unsigned integer)
number_float, ///< number value (floating-point)
discarded ///< discarded by the the parser callback function
};
private: private:
/// helper for exception-safe object creation /// helper for exception-safe object creation
...@@ -5912,47 +5912,6 @@ class basic_json ...@@ -5912,47 +5912,6 @@ class basic_json
/// @} /// @}
//////////////////////////////////////////
// lexicographical comparison operators //
//////////////////////////////////////////
/// @name lexicographical comparison operators
/// @{
private:
/*!
@brief comparison operator for JSON types
Returns an ordering that is similar to Python:
- order: null < boolean < number < object < array < string
- furthermore, each type is not smaller than itself
@since version 1.0.0
*/
friend bool operator<(const value_t lhs, const value_t rhs) noexcept
{
static constexpr std::array<uint8_t, 8> order = {{
0, // null
3, // object
4, // array
5, // string
1, // boolean
2, // integer
2, // unsigned
2, // float
}
};
// discarded values are not comparable
if (lhs == value_t::discarded or rhs == value_t::discarded)
{
return false;
}
return order[static_cast<std::size_t>(lhs)] < order[static_cast<std::size_t>(rhs)];
}
public: public:
/*! /*!
@brief comparison: equal @brief comparison: equal
...@@ -9745,8 +9704,7 @@ class basic_json ...@@ -9745,8 +9704,7 @@ class basic_json
{ {
lexer_char_t yych; lexer_char_t yych;
unsigned int yyaccept = 0; unsigned int yyaccept = 0;
static const unsigned char yybm[] = static const unsigned char yybm[] = {
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 32, 32, 0, 0, 32, 0, 0, 0, 32, 32, 0, 0, 32, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
...@@ -9780,873 +9738,396 @@ class basic_json ...@@ -9780,873 +9738,396 @@ class basic_json
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
}; };
if ((m_limit - m_cursor) < 5) if ((m_limit - m_cursor) < 5) fill_line_buffer(5); // LCOV_EXCL_LINE
{
fill_line_buffer(5); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yybm[0 + yych] & 32) if (yybm[0+yych] & 32) {
{
goto basic_json_parser_6; goto basic_json_parser_6;
} }
if (yych <= '[') if (yych <= '[') {
{ if (yych <= '-') {
if (yych <= '-') if (yych <= '"') {
{ if (yych <= 0x00) goto basic_json_parser_2;
if (yych <= '"') if (yych <= '!') goto basic_json_parser_4;
{
if (yych <= 0x00)
{
goto basic_json_parser_2;
}
if (yych <= '!')
{
goto basic_json_parser_4;
}
goto basic_json_parser_9; goto basic_json_parser_9;
} } else {
else if (yych <= '+') goto basic_json_parser_4;
{ if (yych <= ',') goto basic_json_parser_10;
if (yych <= '+')
{
goto basic_json_parser_4;
}
if (yych <= ',')
{
goto basic_json_parser_10;
}
goto basic_json_parser_12; goto basic_json_parser_12;
} }
} } else {
else if (yych <= '9') {
{ if (yych <= '/') goto basic_json_parser_4;
if (yych <= '9') if (yych <= '0') goto basic_json_parser_13;
{
if (yych <= '/')
{
goto basic_json_parser_4;
}
if (yych <= '0')
{
goto basic_json_parser_13;
}
goto basic_json_parser_15; goto basic_json_parser_15;
} } else {
else if (yych <= ':') goto basic_json_parser_17;
{ if (yych <= 'Z') goto basic_json_parser_4;
if (yych <= ':')
{
goto basic_json_parser_17;
}
if (yych <= 'Z')
{
goto basic_json_parser_4;
}
goto basic_json_parser_19; goto basic_json_parser_19;
} }
} }
} } else {
else if (yych <= 'n') {
{ if (yych <= 'e') {
if (yych <= 'n') if (yych == ']') goto basic_json_parser_21;
{
if (yych <= 'e')
{
if (yych == ']')
{
goto basic_json_parser_21;
}
goto basic_json_parser_4;
}
else
{
if (yych <= 'f')
{
goto basic_json_parser_23;
}
if (yych <= 'm')
{
goto basic_json_parser_4; goto basic_json_parser_4;
} } else {
if (yych <= 'f') goto basic_json_parser_23;
if (yych <= 'm') goto basic_json_parser_4;
goto basic_json_parser_24; goto basic_json_parser_24;
} }
} } else {
else if (yych <= 'z') {
{ if (yych == 't') goto basic_json_parser_25;
if (yych <= 'z')
{
if (yych == 't')
{
goto basic_json_parser_25;
}
goto basic_json_parser_4; goto basic_json_parser_4;
} } else {
else if (yych <= '{') goto basic_json_parser_26;
{ if (yych == '}') goto basic_json_parser_28;
if (yych <= '{')
{
goto basic_json_parser_26;
}
if (yych == '}')
{
goto basic_json_parser_28;
}
goto basic_json_parser_4; goto basic_json_parser_4;
} }
} }
} }
basic_json_parser_2: basic_json_parser_2:
++m_cursor; ++m_cursor;
{ { last_token_type = token_type::end_of_input; break; }
last_token_type = token_type::end_of_input;
break;
}
basic_json_parser_4: basic_json_parser_4:
++m_cursor; ++m_cursor;
basic_json_parser_5: basic_json_parser_5:
{ { last_token_type = token_type::parse_error; break; }
last_token_type = token_type::parse_error;
break;
}
basic_json_parser_6: basic_json_parser_6:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yybm[0 + yych] & 32) if (yybm[0+yych] & 32) {
{
goto basic_json_parser_6; goto basic_json_parser_6;
} }
{ { continue; }
continue;
}
basic_json_parser_9: basic_json_parser_9:
yyaccept = 0; yyaccept = 0;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
if (yych <= 0x1F) if (yych <= 0x1F) goto basic_json_parser_5;
{ if (yych <= 0x7F) goto basic_json_parser_31;
goto basic_json_parser_5; if (yych <= 0xC1) goto basic_json_parser_5;
} if (yych <= 0xF4) goto basic_json_parser_31;
if (yych <= 0x7F)
{
goto basic_json_parser_31;
}
if (yych <= 0xC1)
{
goto basic_json_parser_5;
}
if (yych <= 0xF4)
{
goto basic_json_parser_31;
}
goto basic_json_parser_5; goto basic_json_parser_5;
basic_json_parser_10: basic_json_parser_10:
++m_cursor; ++m_cursor;
{ { last_token_type = token_type::value_separator; break; }
last_token_type = token_type::value_separator;
break;
}
basic_json_parser_12: basic_json_parser_12:
yych = *++m_cursor; yych = *++m_cursor;
if (yych <= '/') if (yych <= '/') goto basic_json_parser_5;
{ if (yych <= '0') goto basic_json_parser_13;
goto basic_json_parser_5; if (yych <= '9') goto basic_json_parser_15;
}
if (yych <= '0')
{
goto basic_json_parser_13;
}
if (yych <= '9')
{
goto basic_json_parser_15;
}
goto basic_json_parser_5; goto basic_json_parser_5;
basic_json_parser_13: basic_json_parser_13:
yyaccept = 1; yyaccept = 1;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
if (yych <= 'D') if (yych <= 'D') {
{ if (yych == '.') goto basic_json_parser_43;
if (yych == '.') } else {
{ if (yych <= 'E') goto basic_json_parser_44;
goto basic_json_parser_43; if (yych == 'e') goto basic_json_parser_44;
}
}
else
{
if (yych <= 'E')
{
goto basic_json_parser_44;
}
if (yych == 'e')
{
goto basic_json_parser_44;
}
} }
basic_json_parser_14: basic_json_parser_14:
{ { last_token_type = token_type::value_number; break; }
last_token_type = token_type::value_number;
break;
}
basic_json_parser_15: basic_json_parser_15:
yyaccept = 1; yyaccept = 1;
m_marker = ++m_cursor; m_marker = ++m_cursor;
if ((m_limit - m_cursor) < 3) if ((m_limit - m_cursor) < 3) fill_line_buffer(3); // LCOV_EXCL_LINE
{
fill_line_buffer(3); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yybm[0 + yych] & 64) if (yybm[0+yych] & 64) {
{
goto basic_json_parser_15; goto basic_json_parser_15;
} }
if (yych <= 'D') if (yych <= 'D') {
{ if (yych == '.') goto basic_json_parser_43;
if (yych == '.')
{
goto basic_json_parser_43;
}
goto basic_json_parser_14; goto basic_json_parser_14;
} } else {
else if (yych <= 'E') goto basic_json_parser_44;
{ if (yych == 'e') goto basic_json_parser_44;
if (yych <= 'E')
{
goto basic_json_parser_44;
}
if (yych == 'e')
{
goto basic_json_parser_44;
}
goto basic_json_parser_14; goto basic_json_parser_14;
} }
basic_json_parser_17: basic_json_parser_17:
++m_cursor; ++m_cursor;
{ { last_token_type = token_type::name_separator; break; }
last_token_type = token_type::name_separator;
break;
}
basic_json_parser_19: basic_json_parser_19:
++m_cursor; ++m_cursor;
{ { last_token_type = token_type::begin_array; break; }
last_token_type = token_type::begin_array;
break;
}
basic_json_parser_21: basic_json_parser_21:
++m_cursor; ++m_cursor;
{ { last_token_type = token_type::end_array; break; }
last_token_type = token_type::end_array;
break;
}
basic_json_parser_23: basic_json_parser_23:
yyaccept = 0; yyaccept = 0;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
if (yych == 'a') if (yych == 'a') goto basic_json_parser_45;
{
goto basic_json_parser_45;
}
goto basic_json_parser_5; goto basic_json_parser_5;
basic_json_parser_24: basic_json_parser_24:
yyaccept = 0; yyaccept = 0;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
if (yych == 'u') if (yych == 'u') goto basic_json_parser_46;
{
goto basic_json_parser_46;
}
goto basic_json_parser_5; goto basic_json_parser_5;
basic_json_parser_25: basic_json_parser_25:
yyaccept = 0; yyaccept = 0;
yych = *(m_marker = ++m_cursor); yych = *(m_marker = ++m_cursor);
if (yych == 'r') if (yych == 'r') goto basic_json_parser_47;
{
goto basic_json_parser_47;
}
goto basic_json_parser_5; goto basic_json_parser_5;
basic_json_parser_26: basic_json_parser_26:
++m_cursor; ++m_cursor;
{ { last_token_type = token_type::begin_object; break; }
last_token_type = token_type::begin_object;
break;
}
basic_json_parser_28: basic_json_parser_28:
++m_cursor; ++m_cursor;
{ { last_token_type = token_type::end_object; break; }
last_token_type = token_type::end_object;
break;
}
basic_json_parser_30: basic_json_parser_30:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
basic_json_parser_31: basic_json_parser_31:
if (yybm[0 + yych] & 128) if (yybm[0+yych] & 128) {
{
goto basic_json_parser_30; goto basic_json_parser_30;
} }
if (yych <= 0xE0) if (yych <= 0xE0) {
{ if (yych <= '\\') {
if (yych <= '\\') if (yych <= 0x1F) goto basic_json_parser_32;
{ if (yych <= '"') goto basic_json_parser_33;
if (yych <= 0x1F)
{
goto basic_json_parser_32;
}
if (yych <= '"')
{
goto basic_json_parser_33;
}
goto basic_json_parser_35; goto basic_json_parser_35;
} } else {
else if (yych <= 0xC1) goto basic_json_parser_32;
{ if (yych <= 0xDF) goto basic_json_parser_36;
if (yych <= 0xC1)
{
goto basic_json_parser_32;
}
if (yych <= 0xDF)
{
goto basic_json_parser_36;
}
goto basic_json_parser_37; goto basic_json_parser_37;
} }
} } else {
else if (yych <= 0xEF) {
{ if (yych == 0xED) goto basic_json_parser_39;
if (yych <= 0xEF)
{
if (yych == 0xED)
{
goto basic_json_parser_39;
}
goto basic_json_parser_38; goto basic_json_parser_38;
} } else {
else if (yych <= 0xF0) goto basic_json_parser_40;
{ if (yych <= 0xF3) goto basic_json_parser_41;
if (yych <= 0xF0) if (yych <= 0xF4) goto basic_json_parser_42;
{
goto basic_json_parser_40;
}
if (yych <= 0xF3)
{
goto basic_json_parser_41;
}
if (yych <= 0xF4)
{
goto basic_json_parser_42;
}
} }
} }
basic_json_parser_32: basic_json_parser_32:
m_cursor = m_marker; m_cursor = m_marker;
if (yyaccept == 0) if (yyaccept == 0) {
{
goto basic_json_parser_5; goto basic_json_parser_5;
} } else {
else
{
goto basic_json_parser_14; goto basic_json_parser_14;
} }
basic_json_parser_33: basic_json_parser_33:
++m_cursor; ++m_cursor;
{ { last_token_type = token_type::value_string; break; }
last_token_type = token_type::value_string;
break;
}
basic_json_parser_35: basic_json_parser_35:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 'e') if (yych <= 'e') {
{ if (yych <= '/') {
if (yych <= '/') if (yych == '"') goto basic_json_parser_30;
{ if (yych <= '.') goto basic_json_parser_32;
if (yych == '"')
{
goto basic_json_parser_30; goto basic_json_parser_30;
} } else {
if (yych <= '.') if (yych <= '\\') {
{ if (yych <= '[') goto basic_json_parser_32;
goto basic_json_parser_32;
}
goto basic_json_parser_30; goto basic_json_parser_30;
} } else {
else if (yych == 'b') goto basic_json_parser_30;
{
if (yych <= '\\')
{
if (yych <= '[')
{
goto basic_json_parser_32; goto basic_json_parser_32;
} }
goto basic_json_parser_30;
}
else
{
if (yych == 'b')
{
goto basic_json_parser_30;
} }
} else {
if (yych <= 'q') {
if (yych <= 'f') goto basic_json_parser_30;
if (yych == 'n') goto basic_json_parser_30;
goto basic_json_parser_32; goto basic_json_parser_32;
} } else {
} if (yych <= 's') {
} if (yych <= 'r') goto basic_json_parser_30;
else
{
if (yych <= 'q')
{
if (yych <= 'f')
{
goto basic_json_parser_30;
}
if (yych == 'n')
{
goto basic_json_parser_30;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} } else {
else if (yych <= 't') goto basic_json_parser_30;
{ if (yych <= 'u') goto basic_json_parser_48;
if (yych <= 's')
{
if (yych <= 'r')
{
goto basic_json_parser_30;
}
goto basic_json_parser_32;
}
else
{
if (yych <= 't')
{
goto basic_json_parser_30;
}
if (yych <= 'u')
{
goto basic_json_parser_48;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} }
} }
} }
basic_json_parser_36: basic_json_parser_36:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 0x7F) if (yych <= 0x7F) goto basic_json_parser_32;
{ if (yych <= 0xBF) goto basic_json_parser_30;
goto basic_json_parser_32;
}
if (yych <= 0xBF)
{
goto basic_json_parser_30;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_37: basic_json_parser_37:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 0x9F) if (yych <= 0x9F) goto basic_json_parser_32;
{ if (yych <= 0xBF) goto basic_json_parser_36;
goto basic_json_parser_32;
}
if (yych <= 0xBF)
{
goto basic_json_parser_36;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_38: basic_json_parser_38:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 0x7F) if (yych <= 0x7F) goto basic_json_parser_32;
{ if (yych <= 0xBF) goto basic_json_parser_36;
goto basic_json_parser_32;
}
if (yych <= 0xBF)
{
goto basic_json_parser_36;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_39: basic_json_parser_39:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 0x7F) if (yych <= 0x7F) goto basic_json_parser_32;
{ if (yych <= 0x9F) goto basic_json_parser_36;
goto basic_json_parser_32;
}
if (yych <= 0x9F)
{
goto basic_json_parser_36;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_40: basic_json_parser_40:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 0x8F) if (yych <= 0x8F) goto basic_json_parser_32;
{ if (yych <= 0xBF) goto basic_json_parser_38;
goto basic_json_parser_32;
}
if (yych <= 0xBF)
{
goto basic_json_parser_38;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_41: basic_json_parser_41:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 0x7F) if (yych <= 0x7F) goto basic_json_parser_32;
{ if (yych <= 0xBF) goto basic_json_parser_38;
goto basic_json_parser_32;
}
if (yych <= 0xBF)
{
goto basic_json_parser_38;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_42: basic_json_parser_42:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 0x7F) if (yych <= 0x7F) goto basic_json_parser_32;
{ if (yych <= 0x8F) goto basic_json_parser_38;
goto basic_json_parser_32;
}
if (yych <= 0x8F)
{
goto basic_json_parser_38;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_43: basic_json_parser_43:
yych = *++m_cursor; yych = *++m_cursor;
if (yych <= '/') if (yych <= '/') goto basic_json_parser_32;
{ if (yych <= '9') goto basic_json_parser_49;
goto basic_json_parser_32;
}
if (yych <= '9')
{
goto basic_json_parser_49;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_44: basic_json_parser_44:
yych = *++m_cursor; yych = *++m_cursor;
if (yych <= ',') if (yych <= ',') {
{ if (yych == '+') goto basic_json_parser_51;
if (yych == '+')
{
goto basic_json_parser_51;
}
goto basic_json_parser_32;
}
else
{
if (yych <= '-')
{
goto basic_json_parser_51;
}
if (yych <= '/')
{
goto basic_json_parser_32; goto basic_json_parser_32;
} } else {
if (yych <= '9') if (yych <= '-') goto basic_json_parser_51;
{ if (yych <= '/') goto basic_json_parser_32;
goto basic_json_parser_52; if (yych <= '9') goto basic_json_parser_52;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} }
basic_json_parser_45: basic_json_parser_45:
yych = *++m_cursor; yych = *++m_cursor;
if (yych == 'l') if (yych == 'l') goto basic_json_parser_54;
{
goto basic_json_parser_54;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_46: basic_json_parser_46:
yych = *++m_cursor; yych = *++m_cursor;
if (yych == 'l') if (yych == 'l') goto basic_json_parser_55;
{
goto basic_json_parser_55;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_47: basic_json_parser_47:
yych = *++m_cursor; yych = *++m_cursor;
if (yych == 'u') if (yych == 'u') goto basic_json_parser_56;
{
goto basic_json_parser_56;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_48: basic_json_parser_48:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= '@') if (yych <= '@') {
{ if (yych <= '/') goto basic_json_parser_32;
if (yych <= '/') if (yych <= '9') goto basic_json_parser_57;
{
goto basic_json_parser_32;
}
if (yych <= '9')
{
goto basic_json_parser_57;
}
goto basic_json_parser_32;
}
else
{
if (yych <= 'F')
{
goto basic_json_parser_57;
}
if (yych <= '`')
{
goto basic_json_parser_32; goto basic_json_parser_32;
} } else {
if (yych <= 'f') if (yych <= 'F') goto basic_json_parser_57;
{ if (yych <= '`') goto basic_json_parser_32;
goto basic_json_parser_57; if (yych <= 'f') goto basic_json_parser_57;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} }
basic_json_parser_49: basic_json_parser_49:
yyaccept = 1; yyaccept = 1;
m_marker = ++m_cursor; m_marker = ++m_cursor;
if ((m_limit - m_cursor) < 3) if ((m_limit - m_cursor) < 3) fill_line_buffer(3); // LCOV_EXCL_LINE
{
fill_line_buffer(3); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= 'D') if (yych <= 'D') {
{ if (yych <= '/') goto basic_json_parser_14;
if (yych <= '/') if (yych <= '9') goto basic_json_parser_49;
{
goto basic_json_parser_14; goto basic_json_parser_14;
} } else {
if (yych <= '9') if (yych <= 'E') goto basic_json_parser_44;
{ if (yych == 'e') goto basic_json_parser_44;
goto basic_json_parser_49;
}
goto basic_json_parser_14;
}
else
{
if (yych <= 'E')
{
goto basic_json_parser_44;
}
if (yych == 'e')
{
goto basic_json_parser_44;
}
goto basic_json_parser_14; goto basic_json_parser_14;
} }
basic_json_parser_51: basic_json_parser_51:
yych = *++m_cursor; yych = *++m_cursor;
if (yych <= '/') if (yych <= '/') goto basic_json_parser_32;
{ if (yych >= ':') goto basic_json_parser_32;
goto basic_json_parser_32;
}
if (yych >= ':')
{
goto basic_json_parser_32;
}
basic_json_parser_52: basic_json_parser_52:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= '/') if (yych <= '/') goto basic_json_parser_14;
{ if (yych <= '9') goto basic_json_parser_52;
goto basic_json_parser_14;
}
if (yych <= '9')
{
goto basic_json_parser_52;
}
goto basic_json_parser_14; goto basic_json_parser_14;
basic_json_parser_54: basic_json_parser_54:
yych = *++m_cursor; yych = *++m_cursor;
if (yych == 's') if (yych == 's') goto basic_json_parser_58;
{
goto basic_json_parser_58;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_55: basic_json_parser_55:
yych = *++m_cursor; yych = *++m_cursor;
if (yych == 'l') if (yych == 'l') goto basic_json_parser_59;
{
goto basic_json_parser_59;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_56: basic_json_parser_56:
yych = *++m_cursor; yych = *++m_cursor;
if (yych == 'e') if (yych == 'e') goto basic_json_parser_61;
{
goto basic_json_parser_61;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_57: basic_json_parser_57:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= '@') if (yych <= '@') {
{ if (yych <= '/') goto basic_json_parser_32;
if (yych <= '/') if (yych <= '9') goto basic_json_parser_63;
{
goto basic_json_parser_32;
}
if (yych <= '9')
{
goto basic_json_parser_63;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} } else {
else if (yych <= 'F') goto basic_json_parser_63;
{ if (yych <= '`') goto basic_json_parser_32;
if (yych <= 'F') if (yych <= 'f') goto basic_json_parser_63;
{
goto basic_json_parser_63;
}
if (yych <= '`')
{
goto basic_json_parser_32;
}
if (yych <= 'f')
{
goto basic_json_parser_63;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} }
basic_json_parser_58: basic_json_parser_58:
yych = *++m_cursor; yych = *++m_cursor;
if (yych == 'e') if (yych == 'e') goto basic_json_parser_64;
{
goto basic_json_parser_64;
}
goto basic_json_parser_32; goto basic_json_parser_32;
basic_json_parser_59: basic_json_parser_59:
++m_cursor; ++m_cursor;
{ { last_token_type = token_type::literal_null; break; }
last_token_type = token_type::literal_null;
break;
}
basic_json_parser_61: basic_json_parser_61:
++m_cursor; ++m_cursor;
{ { last_token_type = token_type::literal_true; break; }
last_token_type = token_type::literal_true;
break;
}
basic_json_parser_63: basic_json_parser_63:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= '@') if (yych <= '@') {
{ if (yych <= '/') goto basic_json_parser_32;
if (yych <= '/') if (yych <= '9') goto basic_json_parser_66;
{
goto basic_json_parser_32;
}
if (yych <= '9')
{
goto basic_json_parser_66;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} } else {
else if (yych <= 'F') goto basic_json_parser_66;
{ if (yych <= '`') goto basic_json_parser_32;
if (yych <= 'F') if (yych <= 'f') goto basic_json_parser_66;
{
goto basic_json_parser_66;
}
if (yych <= '`')
{
goto basic_json_parser_32;
}
if (yych <= 'f')
{
goto basic_json_parser_66;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} }
basic_json_parser_64: basic_json_parser_64:
++m_cursor; ++m_cursor;
{ { last_token_type = token_type::literal_false; break; }
last_token_type = token_type::literal_false;
break;
}
basic_json_parser_66: basic_json_parser_66:
++m_cursor; ++m_cursor;
if (m_limit <= m_cursor) if (m_limit <= m_cursor) fill_line_buffer(1); // LCOV_EXCL_LINE
{
fill_line_buffer(1); // LCOV_EXCL_LINE
}
yych = *m_cursor; yych = *m_cursor;
if (yych <= '@') if (yych <= '@') {
{ if (yych <= '/') goto basic_json_parser_32;
if (yych <= '/') if (yych <= '9') goto basic_json_parser_30;
{
goto basic_json_parser_32; goto basic_json_parser_32;
} } else {
if (yych <= '9') if (yych <= 'F') goto basic_json_parser_30;
{ if (yych <= '`') goto basic_json_parser_32;
goto basic_json_parser_30; if (yych <= 'f') goto basic_json_parser_30;
}
goto basic_json_parser_32;
}
else
{
if (yych <= 'F')
{
goto basic_json_parser_30;
}
if (yych <= '`')
{
goto basic_json_parser_32;
}
if (yych <= 'f')
{
goto basic_json_parser_30;
}
goto basic_json_parser_32; goto basic_json_parser_32;
} }
} }
...@@ -12666,6 +12147,43 @@ basic_json_parser_66: ...@@ -12666,6 +12147,43 @@ basic_json_parser_66:
/// @} /// @}
}; };
//////////////////////////////////////////
// lexicographical comparison operators //
//////////////////////////////////////////
/// @name lexicographical comparison operators
/// @{
/*!
@brief comparison operator for JSON types
Returns an ordering that is similar to Python:
- order: null < boolean < number < object < array < string
- furthermore, each type is not smaller than itself
@since version 1.0.0
*/
inline bool operator<(const value_t lhs, const value_t rhs) noexcept
{
static constexpr std::array<uint8_t, 8> order = {{
0, // null
3, // object
4, // array
5, // string
1, // boolean
2, // integer
2, // unsigned
2, // float
}};
// discarded values are not comparable
if (lhs == value_t::discarded or rhs == value_t::discarded)
{
return false;
}
return order[static_cast<std::size_t>(lhs)] <
order[static_cast<std::size_t>(rhs)];
}
///////////// /////////////
// presets // // presets //
......
...@@ -106,6 +106,46 @@ SOFTWARE. ...@@ -106,6 +106,46 @@ SOFTWARE.
*/ */
namespace nlohmann namespace nlohmann
{ {
///////////////////////////
// JSON type enumeration //
///////////////////////////
/*!
@brief the JSON type enumeration
This enumeration collects the different JSON types. It is internally used
to distinguish the stored values, and the functions @ref is_null(), @ref
is_object(), @ref is_array(), @ref is_string(), @ref is_boolean(), @ref
is_number() (with @ref is_number_integer(), @ref is_number_unsigned(), and
@ref is_number_float()), @ref is_discarded(), @ref is_primitive(), and
@ref is_structured() rely on it.
@note There are three enumeration entries (number_integer,
number_unsigned, and number_float), because the library distinguishes
these three types for numbers: @ref number_unsigned_t is used for unsigned
integers, @ref number_integer_t is used for signed integers, and @ref
number_float_t is used for floating-point numbers or to approximate
integers which do not fit in the limits of their respective type.
@sa @ref basic_json(const value_t value_type) -- create a JSON value with
the default value for a given type
@since version 1.0.0
*/
enum class value_t : uint8_t
{
null, ///< null value
object, ///< object (unordered set of name/value pairs)
array, ///< array (ordered collection of values)
string, ///< string value
boolean, ///< boolean value
number_integer, ///< number value (signed integer)
number_unsigned, ///< number value (unsigned integer)
number_float, ///< number value (floating-point)
discarded ///< discarded by the the parser callback function
};
// alias templates to reduce boilerplate // alias templates to reduce boilerplate
template <bool B, typename T = void> template <bool B, typename T = void>
using enable_if_t = typename std::enable_if<B, T>::type; using enable_if_t = typename std::enable_if<B, T>::type;
...@@ -553,6 +593,7 @@ class basic_json ...@@ -553,6 +593,7 @@ class basic_json
class primitive_iterator_t; class primitive_iterator_t;
public: public:
using value_t = ::nlohmann::value_t;
// forward declarations // forward declarations
template<typename U> class iter_impl; template<typename U> class iter_impl;
template<typename Base> class json_reverse_iterator; template<typename Base> class json_reverse_iterator;
...@@ -1103,47 +1144,6 @@ class basic_json ...@@ -1103,47 +1144,6 @@ class basic_json
/// @} /// @}
///////////////////////////
// JSON type enumeration //
///////////////////////////
/*!
@brief the JSON type enumeration
This enumeration collects the different JSON types. It is internally used
to distinguish the stored values, and the functions @ref is_null(), @ref
is_object(), @ref is_array(), @ref is_string(), @ref is_boolean(), @ref
is_number() (with @ref is_number_integer(), @ref is_number_unsigned(), and
@ref is_number_float()), @ref is_discarded(), @ref is_primitive(), and
@ref is_structured() rely on it.
@note There are three enumeration entries (number_integer,
number_unsigned, and number_float), because the library distinguishes
these three types for numbers: @ref number_unsigned_t is used for unsigned
integers, @ref number_integer_t is used for signed integers, and @ref
number_float_t is used for floating-point numbers or to approximate
integers which do not fit in the limits of their respective type.
@sa @ref basic_json(const value_t value_type) -- create a JSON value with
the default value for a given type
@since version 1.0.0
*/
enum class value_t : uint8_t
{
null, ///< null value
object, ///< object (unordered set of name/value pairs)
array, ///< array (ordered collection of values)
string, ///< string value
boolean, ///< boolean value
number_integer, ///< number value (signed integer)
number_unsigned, ///< number value (unsigned integer)
number_float, ///< number value (floating-point)
discarded ///< discarded by the the parser callback function
};
private: private:
/// helper for exception-safe object creation /// helper for exception-safe object creation
...@@ -5910,47 +5910,6 @@ class basic_json ...@@ -5910,47 +5910,6 @@ class basic_json
/// @} /// @}
//////////////////////////////////////////
// lexicographical comparison operators //
//////////////////////////////////////////
/// @name lexicographical comparison operators
/// @{
private:
/*!
@brief comparison operator for JSON types
Returns an ordering that is similar to Python:
- order: null < boolean < number < object < array < string
- furthermore, each type is not smaller than itself
@since version 1.0.0
*/
friend bool operator<(const value_t lhs, const value_t rhs) noexcept
{
static constexpr std::array<uint8_t, 8> order = {{
0, // null
3, // object
4, // array
5, // string
1, // boolean
2, // integer
2, // unsigned
2, // float
}
};
// discarded values are not comparable
if (lhs == value_t::discarded or rhs == value_t::discarded)
{
return false;
}
return order[static_cast<std::size_t>(lhs)] < order[static_cast<std::size_t>(rhs)];
}
public: public:
/*! /*!
@brief comparison: equal @brief comparison: equal
...@@ -11814,6 +11773,43 @@ class basic_json ...@@ -11814,6 +11773,43 @@ class basic_json
/// @} /// @}
}; };
//////////////////////////////////////////
// lexicographical comparison operators //
//////////////////////////////////////////
/// @name lexicographical comparison operators
/// @{
/*!
@brief comparison operator for JSON types
Returns an ordering that is similar to Python:
- order: null < boolean < number < object < array < string
- furthermore, each type is not smaller than itself
@since version 1.0.0
*/
inline bool operator<(const value_t lhs, const value_t rhs) noexcept
{
static constexpr std::array<uint8_t, 8> order = {{
0, // null
3, // object
4, // array
5, // string
1, // boolean
2, // integer
2, // unsigned
2, // float
}};
// discarded values are not comparable
if (lhs == value_t::discarded or rhs == value_t::discarded)
{
return false;
}
return order[static_cast<std::size_t>(lhs)] <
order[static_cast<std::size_t>(rhs)];
}
///////////// /////////////
// presets // // presets //
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment