diff options
author | nkmakarov <nkmakarov@yandex-team.ru> | 2022-02-10 16:49:06 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:06 +0300 |
commit | 324348a37ed08cf66897faefb0ec4bebfe7804e1 (patch) | |
tree | 8736a3afd6953763bf57544746bf1b8b5404dec6 /util/draft/enum.h | |
parent | 5eddcf9f19515e4be1e49ba1482d920e007a07d1 (diff) | |
download | ydb-324348a37ed08cf66897faefb0ec4bebfe7804e1.tar.gz |
Restoring authorship annotation for <nkmakarov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/draft/enum.h')
-rw-r--r-- | util/draft/enum.h | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/util/draft/enum.h b/util/draft/enum.h index 18002b7df20..c65f54357c4 100644 --- a/util/draft/enum.h +++ b/util/draft/enum.h @@ -3,7 +3,7 @@ #include <bitset> #include <util/generic/strbuf.h> -#include <util/stream/str.h> +#include <util/stream/str.h> #include <util/string/cast.h> #include <util/string/split.h> #include <utility> @@ -12,11 +12,11 @@ class TEnumNotFoundException: public yexception { }; #define EnumFromString(key, entries) EnumFromStringImpl(key, entries, Y_ARRAY_SIZE(entries)) -#define EnumFromStringWithSize(key, entries, size) EnumFromStringImpl(key, entries, size) +#define EnumFromStringWithSize(key, entries, size) EnumFromStringImpl(key, entries, size) #define FindEnumFromString(key, entries) FindEnumFromStringImpl(key, entries, Y_ARRAY_SIZE(entries)) -#define FindEnumFromStringWithSize(key, entries, size) FindEnumFromStringImpl(key, entries, size) +#define FindEnumFromStringWithSize(key, entries, size) FindEnumFromStringImpl(key, entries, size) #define EnumToString(key, entries) EnumToStringImpl(key, entries, Y_ARRAY_SIZE(entries)) -#define EnumToStringWithSize(key, entries, size) EnumToStringImpl(key, entries, size) +#define EnumToStringWithSize(key, entries, size) EnumToStringImpl(key, entries, size) #define PrintEnumItems(entries) PrintEnumItemsImpl(entries, Y_ARRAY_SIZE(entries)) template <class K1, class K2, class V> @@ -80,39 +80,39 @@ const K* EnumToStringImpl(V value, const std::pair<K, V>* entries, size_t arrayS /////////////////////////////////// -template <class B> -inline void SetEnumFlagsForEmptySpec(B& flags, bool allIfEmpty) { - if (allIfEmpty) { - flags.set(); - } else { - flags.reset(); - } -} - +template <class B> +inline void SetEnumFlagsForEmptySpec(B& flags, bool allIfEmpty) { + if (allIfEmpty) { + flags.set(); + } else { + flags.reset(); + } +} + // all set by default template <class E, size_t N, size_t B> inline void SetEnumFlags(const std::pair<const char*, E> (&str2Enum)[N], TStringBuf optSpec, std::bitset<B>& flags, bool allIfEmpty = true) { if (optSpec.empty()) { - SetEnumFlagsForEmptySpec(flags, allIfEmpty); - } else { - flags.reset(); - for (const auto& it : StringSplitter(optSpec).Split(',')) { + SetEnumFlagsForEmptySpec(flags, allIfEmpty); + } else { + flags.reset(); + for (const auto& it : StringSplitter(optSpec).Split(',')) { E e = *EnumFromStringImpl(ToString(it.Token()).data(), str2Enum, N); - flags.set(e); + flags.set(e); } - } -} - -template <class E, size_t B> + } +} + +template <class E, size_t B> inline void SetEnumFlags(const std::pair<const char*, E>* str2Enum, TStringBuf optSpec, - std::bitset<B>& flags, const size_t size, + std::bitset<B>& flags, const size_t size, bool allIfEmpty = true) { - if (optSpec.empty()) { - SetEnumFlagsForEmptySpec(flags, allIfEmpty); + if (optSpec.empty()) { + SetEnumFlagsForEmptySpec(flags, allIfEmpty); } else { flags.reset(); - for (const auto& it : StringSplitter(optSpec).Split(',')) { + for (const auto& it : StringSplitter(optSpec).Split(',')) { E e = *EnumFromStringImpl(ToString(it.Token()).data(), str2Enum, size); flags.set(e); } @@ -123,13 +123,13 @@ inline void SetEnumFlags(const std::pair<const char*, E>* str2Enum, TStringBuf o template <class E, size_t B> inline void SetEnumFlags(TStringBuf optSpec, std::bitset<B>& flags, bool allIfEmpty = true) { if (optSpec.empty()) { - SetEnumFlagsForEmptySpec(flags, allIfEmpty); + SetEnumFlagsForEmptySpec(flags, allIfEmpty); } else { flags.reset(); - for (const auto& it : StringSplitter(optSpec).Split(',')) { + for (const auto& it : StringSplitter(optSpec).Split(',')) { E e; if (!TryFromString(it.Token(), e)) - ythrow yexception() << "Unknown enum value '" << it.Token() << "'"; + ythrow yexception() << "Unknown enum value '" << it.Token() << "'"; flags.set((size_t)e); } } |