aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/unified_agent_client/enum.h
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2023-03-31 10:54:08 +0300
committerDaniil Cherednik <dan.cherednik@gmail.com>2023-03-31 12:28:07 +0300
commitfc1cffcfa7f0497a1f97b384a24bcbf23362f3be (patch)
treec15f7ab5b9e9b20fd0ef8fc07d598d28e8b32004 /library/cpp/unified_agent_client/enum.h
parent8a749596d40e91c896a1907afcd108d9221fbde1 (diff)
downloadydb-fc1cffcfa7f0497a1f97b384a24bcbf23362f3be.tar.gz
Ydb stable 23-1-1923.1.19
x-stable-origin-commit: c5d5a396e89d0a72e0267a55e93d8404d4fb54fe
Diffstat (limited to 'library/cpp/unified_agent_client/enum.h')
-rw-r--r--library/cpp/unified_agent_client/enum.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/library/cpp/unified_agent_client/enum.h b/library/cpp/unified_agent_client/enum.h
new file mode 100644
index 0000000000..b21e21acb0
--- /dev/null
+++ b/library/cpp/unified_agent_client/enum.h
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <util/generic/serialized_enum.h>
+#include <util/generic/vector.h>
+
+namespace NUnifiedAgent {
+ namespace NPrivate {
+ using TEnumNames = TVector<const TString*>;
+
+ template <typename TEnum>
+ TEnumNames BuildEnumNames() {
+ const auto names = GetEnumNames<TEnum>();
+ auto result = TEnumNames(names.size());
+ size_t index = 0;
+ for (const auto& p: names) {
+ Y_VERIFY(static_cast<size_t>(p.first) == index);
+ result[index++] = &p.second;
+ }
+ return result;
+ }
+
+ template <typename TEnum>
+ inline const auto EnumNames = BuildEnumNames<TEnum>();
+ }
+
+ template <typename TEnum, typename = std::enable_if_t<std::is_enum_v<TEnum>>>
+ inline const TString& NameOf(TEnum val) noexcept {
+ return *NPrivate::EnumNames<TEnum>[static_cast<size_t>(val)];
+ }
+}