diff options
author | levysotsky <levysotsky@yandex-team.ru> | 2022-02-10 16:47:29 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:29 +0300 |
commit | 57f874ffc2a75047c1c4fea7a9fc86cb0f56ed50 (patch) | |
tree | ba6454f353979bb4bafaf230cafdf3e02ea120b2 /library/cpp/yt/misc | |
parent | 23d4769f0fea97cfb1028710e50f2b5ecd0ac2c0 (diff) | |
download | ydb-57f874ffc2a75047c1c4fea7a9fc86cb0f56ed50.tar.gz |
Restoring authorship annotation for <levysotsky@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/yt/misc')
-rw-r--r-- | library/cpp/yt/misc/enum-inl.h | 114 | ||||
-rw-r--r-- | library/cpp/yt/misc/enum.h | 20 |
2 files changed, 67 insertions, 67 deletions
diff --git a/library/cpp/yt/misc/enum-inl.h b/library/cpp/yt/misc/enum-inl.h index 59ef704775..0941e1fb63 100644 --- a/library/cpp/yt/misc/enum-inl.h +++ b/library/cpp/yt/misc/enum-inl.h @@ -8,7 +8,7 @@ #include <util/string/printf.h> #include <util/string/cast.h> -#include <algorithm> +#include <algorithm> #include <stdexcept> namespace NYT { @@ -36,25 +36,25 @@ namespace NYT { //////////////////////////////////////////////////////////////////////////////// -namespace NDetail { - -template <typename TValues> -static constexpr bool AreValuesDistinct(const TValues& values) -{ - for (int i = 0; i < static_cast<int>(values.size()); ++i) { - for (int j = i + 1; j < static_cast<int>(values.size()); ++j) { - if (values[i] == values[j]) { - return false; - } - } - } - return true; -} - -} // namespace NDetail - -//////////////////////////////////////////////////////////////////////////////// - +namespace NDetail { + +template <typename TValues> +static constexpr bool AreValuesDistinct(const TValues& values) +{ + for (int i = 0; i < static_cast<int>(values.size()); ++i) { + for (int j = i + 1; j < static_cast<int>(values.size()); ++j) { + if (values[i] == values[j]) { + return false; + } + } + } + return true; +} + +} // namespace NDetail + +//////////////////////////////////////////////////////////////////////////////// + #define ENUM__BEGIN_TRAITS(name, underlyingType, isBit, isStringSerializable, seq) \ struct TEnumTraitsImpl_##name \ { \ @@ -64,13 +64,13 @@ static constexpr bool AreValuesDistinct(const TValues& values) [[maybe_unused]] static constexpr bool IsStringSerializableEnum = isStringSerializable; \ [[maybe_unused]] static constexpr int DomainSize = PP_COUNT(seq); \ \ - static constexpr std::array<TStringBuf, DomainSize> Names{{ \ - PP_FOR_EACH(ENUM__GET_DOMAIN_NAMES_ITEM, seq) \ - }}; \ - static constexpr std::array<TType, DomainSize> Values{{ \ - PP_FOR_EACH(ENUM__GET_DOMAIN_VALUES_ITEM, seq) \ - }}; \ - \ + static constexpr std::array<TStringBuf, DomainSize> Names{{ \ + PP_FOR_EACH(ENUM__GET_DOMAIN_NAMES_ITEM, seq) \ + }}; \ + static constexpr std::array<TType, DomainSize> Values{{ \ + PP_FOR_EACH(ENUM__GET_DOMAIN_VALUES_ITEM, seq) \ + }}; \ + \ static TStringBuf GetTypeName() \ { \ static constexpr TStringBuf typeName = PP_STRINGIZE(name); \ @@ -79,33 +79,33 @@ static constexpr bool AreValuesDistinct(const TValues& values) \ static const TStringBuf* FindLiteralByValue(TType value) \ { \ - for (int i = 0; i < DomainSize; ++i) { \ - if (Values[i] == value) { \ - return &Names[i]; \ - } \ - } \ + for (int i = 0; i < DomainSize; ++i) { \ + if (Values[i] == value) { \ + return &Names[i]; \ + } \ + } \ return nullptr; \ } \ \ static bool FindValueByLiteral(TStringBuf literal, TType* result) \ { \ - for (int i = 0; i < DomainSize; ++i) { \ - if (Names[i] == literal) { \ - *result = Values[i]; \ - return true; \ - } \ - } \ + for (int i = 0; i < DomainSize; ++i) { \ + if (Names[i] == literal) { \ + *result = Values[i]; \ + return true; \ + } \ + } \ return false; \ } \ \ static const std::array<TStringBuf, DomainSize>& GetDomainNames() \ { \ - return Names; \ + return Names; \ } \ \ static const std::array<TType, DomainSize>& GetDomainValues() \ { \ - return Values; \ + return Values; \ } \ \ static TType FromString(TStringBuf str) \ @@ -145,34 +145,34 @@ static constexpr bool AreValuesDistinct(const TValues& values) #define ENUM__GET_DOMAIN_NAMES_ITEM_ATOMIC(item) \ TStringBuf(PP_STRINGIZE(item)), -#define ENUM__DECOMPOSE \ +#define ENUM__DECOMPOSE \ static std::vector<TType> Decompose(TType value) \ { \ std::vector<TType> result; \ - for (int i = 0; i < DomainSize; ++i) { \ - if (static_cast<TUnderlying>(value) & static_cast<TUnderlying>(Values[i])) { \ - result.push_back(Values[i]); \ - } \ - } \ + for (int i = 0; i < DomainSize; ++i) { \ + if (static_cast<TUnderlying>(value) & static_cast<TUnderlying>(Values[i])) { \ + result.push_back(Values[i]); \ + } \ + } \ return result; \ } -#define ENUM__MINMAX \ - static constexpr TType GetMinValue() \ +#define ENUM__MINMAX \ + static constexpr TType GetMinValue() \ { \ - static_assert(!Values.empty()); \ - return *std::min_element(std::begin(Values), std::end(Values)); \ + static_assert(!Values.empty()); \ + return *std::min_element(std::begin(Values), std::end(Values)); \ } \ \ - static constexpr TType GetMaxValue() \ + static constexpr TType GetMaxValue() \ { \ - static_assert(!Values.empty()); \ - return *std::max_element(std::begin(Values), std::end(Values)); \ + static_assert(!Values.empty()); \ + return *std::max_element(std::begin(Values), std::end(Values)); \ } -#define ENUM__VALIDATE_UNIQUE(name) \ - static_assert(::NYT::NDetail::AreValuesDistinct(Values), \ - "Enumeration " #name " contains duplicate values"); +#define ENUM__VALIDATE_UNIQUE(name) \ + static_assert(::NYT::NDetail::AreValuesDistinct(Values), \ + "Enumeration " #name " contains duplicate values"); #define ENUM__END_TRAITS(name) \ }; \ @@ -181,7 +181,7 @@ static constexpr bool AreValuesDistinct(const TValues& values) { \ return TEnumTraitsImpl_##name(); \ } \ - \ + \ using ::ToString; \ [[maybe_unused]] inline TString ToString(name value) \ { \ diff --git a/library/cpp/yt/misc/enum.h b/library/cpp/yt/misc/enum.h index 894364aa43..97c62cac93 100644 --- a/library/cpp/yt/misc/enum.h +++ b/library/cpp/yt/misc/enum.h @@ -108,16 +108,16 @@ struct TEnumTraits<T, true> #define DEFINE_ENUM_WITH_UNDERLYING_TYPE(name, underlyingType, seq) \ ENUM__CLASS(name, underlyingType, seq) \ ENUM__BEGIN_TRAITS(name, underlyingType, false, false, seq) \ - ENUM__MINMAX \ - ENUM__VALIDATE_UNIQUE(name) \ - ENUM__END_TRAITS(name) + ENUM__MINMAX \ + ENUM__VALIDATE_UNIQUE(name) \ + ENUM__END_TRAITS(name) //! Defines a smart enumeration with a specific underlying type. //! Duplicate enumeration values are allowed. #define DEFINE_AMBIGUOUS_ENUM_WITH_UNDERLYING_TYPE(name, underlyingType, seq) \ ENUM__CLASS(name, underlyingType, seq) \ ENUM__BEGIN_TRAITS(name, underlyingType, false, false, seq) \ - ENUM__MINMAX \ + ENUM__MINMAX \ ENUM__END_TRAITS(name) //! Defines a smart enumeration with the default |int| underlying type. @@ -133,8 +133,8 @@ struct TEnumTraits<T, true> #define DEFINE_BIT_ENUM_WITH_UNDERLYING_TYPE(name, underlyingType, seq) \ ENUM__CLASS(name, underlyingType, seq) \ ENUM__BEGIN_TRAITS(name, underlyingType, true, false, seq) \ - ENUM__DECOMPOSE \ - ENUM__VALIDATE_UNIQUE(name) \ + ENUM__DECOMPOSE \ + ENUM__VALIDATE_UNIQUE(name) \ ENUM__END_TRAITS(name) \ ENUM__BITWISE_OPS(name) @@ -148,7 +148,7 @@ struct TEnumTraits<T, true> #define DEFINE_AMBIGUOUS_BIT_ENUM_WITH_UNDERLYING_TYPE(name, underlyingType, seq) \ ENUM__CLASS(name, underlyingType, seq) \ ENUM__BEGIN_TRAITS(name, underlyingType, true, false, seq) \ - ENUM__DECOMPOSE \ + ENUM__DECOMPOSE \ ENUM__END_TRAITS(name) \ ENUM__BITWISE_OPS(name) @@ -169,8 +169,8 @@ struct TEnumTraits<T, true> #define DEFINE_STRING_SERIALIZABLE_ENUM_WITH_UNDERLYING_TYPE(name, underlyingType, seq) \ ENUM__CLASS(name, underlyingType, seq) \ ENUM__BEGIN_TRAITS(name, underlyingType, false, true, seq) \ - ENUM__MINMAX \ - ENUM__VALIDATE_UNIQUE(name) \ + ENUM__MINMAX \ + ENUM__VALIDATE_UNIQUE(name) \ ENUM__END_TRAITS(name) \ //! Defines a smart enumeration with a specific underlying type and IsStringSerializable attribute. @@ -178,7 +178,7 @@ struct TEnumTraits<T, true> #define DEFINE_AMBIGUOUS_STRING_SERIALIZABLE_ENUM_WITH_UNDERLYING_TYPE(name, underlyingType, seq) \ ENUM__CLASS(name, underlyingType, seq) \ ENUM__BEGIN_TRAITS(name, underlyingType, false, true, seq) \ - ENUM__MINMAX \ + ENUM__MINMAX \ ENUM__END_TRAITS(name) //! Defines a smart enumeration with the default |int| underlying type and IsStringSerializable attribute. |