move enum class value_t outside of basic_json
This commit is contained in:
parent
034d5ed97e
commit
d359684f2b
2 changed files with 556 additions and 1042 deletions
1438
src/json.hpp
1438
src/json.hpp
File diff suppressed because it is too large
Load diff
|
@ -106,6 +106,46 @@ SOFTWARE.
|
|||
*/
|
||||
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
|
||||
template <bool B, typename T = void>
|
||||
using enable_if_t = typename std::enable_if<B, T>::type;
|
||||
|
@ -553,6 +593,7 @@ class basic_json
|
|||
class primitive_iterator_t;
|
||||
|
||||
public:
|
||||
using value_t = ::nlohmann::value_t;
|
||||
// forward declarations
|
||||
template<typename U> class iter_impl;
|
||||
template<typename Base> class json_reverse_iterator;
|
||||
|
@ -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:
|
||||
|
||||
/// helper for exception-safe object creation
|
||||
|
@ -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:
|
||||
/*!
|
||||
@brief comparison: equal
|
||||
|
@ -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 //
|
||||
|
|
Loading…
Reference in a new issue