Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:44:47

0001 //     __ _____ _____ _____
0002 //  __|  |   __|     |   | |  JSON for Modern C++
0003 // |  |  |__   |  |  | | | |  version 3.11.2
0004 // |_____|_____|_____|_|___|  https://github.com/nlohmann/json
0005 //
0006 // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
0007 // SPDX-License-Identifier: MIT
0008 
0009 #pragma once
0010 
0011 #include <array> // array
0012 #include <cstddef> // size_t
0013 #include <cstdint> // uint8_t
0014 #include <string> // string
0015 
0016 #include <nlohmann/detail/macro_scope.hpp>
0017 #if JSON_HAS_THREE_WAY_COMPARISON
0018     #include <compare> // partial_ordering
0019 #endif
0020 
0021 NLOHMANN_JSON_NAMESPACE_BEGIN
0022 namespace detail
0023 {
0024 
0025 ///////////////////////////
0026 // JSON type enumeration //
0027 ///////////////////////////
0028 
0029 /*!
0030 @brief the JSON type enumeration
0031 
0032 This enumeration collects the different JSON types. It is internally used to
0033 distinguish the stored values, and the functions @ref basic_json::is_null(),
0034 @ref basic_json::is_object(), @ref basic_json::is_array(),
0035 @ref basic_json::is_string(), @ref basic_json::is_boolean(),
0036 @ref basic_json::is_number() (with @ref basic_json::is_number_integer(),
0037 @ref basic_json::is_number_unsigned(), and @ref basic_json::is_number_float()),
0038 @ref basic_json::is_discarded(), @ref basic_json::is_primitive(), and
0039 @ref basic_json::is_structured() rely on it.
0040 
0041 @note There are three enumeration entries (number_integer, number_unsigned, and
0042 number_float), because the library distinguishes these three types for numbers:
0043 @ref basic_json::number_unsigned_t is used for unsigned integers,
0044 @ref basic_json::number_integer_t is used for signed integers, and
0045 @ref basic_json::number_float_t is used for floating-point numbers or to
0046 approximate integers which do not fit in the limits of their respective type.
0047 
0048 @sa see @ref basic_json::basic_json(const value_t value_type) -- create a JSON
0049 value with the default value for a given type
0050 
0051 @since version 1.0.0
0052 */
0053 enum class value_t : std::uint8_t
0054 {
0055     null,             ///< null value
0056     object,           ///< object (unordered set of name/value pairs)
0057     array,            ///< array (ordered collection of values)
0058     string,           ///< string value
0059     boolean,          ///< boolean value
0060     number_integer,   ///< number value (signed integer)
0061     number_unsigned,  ///< number value (unsigned integer)
0062     number_float,     ///< number value (floating-point)
0063     binary,           ///< binary array (ordered collection of bytes)
0064     discarded         ///< discarded by the parser callback function
0065 };
0066 
0067 /*!
0068 @brief comparison operator for JSON types
0069 
0070 Returns an ordering that is similar to Python:
0071 - order: null < boolean < number < object < array < string < binary
0072 - furthermore, each type is not smaller than itself
0073 - discarded values are not comparable
0074 - binary is represented as a b"" string in python and directly comparable to a
0075   string; however, making a binary array directly comparable with a string would
0076   be surprising behavior in a JSON file.
0077 
0078 @since version 1.0.0
0079 */
0080 #if JSON_HAS_THREE_WAY_COMPARISON
0081     inline std::partial_ordering operator<=>(const value_t lhs, const value_t rhs) noexcept // *NOPAD*
0082 #else
0083     inline bool operator<(const value_t lhs, const value_t rhs) noexcept
0084 #endif
0085 {
0086     static constexpr std::array<std::uint8_t, 9> order = {{
0087             0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */,
0088             1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */,
0089             6 /* binary */
0090         }
0091     };
0092 
0093     const auto l_index = static_cast<std::size_t>(lhs);
0094     const auto r_index = static_cast<std::size_t>(rhs);
0095 #if JSON_HAS_THREE_WAY_COMPARISON
0096     if (l_index < order.size() && r_index < order.size())
0097     {
0098         return order[l_index] <=> order[r_index]; // *NOPAD*
0099     }
0100     return std::partial_ordering::unordered;
0101 #else
0102     return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
0103 #endif
0104 }
0105 
0106 // GCC selects the built-in operator< over an operator rewritten from
0107 // a user-defined spaceship operator
0108 // Clang, MSVC, and ICC select the rewritten candidate
0109 // (see GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105200)
0110 #if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__)
0111 inline bool operator<(const value_t lhs, const value_t rhs) noexcept
0112 {
0113     return std::is_lt(lhs <=> rhs); // *NOPAD*
0114 }
0115 #endif
0116 
0117 }  // namespace detail
0118 NLOHMANN_JSON_NAMESPACE_END