From 718112a61dc44faa1847136d8d4c672ef875c46d Mon Sep 17 00:00:00 2001 From: mrabine Date: Mon, 26 Oct 2026 13:49:26 +0100 Subject: [PATCH] Rename value index enum --- data/include/join/document.hpp | 14 +- data/include/join/json.hpp | 2 +- data/include/join/pack.hpp | 14 +- data/include/join/value.hpp | 500 +++++++++++++++++---------------- data/tests/document_test.cpp | 16 +- data/tests/value_test.cpp | 164 +++++------ 6 files changed, 368 insertions(+), 342 deletions(-) diff --git a/data/include/join/document.hpp b/data/include/join/document.hpp index 7959c2d9..e4f8991e 100644 --- a/data/include/join/document.hpp +++ b/data/include/join/document.hpp @@ -395,25 +395,25 @@ namespace join { switch (value.index ()) { - case Value::Boolean: + case Value::BooleanValue: return handler.setBool (value.getBool ()); - case Value::Integer: + case Value::IntegerValue: return handler.setInt (value.getInt ()); - case Value::Unsigned: + case Value::UnsignedValue: return handler.setUint (value.getUint ()); - case Value::Integer64: + case Value::Integer64Value: return handler.setInt64 (value.getInt64 ()); - case Value::Unsigned64: + case Value::Unsigned64Value: return handler.setUint64 (value.getUint64 ()); - case Value::Real: + case Value::RealValue: return handler.setDouble (value.getDouble ()); - case Value::String: + case Value::StringValue: return handler.setString (value.getString ()); case Value::ArrayValue: diff --git a/data/include/join/json.hpp b/data/include/join/json.hpp index 03e25394..9d0b5b65 100644 --- a/data/include/join/json.hpp +++ b/data/include/join/json.hpp @@ -1868,7 +1868,7 @@ namespace join if (JOIN_LIKELY (document.peek () == '"')) { document.get (); - return isKey ? handler.setKey (Value (std::string (chunk))) : handler.setString (chunk); + return isKey ? handler.setKey (Value (chunk)) : handler.setString (chunk); } } diff --git a/data/include/join/pack.hpp b/data/include/join/pack.hpp index c83cf422..37bf518b 100644 --- a/data/include/join/pack.hpp +++ b/data/include/join/pack.hpp @@ -433,25 +433,25 @@ namespace join } switch (key.index ()) { - case Value::Boolean: + case Value::BooleanValue: return setBool (key.getBool ()); - case Value::Integer: + case Value::IntegerValue: return setInt (key.getInt ()); - case Value::Unsigned: + case Value::UnsignedValue: return setUint (key.getUint ()); - case Value::Integer64: + case Value::Integer64Value: return setInt64 (key.getInt64 ()); - case Value::Unsigned64: + case Value::Unsigned64Value: return setUint64 (key.getUint64 ()); - case Value::Real: + case Value::RealValue: return setDouble (key.getDouble ()); - case Value::String: + case Value::StringValue: return setString (key.getString ()); default: diff --git a/data/include/join/value.hpp b/data/include/join/value.hpp index dbdb3d7f..3d152225 100644 --- a/data/include/join/value.hpp +++ b/data/include/join/value.hpp @@ -30,6 +30,7 @@ #include // C++. +#include #include #include #include @@ -68,16 +69,16 @@ namespace join */ enum Index : size_t { - Null = 0, /**< index of the std::nullptr_t alternative. */ - Boolean = 1, /**< index of the boolean alternative. */ - Integer = 2, /**< index of the 32 bits integer alternative. */ - Unsigned = 3, /**< index of the 32 bits unsigned integer alternative. */ - Integer64 = 4, /**< index of the 64 bits integer alternative. */ - Unsigned64 = 5, /**< index of the 64 bits unsigned integer alternative. */ - Real = 6, /**< index of the real alternative. */ - String = 7, /**< index of the std::string alternative. */ - ArrayValue = 8, /**< index of the Array alternative. */ - ObjectValue = 9, /**< index of the Object alternative. */ + NullValue = 0, /**< index of the std::nullptr_t alternative. */ + BooleanValue = 1, /**< index of the boolean alternative. */ + IntegerValue = 2, /**< index of the 32 bits integer alternative. */ + UnsignedValue = 3, /**< index of the 32 bits unsigned integer alternative. */ + Integer64Value = 4, /**< index of the 64 bits integer alternative. */ + Unsigned64Value = 5, /**< index of the 64 bits unsigned integer alternative. */ + RealValue = 6, /**< index of the real alternative. */ + StringValue = 7, /**< index of the std::string alternative. */ + ArrayValue = 8, /**< index of the Array alternative. */ + ObjectValue = 9, /**< index of the Object alternative. */ }; /** @@ -90,7 +91,7 @@ namespace join * @param value null value. */ constexpr Value (std::nullptr_t value) - : _data (std::in_place_index, value) + : _data (std::in_place_index, value) { } @@ -99,7 +100,7 @@ namespace join * @param value boolean value. */ constexpr Value (bool value) - : _data (std::in_place_index, value) + : _data (std::in_place_index, value) { } @@ -108,7 +109,7 @@ namespace join * @param value integer value. */ constexpr Value (int32_t value) - : _data (std::in_place_index, value) + : _data (std::in_place_index, value) { } @@ -117,7 +118,7 @@ namespace join * @param value unsigned integer value. */ constexpr Value (uint32_t value) - : _data (std::in_place_index, value) + : _data (std::in_place_index, value) { } @@ -126,7 +127,7 @@ namespace join * @param value 64 bits integer value. */ constexpr Value (int64_t value) - : _data (std::in_place_index, value) + : _data (std::in_place_index, value) { } @@ -135,7 +136,7 @@ namespace join * @param value 64 bits unsigned integer value. */ constexpr Value (uint64_t value) - : _data (std::in_place_index, value) + : _data (std::in_place_index, value) { } @@ -144,7 +145,7 @@ namespace join * @param value real value. */ constexpr Value (double value) - : _data (std::in_place_index, value) + : _data (std::in_place_index, value) { } @@ -153,7 +154,16 @@ namespace join * @param value string value. */ Value (const char* value) - : _data (std::in_place_index, value) + : _data (std::in_place_index, value) + { + } + + /** + * @brief constructs a string value from a string view. + * @param value string value. + */ + Value (std::string_view value) + : _data (std::in_place_index, value) { } @@ -162,7 +172,7 @@ namespace join * @param value string value. */ Value (const std::string& value) - : _data (std::in_place_index, value) + : _data (std::in_place_index, value) { } @@ -171,7 +181,7 @@ namespace join * @param value string value. */ Value (std::string&& value) - : _data (std::in_place_index, std::move (value)) + : _data (std::in_place_index, std::move (value)) { } @@ -257,7 +267,7 @@ namespace join */ constexpr bool isNull () const { - return _data.index () == Null; + return _data.index () == NullValue; } /** @@ -266,7 +276,7 @@ namespace join */ constexpr bool isBool () const { - return _data.index () == Boolean; + return _data.index () == BooleanValue; } /** @@ -276,9 +286,9 @@ namespace join */ constexpr bool getBool () const { - if (_data.index () == Boolean) + if (_data.index () == BooleanValue) { - return _data.get (); + return _data.get (); } return convertBool (); @@ -320,8 +330,8 @@ namespace join */ constexpr bool isNumber () const { - return _data.index () == Integer || _data.index () == Unsigned || _data.index () == Integer64 || - _data.index () == Unsigned64 || _data.index () == Real; + return _data.index () == IntegerValue || _data.index () == UnsignedValue || + _data.index () == Integer64Value || _data.index () == Unsigned64Value || _data.index () == RealValue; } /** @@ -332,24 +342,24 @@ namespace join { switch (_data.index ()) { - case Integer: - return _data.get () >= static_cast (std::numeric_limits::min ()) && - _data.get () <= static_cast (std::numeric_limits::max ()); + case IntegerValue: + return _data.get () >= static_cast (std::numeric_limits::min ()) && + _data.get () <= static_cast (std::numeric_limits::max ()); - case Unsigned: - return _data.get () <= static_cast (std::numeric_limits::max ()); + case UnsignedValue: + return _data.get () <= static_cast (std::numeric_limits::max ()); - case Integer64: - return _data.get () >= static_cast (std::numeric_limits::min ()) && - _data.get () <= static_cast (std::numeric_limits::max ()); + case Integer64Value: + return _data.get () >= static_cast (std::numeric_limits::min ()) && + _data.get () <= static_cast (std::numeric_limits::max ()); - case Unsigned64: - return _data.get () <= static_cast (std::numeric_limits::max ()); + case Unsigned64Value: + return _data.get () <= static_cast (std::numeric_limits::max ()); - case Real: - return std::trunc (_data.get ()) == _data.get () && - _data.get () >= static_cast (std::numeric_limits::min ()) && - _data.get () <= static_cast (std::numeric_limits::max ()); + case RealValue: + return std::trunc (_data.get ()) == _data.get () && + _data.get () >= static_cast (std::numeric_limits::min ()) && + _data.get () <= static_cast (std::numeric_limits::max ()); default: break; @@ -369,20 +379,20 @@ namespace join { switch (_data.index ()) { - case Integer: - return static_cast (_data.get ()); + case IntegerValue: + return static_cast (_data.get ()); - case Unsigned: - return static_cast (_data.get ()); + case UnsignedValue: + return static_cast (_data.get ()); - case Integer64: - return static_cast (_data.get ()); + case Integer64Value: + return static_cast (_data.get ()); - case Unsigned64: - return static_cast (_data.get ()); + case Unsigned64Value: + return static_cast (_data.get ()); default: - return static_cast (_data.get ()); + return static_cast (_data.get ()); } } @@ -407,23 +417,25 @@ namespace join { switch (_data.index ()) { - case Integer: - return _data.get () >= 0 && - _data.get () <= static_cast (std::numeric_limits::max ()); + case IntegerValue: + return _data.get () >= 0 && + _data.get () <= static_cast (std::numeric_limits::max ()); - case Unsigned: - return _data.get () <= static_cast (std::numeric_limits::max ()); + case UnsignedValue: + return _data.get () <= static_cast (std::numeric_limits::max ()); - case Integer64: - return _data.get () >= 0 && - _data.get () <= static_cast (std::numeric_limits::max ()); + case Integer64Value: + return _data.get () >= 0 && + _data.get () <= static_cast (std::numeric_limits::max ()); - case Unsigned64: - return _data.get () <= static_cast (std::numeric_limits::max ()); + case Unsigned64Value: + return _data.get () <= + static_cast (std::numeric_limits::max ()); - case Real: - return std::trunc (_data.get ()) == _data.get () && _data.get () >= 0 && - _data.get () <= static_cast (std::numeric_limits::max ()); + case RealValue: + return std::trunc (_data.get ()) == _data.get () && + _data.get () >= 0 && + _data.get () <= static_cast (std::numeric_limits::max ()); default: break; @@ -443,20 +455,20 @@ namespace join { switch (_data.index ()) { - case Integer: - return static_cast (_data.get ()); + case IntegerValue: + return static_cast (_data.get ()); - case Unsigned: - return static_cast (_data.get ()); + case UnsignedValue: + return static_cast (_data.get ()); - case Integer64: - return static_cast (_data.get ()); + case Integer64Value: + return static_cast (_data.get ()); - case Unsigned64: - return static_cast (_data.get ()); + case Unsigned64Value: + return static_cast (_data.get ()); default: - return static_cast (_data.get ()); + return static_cast (_data.get ()); } } @@ -481,24 +493,26 @@ namespace join { switch (_data.index ()) { - case Integer: - return _data.get () >= static_cast (std::numeric_limits::min ()) && - _data.get () <= static_cast (std::numeric_limits::max ()); + case IntegerValue: + return _data.get () >= static_cast (std::numeric_limits::min ()) && + _data.get () <= static_cast (std::numeric_limits::max ()); - case Unsigned: - return _data.get () <= static_cast (std::numeric_limits::max ()); + case UnsignedValue: + return _data.get () <= static_cast (std::numeric_limits::max ()); - case Integer64: - return _data.get () >= static_cast (std::numeric_limits::min ()) && - _data.get () <= static_cast (std::numeric_limits::max ()); + case Integer64Value: + return _data.get () >= + static_cast (std::numeric_limits::min ()) && + _data.get () <= static_cast (std::numeric_limits::max ()); - case Unsigned64: - return _data.get () <= static_cast (std::numeric_limits::max ()); + case Unsigned64Value: + return _data.get () <= + static_cast (std::numeric_limits::max ()); - case Real: - return std::trunc (_data.get ()) == _data.get () && - _data.get () >= static_cast (std::numeric_limits::min ()) && - _data.get () <= static_cast (std::numeric_limits::max ()); + case RealValue: + return std::trunc (_data.get ()) == _data.get () && + _data.get () >= static_cast (std::numeric_limits::min ()) && + _data.get () <= static_cast (std::numeric_limits::max ()); default: break; @@ -518,20 +532,20 @@ namespace join { switch (_data.index ()) { - case Integer: - return static_cast (_data.get ()); + case IntegerValue: + return static_cast (_data.get ()); - case Unsigned: - return static_cast (_data.get ()); + case UnsignedValue: + return static_cast (_data.get ()); - case Integer64: - return static_cast (_data.get ()); + case Integer64Value: + return static_cast (_data.get ()); - case Unsigned64: - return static_cast (_data.get ()); + case Unsigned64Value: + return static_cast (_data.get ()); default: - return static_cast (_data.get ()); + return static_cast (_data.get ()); } } @@ -556,23 +570,25 @@ namespace join { switch (_data.index ()) { - case Integer: - return _data.get () >= 0 && - _data.get () <= static_cast (std::numeric_limits::max ()); + case IntegerValue: + return _data.get () >= 0 && + _data.get () <= static_cast (std::numeric_limits::max ()); - case Unsigned: - return _data.get () <= static_cast (std::numeric_limits::max ()); + case UnsignedValue: + return _data.get () <= static_cast (std::numeric_limits::max ()); - case Integer64: - return _data.get () >= 0 && - _data.get () <= static_cast (std::numeric_limits::max ()); + case Integer64Value: + return _data.get () >= 0 && + _data.get () <= static_cast (std::numeric_limits::max ()); - case Unsigned64: - return _data.get () <= static_cast (std::numeric_limits::max ()); + case Unsigned64Value: + return _data.get () <= + static_cast (std::numeric_limits::max ()); - case Real: - return std::trunc (_data.get ()) == _data.get () && _data.get () >= 0 && - _data.get () <= static_cast (std::numeric_limits::max ()); + case RealValue: + return std::trunc (_data.get ()) == _data.get () && + _data.get () >= 0 && + _data.get () <= static_cast (std::numeric_limits::max ()); default: break; @@ -592,20 +608,20 @@ namespace join { switch (_data.index ()) { - case Integer: - return static_cast (_data.get ()); + case IntegerValue: + return static_cast (_data.get ()); - case Unsigned: - return static_cast (_data.get ()); + case UnsignedValue: + return static_cast (_data.get ()); - case Integer64: - return static_cast (_data.get ()); + case Integer64Value: + return static_cast (_data.get ()); - case Unsigned64: - return static_cast (_data.get ()); + case Unsigned64Value: + return static_cast (_data.get ()); default: - return static_cast (_data.get ()); + return static_cast (_data.get ()); } } @@ -630,23 +646,25 @@ namespace join { switch (_data.index ()) { - case Integer: + case IntegerValue: return true; - case Unsigned: - return _data.get () <= static_cast (std::numeric_limits::max ()); + case UnsignedValue: + return _data.get () <= static_cast (std::numeric_limits::max ()); - case Integer64: - return _data.get () >= static_cast (std::numeric_limits::min ()) && - _data.get () <= static_cast (std::numeric_limits::max ()); + case Integer64Value: + return _data.get () >= + static_cast (std::numeric_limits::min ()) && + _data.get () <= static_cast (std::numeric_limits::max ()); - case Unsigned64: - return _data.get () <= static_cast (std::numeric_limits::max ()); + case Unsigned64Value: + return _data.get () <= + static_cast (std::numeric_limits::max ()); - case Real: - return std::trunc (_data.get ()) == _data.get () && - _data.get () >= static_cast (std::numeric_limits::min ()) && - _data.get () <= static_cast (std::numeric_limits::max ()); + case RealValue: + return std::trunc (_data.get ()) == _data.get () && + _data.get () >= static_cast (std::numeric_limits::min ()) && + _data.get () <= static_cast (std::numeric_limits::max ()); default: break; @@ -662,9 +680,9 @@ namespace join */ constexpr int32_t getInt () const { - if (_data.index () == Integer) + if (_data.index () == IntegerValue) { - return _data.get (); + return _data.get (); } return convertInt (); @@ -688,22 +706,24 @@ namespace join { switch (_data.index ()) { - case Integer: - return _data.get () >= 0; + case IntegerValue: + return _data.get () >= 0; - case Unsigned: + case UnsignedValue: return true; - case Integer64: - return _data.get () >= 0 && - _data.get () <= static_cast (std::numeric_limits::max ()); + case Integer64Value: + return _data.get () >= 0 && + _data.get () <= static_cast (std::numeric_limits::max ()); - case Unsigned64: - return _data.get () <= static_cast (std::numeric_limits::max ()); + case Unsigned64Value: + return _data.get () <= + static_cast (std::numeric_limits::max ()); - case Real: - return std::trunc (_data.get ()) == _data.get () && _data.get () >= 0 && - _data.get () <= static_cast (std::numeric_limits::max ()); + case RealValue: + return std::trunc (_data.get ()) == _data.get () && + _data.get () >= 0 && + _data.get () <= static_cast (std::numeric_limits::max ()); default: break; @@ -719,9 +739,9 @@ namespace join */ constexpr uint32_t getUint () const { - if (_data.index () == Unsigned) + if (_data.index () == UnsignedValue) { - return _data.get (); + return _data.get (); } return convertUint (); @@ -745,18 +765,19 @@ namespace join { switch (_data.index ()) { - case Integer: - case Unsigned: - case Integer64: + case IntegerValue: + case UnsignedValue: + case Integer64Value: return true; - case Unsigned64: - return _data.get () <= static_cast (std::numeric_limits::max ()); + case Unsigned64Value: + return _data.get () <= + static_cast (std::numeric_limits::max ()); - case Real: - return std::trunc (_data.get ()) == _data.get () && - _data.get () >= static_cast (std::numeric_limits::min ()) && - _data.get () < static_cast (std::numeric_limits::max ()); + case RealValue: + return std::trunc (_data.get ()) == _data.get () && + _data.get () >= static_cast (std::numeric_limits::min ()) && + _data.get () < static_cast (std::numeric_limits::max ()); default: break; @@ -772,9 +793,9 @@ namespace join */ constexpr int64_t getInt64 () const { - if (_data.index () == Integer64) + if (_data.index () == Integer64Value) { - return _data.get (); + return _data.get (); } return convertInt64 (); @@ -798,21 +819,22 @@ namespace join { switch (_data.index ()) { - case Integer: - return _data.get () >= 0; + case IntegerValue: + return _data.get () >= 0; - case Unsigned: + case UnsignedValue: return true; - case Integer64: - return _data.get () >= 0; + case Integer64Value: + return _data.get () >= 0; - case Unsigned64: + case Unsigned64Value: return true; - case Real: - return std::trunc (_data.get ()) == _data.get () && _data.get () >= 0 && - _data.get () < static_cast (std::numeric_limits::max ()); + case RealValue: + return std::trunc (_data.get ()) == _data.get () && + _data.get () >= 0 && + _data.get () < static_cast (std::numeric_limits::max ()); default: break; @@ -828,9 +850,9 @@ namespace join */ constexpr uint64_t getUint64 () const { - if (_data.index () == Unsigned64) + if (_data.index () == Unsigned64Value) { - return _data.get (); + return _data.get (); } return convertUint64 (); @@ -862,9 +884,9 @@ namespace join */ constexpr float getFloat () const { - if (_data.index () == Real) + if (_data.index () == RealValue) { - return static_cast (_data.get ()); + return static_cast (_data.get ()); } return convertFloat (); @@ -896,9 +918,9 @@ namespace join */ constexpr double getDouble () const { - if (_data.index () == Real) + if (_data.index () == RealValue) { - return _data.get (); + return _data.get (); } return convertDouble (); @@ -920,7 +942,7 @@ namespace join */ constexpr bool isString () const { - return _data.index () == String; + return _data.index () == StringValue; } /** @@ -930,7 +952,7 @@ namespace join */ constexpr const std::string& getString () const { - return _data.get (); + return _data.get (); } /** @@ -940,7 +962,7 @@ namespace join */ constexpr std::string& getString () { - return _data.get (); + return _data.get (); } /** @@ -1072,7 +1094,7 @@ namespace join return _data.get ()[key.getUint64 ()]; } - if (_data.index () == Null) + if (_data.index () == NullValue) { _data.set (); } @@ -1099,8 +1121,8 @@ namespace join { switch (_data.index ()) { - case String: - return _data.get ().empty (); + case StringValue: + return _data.get ().empty (); case ArrayValue: return _data.get ().empty (); @@ -1124,8 +1146,8 @@ namespace join { switch (_data.index ()) { - case String: - return _data.get ().size (); + case StringValue: + return _data.get ().size (); case ArrayValue: return _data.get ().size (); @@ -1149,8 +1171,8 @@ namespace join { switch (_data.index ()) { - case String: - _data.get ().reserve (cap); + case StringValue: + _data.get ().reserve (cap); return; case ArrayValue: @@ -1176,8 +1198,8 @@ namespace join { switch (_data.index ()) { - case String: - _data.get ().clear (); + case StringValue: + _data.get ().clear (); return; case ArrayValue: @@ -1251,7 +1273,7 @@ namespace join template Value& emplaceBack (Args&&... args) { - if (_data.index () == Null) + if (_data.index () == NullValue) { _data.set (); } @@ -1267,7 +1289,7 @@ namespace join */ Value& pushBack (const Value& value) { - if (_data.index () == Null) + if (_data.index () == NullValue) { _data.set (); } @@ -1283,7 +1305,7 @@ namespace join */ Value& pushBack (Value&& value) { - if (_data.index () == Null) + if (_data.index () == NullValue) { _data.set (); } @@ -1349,17 +1371,17 @@ namespace join { switch (_data.index ()) { - case Integer: - return static_cast (_data.get ()); + case IntegerValue: + return static_cast (_data.get ()); - case Unsigned: - return static_cast (_data.get ()); + case UnsignedValue: + return static_cast (_data.get ()); - case Integer64: - return static_cast (_data.get ()); + case Integer64Value: + return static_cast (_data.get ()); - case Unsigned64: - return static_cast (_data.get ()); + case Unsigned64Value: + return static_cast (_data.get ()); default: break; @@ -1376,23 +1398,23 @@ namespace join { switch (_data.index ()) { - case Null: + case NullValue: return false; - case Integer: - return _data.get (); + case IntegerValue: + return _data.get (); - case Unsigned: - return _data.get (); + case UnsignedValue: + return _data.get (); - case Integer64: - return _data.get (); + case Integer64Value: + return _data.get (); - case Unsigned64: - return _data.get (); + case Unsigned64Value: + return _data.get (); - case Real: - return _data.get (); + case RealValue: + return _data.get (); default: break; @@ -1411,17 +1433,17 @@ namespace join { switch (_data.index ()) { - case Unsigned: - return static_cast (_data.get ()); + case UnsignedValue: + return static_cast (_data.get ()); - case Integer64: - return static_cast (_data.get ()); + case Integer64Value: + return static_cast (_data.get ()); - case Unsigned64: - return static_cast (_data.get ()); + case Unsigned64Value: + return static_cast (_data.get ()); default: - return static_cast (_data.get ()); + return static_cast (_data.get ()); } } @@ -1438,17 +1460,17 @@ namespace join { switch (_data.index ()) { - case Integer: - return static_cast (_data.get ()); + case IntegerValue: + return static_cast (_data.get ()); - case Integer64: - return static_cast (_data.get ()); + case Integer64Value: + return static_cast (_data.get ()); - case Unsigned64: - return static_cast (_data.get ()); + case Unsigned64Value: + return static_cast (_data.get ()); default: - return static_cast (_data.get ()); + return static_cast (_data.get ()); } } @@ -1465,17 +1487,17 @@ namespace join { switch (_data.index ()) { - case Integer: - return static_cast (_data.get ()); + case IntegerValue: + return static_cast (_data.get ()); - case Unsigned: - return static_cast (_data.get ()); + case UnsignedValue: + return static_cast (_data.get ()); - case Unsigned64: - return static_cast (_data.get ()); + case Unsigned64Value: + return static_cast (_data.get ()); default: - return static_cast (_data.get ()); + return static_cast (_data.get ()); } } @@ -1492,17 +1514,17 @@ namespace join { switch (_data.index ()) { - case Integer: - return static_cast (_data.get ()); + case IntegerValue: + return static_cast (_data.get ()); - case Unsigned: - return static_cast (_data.get ()); + case UnsignedValue: + return static_cast (_data.get ()); - case Integer64: - return static_cast (_data.get ()); + case Integer64Value: + return static_cast (_data.get ()); default: - return static_cast (_data.get ()); + return static_cast (_data.get ()); } } @@ -1517,17 +1539,17 @@ namespace join { switch (_data.index ()) { - case Integer: - return static_cast (_data.get ()); + case IntegerValue: + return static_cast (_data.get ()); - case Unsigned: - return static_cast (_data.get ()); + case UnsignedValue: + return static_cast (_data.get ()); - case Integer64: - return static_cast (_data.get ()); + case Integer64Value: + return static_cast (_data.get ()); - case Unsigned64: - return static_cast (_data.get ()); + case Unsigned64Value: + return static_cast (_data.get ()); default: break; diff --git a/data/tests/document_test.cpp b/data/tests/document_test.cpp index 440263bb..977a63bc 100644 --- a/data/tests/document_test.cpp +++ b/data/tests/document_test.cpp @@ -291,7 +291,7 @@ TEST (Document, setInt) { Document document; ASSERT_EQ (document.setInt (-1), 0); - ASSERT_EQ (document.root ().index (), Value::Integer); + ASSERT_EQ (document.root ().index (), Value::IntegerValue); ASSERT_EQ (document.root (), -1); ASSERT_EQ (JsonReader ().deserialize (std::string ("42"), document), 0) << join::lastError.message (); ASSERT_EQ (document.root (), 42); @@ -299,7 +299,7 @@ TEST (Document, setInt) ASSERT_EQ (document.startArray (), 0); ASSERT_EQ (document.setInt (-1), 0); ASSERT_EQ (document.stopArray (), 0); - ASSERT_EQ (document.root ()[0].index (), Value::Integer); + ASSERT_EQ (document.root ()[0].index (), Value::IntegerValue); ASSERT_EQ (document.root ()[0], -1); } @@ -310,12 +310,12 @@ TEST (Document, setUint) { Document document; ASSERT_EQ (document.setUint (1), 0); - ASSERT_EQ (document.root ().index (), Value::Unsigned); + ASSERT_EQ (document.root ().index (), Value::UnsignedValue); ASSERT_EQ (document.startArray (), 0); ASSERT_EQ (document.setUint (1), 0); ASSERT_EQ (document.stopArray (), 0); - ASSERT_EQ (document.root ()[0].index (), Value::Unsigned); + ASSERT_EQ (document.root ()[0].index (), Value::UnsignedValue); ASSERT_EQ (document.root ()[0], 1U); } @@ -326,12 +326,12 @@ TEST (Document, setInt64) { Document document; ASSERT_EQ (document.setInt64 (-1), 0); - ASSERT_EQ (document.root ().index (), Value::Integer64); + ASSERT_EQ (document.root ().index (), Value::Integer64Value); ASSERT_EQ (document.startArray (), 0); ASSERT_EQ (document.setInt64 (-1), 0); ASSERT_EQ (document.stopArray (), 0); - ASSERT_EQ (document.root ()[0].index (), Value::Integer64); + ASSERT_EQ (document.root ()[0].index (), Value::Integer64Value); ASSERT_EQ (document.root ()[0], int64_t (-1)); } @@ -342,12 +342,12 @@ TEST (Document, setUint64) { Document document; ASSERT_EQ (document.setUint64 (1), 0); - ASSERT_EQ (document.root ().index (), Value::Unsigned64); + ASSERT_EQ (document.root ().index (), Value::Unsigned64Value); ASSERT_EQ (document.startArray (), 0); ASSERT_EQ (document.setUint64 (1), 0); ASSERT_EQ (document.stopArray (), 0); - ASSERT_EQ (document.root ()[0].index (), Value::Unsigned64); + ASSERT_EQ (document.root ()[0].index (), Value::Unsigned64Value); ASSERT_EQ (document.root ()[0], uint64_t (1)); } diff --git a/data/tests/value_test.cpp b/data/tests/value_test.cpp index c5debd4b..a7db9d96 100644 --- a/data/tests/value_test.cpp +++ b/data/tests/value_test.cpp @@ -126,6 +126,10 @@ TEST (Value, create) ASSERT_TRUE (movedStringValue.isString ()); ASSERT_EQ (movedStringValue.getString (), "qux"); + Value viewStringValue (std::string_view ("quux", 3)); + ASSERT_TRUE (viewStringValue.isString ()); + ASSERT_EQ (viewStringValue.getString (), "quu"); + Value arrayValue (Array{1}); ASSERT_TRUE (arrayValue.isArray ()); @@ -3881,122 +3885,122 @@ TEST (Value, index) Value value; value = nullptr; - ASSERT_EQ (value.index (), static_cast (Value::Index::Null)); - ASSERT_NE (value.index (), static_cast (Value::Index::Boolean)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Real)); - ASSERT_NE (value.index (), static_cast (Value::Index::String)); + ASSERT_EQ (value.index (), static_cast (Value::Index::NullValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::BooleanValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::IntegerValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::UnsignedValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::Integer64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::RealValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::StringValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ArrayValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ObjectValue)); value = bool (true); - ASSERT_NE (value.index (), static_cast (Value::Index::Null)); - ASSERT_EQ (value.index (), static_cast (Value::Index::Boolean)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Real)); - ASSERT_NE (value.index (), static_cast (Value::Index::String)); + ASSERT_NE (value.index (), static_cast (Value::Index::NullValue)); + ASSERT_EQ (value.index (), static_cast (Value::Index::BooleanValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::IntegerValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::UnsignedValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::Integer64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::RealValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::StringValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ArrayValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ObjectValue)); value = int32_t (std::numeric_limits::min ()); - ASSERT_NE (value.index (), static_cast (Value::Index::Null)); - ASSERT_NE (value.index (), static_cast (Value::Index::Boolean)); - ASSERT_EQ (value.index (), static_cast (Value::Index::Integer)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Real)); - ASSERT_NE (value.index (), static_cast (Value::Index::String)); + ASSERT_NE (value.index (), static_cast (Value::Index::NullValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::BooleanValue)); + ASSERT_EQ (value.index (), static_cast (Value::Index::IntegerValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::UnsignedValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::Integer64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::RealValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::StringValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ArrayValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ObjectValue)); value = uint32_t (std::numeric_limits::max ()); - ASSERT_NE (value.index (), static_cast (Value::Index::Null)); - ASSERT_NE (value.index (), static_cast (Value::Index::Boolean)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer)); - ASSERT_EQ (value.index (), static_cast (Value::Index::Unsigned)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Real)); - ASSERT_NE (value.index (), static_cast (Value::Index::String)); + ASSERT_NE (value.index (), static_cast (Value::Index::NullValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::BooleanValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::IntegerValue)); + ASSERT_EQ (value.index (), static_cast (Value::Index::UnsignedValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::Integer64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::RealValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::StringValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ArrayValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ObjectValue)); value = int64_t (std::numeric_limits::min ()); - ASSERT_NE (value.index (), static_cast (Value::Index::Null)); - ASSERT_NE (value.index (), static_cast (Value::Index::Boolean)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned)); - ASSERT_EQ (value.index (), static_cast (Value::Index::Integer64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Real)); - ASSERT_NE (value.index (), static_cast (Value::Index::String)); + ASSERT_NE (value.index (), static_cast (Value::Index::NullValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::BooleanValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::IntegerValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::UnsignedValue)); + ASSERT_EQ (value.index (), static_cast (Value::Index::Integer64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::RealValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::StringValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ArrayValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ObjectValue)); value = uint64_t (std::numeric_limits::max ()); - ASSERT_NE (value.index (), static_cast (Value::Index::Null)); - ASSERT_NE (value.index (), static_cast (Value::Index::Boolean)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer64)); - ASSERT_EQ (value.index (), static_cast (Value::Index::Unsigned64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Real)); - ASSERT_NE (value.index (), static_cast (Value::Index::String)); + ASSERT_NE (value.index (), static_cast (Value::Index::NullValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::BooleanValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::IntegerValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::UnsignedValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::Integer64Value)); + ASSERT_EQ (value.index (), static_cast (Value::Index::Unsigned64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::RealValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::StringValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ArrayValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ObjectValue)); value = double (std::numeric_limits::min ()); - ASSERT_NE (value.index (), static_cast (Value::Index::Null)); - ASSERT_NE (value.index (), static_cast (Value::Index::Boolean)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64)); - ASSERT_EQ (value.index (), static_cast (Value::Index::Real)); - ASSERT_NE (value.index (), static_cast (Value::Index::String)); + ASSERT_NE (value.index (), static_cast (Value::Index::NullValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::BooleanValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::IntegerValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::UnsignedValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::Integer64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64Value)); + ASSERT_EQ (value.index (), static_cast (Value::Index::RealValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::StringValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ArrayValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ObjectValue)); value = std::string ("foobar"); - ASSERT_NE (value.index (), static_cast (Value::Index::Null)); - ASSERT_NE (value.index (), static_cast (Value::Index::Boolean)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Real)); - ASSERT_EQ (value.index (), static_cast (Value::Index::String)); + ASSERT_NE (value.index (), static_cast (Value::Index::NullValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::BooleanValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::IntegerValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::UnsignedValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::Integer64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::RealValue)); + ASSERT_EQ (value.index (), static_cast (Value::Index::StringValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ArrayValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ObjectValue)); value = Array{1}; - ASSERT_NE (value.index (), static_cast (Value::Index::Null)); - ASSERT_NE (value.index (), static_cast (Value::Index::Boolean)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Real)); - ASSERT_NE (value.index (), static_cast (Value::Index::String)); + ASSERT_NE (value.index (), static_cast (Value::Index::NullValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::BooleanValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::IntegerValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::UnsignedValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::Integer64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::RealValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::StringValue)); ASSERT_EQ (value.index (), static_cast (Value::Index::ArrayValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ObjectValue)); value = Object{{"i", 1}}; - ASSERT_NE (value.index (), static_cast (Value::Index::Null)); - ASSERT_NE (value.index (), static_cast (Value::Index::Boolean)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned)); - ASSERT_NE (value.index (), static_cast (Value::Index::Integer64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64)); - ASSERT_NE (value.index (), static_cast (Value::Index::Real)); - ASSERT_NE (value.index (), static_cast (Value::Index::String)); + ASSERT_NE (value.index (), static_cast (Value::Index::NullValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::BooleanValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::IntegerValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::UnsignedValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::Integer64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::Unsigned64Value)); + ASSERT_NE (value.index (), static_cast (Value::Index::RealValue)); + ASSERT_NE (value.index (), static_cast (Value::Index::StringValue)); ASSERT_NE (value.index (), static_cast (Value::Index::ArrayValue)); ASSERT_EQ (value.index (), static_cast (Value::Index::ObjectValue)); }