diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/yson_pull/scalar.h | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/yson_pull/scalar.h')
-rw-r--r-- | library/cpp/yson_pull/scalar.h | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/library/cpp/yson_pull/scalar.h b/library/cpp/yson_pull/scalar.h index 509fce8b5e..a105e36de2 100644 --- a/library/cpp/yson_pull/scalar.h +++ b/library/cpp/yson_pull/scalar.h @@ -7,24 +7,24 @@ #include <util/system/yassert.h> namespace NYsonPull { - //! \brief YSON TScalar value type tag - enum class EScalarType { + //! \brief YSON TScalar value type tag + enum class EScalarType { Entity = YSON_SCALAR_ENTITY, Boolean = YSON_SCALAR_BOOLEAN, Int64 = YSON_SCALAR_INT64, UInt64 = YSON_SCALAR_UINT64, Float64 = YSON_SCALAR_FLOAT64, String = YSON_SCALAR_STRING, - }; + }; - //! \brief YSON TScalar value variant - class TScalar { - //! \internal \brief YSON TScalar value underlying representation + //! \brief YSON TScalar value variant + class TScalar { + //! \internal \brief YSON TScalar value underlying representation union TScalarValue { struct TScalarStringRef { const char* Data; size_t Size; - }; + }; ui8 AsNothing[1]; bool AsBoolean; @@ -35,76 +35,76 @@ namespace NYsonPull { constexpr TScalarValue() : AsNothing{} { - } + } explicit constexpr TScalarValue(bool value) : AsBoolean{value} { - } + } explicit constexpr TScalarValue(i64 value) : AsInt64{value} { - } + } explicit constexpr TScalarValue(ui64 value) : AsUInt64{value} { - } + } explicit constexpr TScalarValue(double value) : AsFloat64{value} { - } + } explicit constexpr TScalarValue(TStringBuf value) : AsString{value.data(), value.size()} { - } - }; - static_assert( + } + }; + static_assert( sizeof(TScalarValue) == sizeof(TStringBuf), - "bad scalar_value size"); + "bad scalar_value size"); EScalarType Type_; TScalarValue Value_; - public: - constexpr TScalar() + public: + constexpr TScalar() : Type_{EScalarType::Entity} { - } + } - explicit constexpr TScalar(bool value) + explicit constexpr TScalar(bool value) : Type_{EScalarType::Boolean} , Value_{value} { - } + } - explicit constexpr TScalar(i64 value) + explicit constexpr TScalar(i64 value) : Type_{EScalarType::Int64} , Value_{value} { - } + } - explicit constexpr TScalar(ui64 value) + explicit constexpr TScalar(ui64 value) : Type_{EScalarType::UInt64} , Value_{value} { - } + } - explicit constexpr TScalar(double value) + explicit constexpr TScalar(double value) : Type_{EScalarType::Float64} , Value_{value} { - } + } - explicit constexpr TScalar(TStringBuf value) + explicit constexpr TScalar(TStringBuf value) : Type_{EScalarType::String} , Value_{value} { - } + } - // Disambiguation for literal constants - // In the absence of this constructor, - // they get implicitly converted to bool (yikes!) - explicit TScalar(const char* value) + // Disambiguation for literal constants + // In the absence of this constructor, + // they get implicitly converted to bool (yikes!) + explicit TScalar(const char* value) : Type_{EScalarType::String} , Value_{TStringBuf{value}} { - } + } EScalarType Type() const { return Type_; - } + } #define CAST_TO(Type) \ Y_ASSERT(Type_ == EScalarType::Type); \ @@ -112,35 +112,35 @@ namespace NYsonPull { bool AsBoolean() const { CAST_TO(Boolean); - } + } i64 AsInt64() const { CAST_TO(Int64); - } + } ui64 AsUInt64() const { CAST_TO(UInt64); - } + } double AsFloat64() const { CAST_TO(Float64); - } + } #undef CAST_TO TStringBuf AsString() const { Y_ASSERT(Type_ == EScalarType::String); - return TStringBuf{ + return TStringBuf{ Value_.AsString.Data, Value_.AsString.Size, - }; - } + }; + } const TScalarValue& AsUnsafeValue() const { return Value_; - } - }; + } + }; - bool operator==(const TScalar& left, const TScalar& right) noexcept; + bool operator==(const TScalar& left, const TScalar& right) noexcept; - inline bool operator!=(const TScalar& left, const TScalar& right) noexcept { - return !(left == right); - } + inline bool operator!=(const TScalar& left, const TScalar& right) noexcept { + return !(left == right); + } -} +} |