aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorivanmorozov <ivanmorozov@yandex-team.com>2022-10-19 11:43:44 +0300
committerivanmorozov <ivanmorozov@yandex-team.com>2022-10-19 11:43:44 +0300
commit708323aafd02440737d5fcf47ae2fbf68134d864 (patch)
tree0706103031ddf522af327340f077b48bc0bd0917
parent3c5ef6b14a1e7a22fdd62b0cb3de643221a00d3b (diff)
downloadydb-708323aafd02440737d5fcf47ae2fbf68134d864.tar.gz
accessor macroses
-rw-r--r--ydb/library/CMakeLists.txt1
-rw-r--r--ydb/library/accessor/CMakeLists.txt17
-rw-r--r--ydb/library/accessor/accessor.cpp1
-rw-r--r--ydb/library/accessor/accessor.h145
4 files changed, 164 insertions, 0 deletions
diff --git a/ydb/library/CMakeLists.txt b/ydb/library/CMakeLists.txt
index 62d58f9c1ed..5186aee93ab 100644
--- a/ydb/library/CMakeLists.txt
+++ b/ydb/library/CMakeLists.txt
@@ -6,6 +6,7 @@
# original buildsystem will not be accepted.
+add_subdirectory(accessor)
add_subdirectory(aclib)
add_subdirectory(arrow_clickhouse)
add_subdirectory(backup)
diff --git a/ydb/library/accessor/CMakeLists.txt b/ydb/library/accessor/CMakeLists.txt
new file mode 100644
index 00000000000..f7402105d24
--- /dev/null
+++ b/ydb/library/accessor/CMakeLists.txt
@@ -0,0 +1,17 @@
+
+# This file was gererated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(ydb-library-accessor)
+target_link_libraries(ydb-library-accessor PUBLIC
+ contrib-libs-cxxsupp
+ yutil
+)
+target_sources(ydb-library-accessor PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/library/accessor/accessor.cpp
+)
diff --git a/ydb/library/accessor/accessor.cpp b/ydb/library/accessor/accessor.cpp
new file mode 100644
index 00000000000..95a89fb8292
--- /dev/null
+++ b/ydb/library/accessor/accessor.cpp
@@ -0,0 +1 @@
+#include "accessor.h"
diff --git a/ydb/library/accessor/accessor.h b/ydb/library/accessor/accessor.h
new file mode 100644
index 00000000000..7d6654994c7
--- /dev/null
+++ b/ydb/library/accessor/accessor.h
@@ -0,0 +1,145 @@
+#pragma once
+
+#include <util/generic/ptr.h>
+
+#define YDB_READONLY_FLAG(name, defaultValue) \
+private:\
+ bool name ## Flag = defaultValue;\
+public:\
+ bool Is ## name() const noexcept {\
+ return name ## Flag;\
+ }\
+private:
+
+#define YDB_FLAG_ACCESSOR(name, defaultValue) \
+YDB_READONLY_FLAG(name, defaultValue) \
+public:\
+ auto& Set##name(const bool value) noexcept {\
+ name ## Flag = value;\
+ return *this;\
+ }\
+private:
+
+#define YDB_READONLY_ACCESSOR_IMPL(name, type, declSpecifiers, defaultValue) \
+private:\
+ declSpecifiers type name = defaultValue;\
+public:\
+ const type& Get ## name() const noexcept {\
+ return name;\
+ }\
+private:
+
+#define YDB_ACCESSOR_IMPL(ClassName, name, type, declSpecifiers, defaultValue, methodsModifier) \
+YDB_READONLY_ACCESSOR_IMPL(name, type, declSpecifiers, defaultValue)\
+public:\
+ ClassName& Set ## name(const type& value) methodsModifier {\
+ name = value;\
+ return *this;\
+ }\
+ ClassName& Set##name(type&& value) methodsModifier {\
+ name = std::move(value);\
+ return *this;\
+ }\
+ type& Mutable ## name() methodsModifier {\
+ return name;\
+ }\
+private:
+
+#define YDB_ACCESSOR(type, name, defaultValue) YDB_ACCESSOR_IMPL(auto, name, type, private:, defaultValue, noexcept)
+#define YDB_MUTABLE_ACCESSOR(type, name, defaultValue) YDB_ACCESSOR_IMPL(const auto, name, type, mutable, defaultValue, const noexcept)
+#define YDB_ACCESSOR_DEF(type, name) YDB_ACCESSOR_IMPL(auto, name, type, private:, type(), noexcept)
+#define YDB_PROTECT_ACCESSOR(type, name, defaultValue) YDB_ACCESSOR_IMPL(auto, name, type, protected:, defaultValue, noexcept)
+#define YDB_PROTECT_ACCESSOR_DEF(type, name) YDB_ACCESSOR_IMPL(auto, name, type, protected:, type(), noexcept)
+
+#define YDB_CONST(type, name) YDB_READONLY_ACCESSOR_IMPL(name, type, const, type())
+#define YDB_READONLY(type, name, defaultValue) YDB_READONLY_ACCESSOR_IMPL(name, type, private:, defaultValue)
+#define YDB_READONLY_DEF(type, name) YDB_READONLY_ACCESSOR_IMPL(name, type, private:, type())
+#define YDB_READONLY_PROTECT(type, name, defaultValue) YDB_READONLY_ACCESSOR_IMPL(name, type, protected:, defaultValue)
+#define YDB_READONLY_PROTECT_DEF(type, name) YDB_READONLY_ACCESSOR_IMPL(name, type, protected:, type())
+#define YDB_READONLY_MUTABLE(type, name, defaultValue) YDB_READONLY_ACCESSOR_IMPL(name, type, mutable, defaultValue)
+#define YDB_READONLY_MUTABLE_DEF(type, name) YDB_READONLY_ACCESSOR_IMPL(name, type, mutable, type())
+
+#define YDB_READONLY_ACCESSOR_OPT_IMPL(name, type, declSpecifiers) \
+private:\
+ declSpecifiers std::optional<type> name;\
+public:\
+ bool Has##name() const noexcept {\
+ return name.has_value();\
+ }\
+ const type& Get##name##Unsafe() const noexcept {\
+ return *name;\
+ }\
+ type& Get##name##Unsafe() noexcept {\
+ return *name;\
+ }\
+ const std::optional<type>& Get##name##Optional() const noexcept {\
+ return name;\
+ }\
+ std::optional<type> Get##name##MaybeDetach() const noexcept {\
+ if (name) {\
+ return *name;\
+ } else {\
+ return {};\
+ }\
+ }\
+ type Get##name##Def(const type defValue) const noexcept {\
+ return name.value_or(defValue);\
+ }\
+ const type* Get##name##Safe() const noexcept {\
+ return name ? &name.value() : nullptr;\
+ }\
+private:
+
+#define YDB_ACCESSOR_OPT_IMPL(name, type, declSpecifiers) \
+YDB_READONLY_ACCESSOR_OPT_IMPL(name, type, declSpecifiers)\
+public:\
+ auto& Set##name(const type& value) noexcept {\
+ name = value;\
+ return *this;\
+ }\
+ auto& Set##name(type&& value) noexcept {\
+ name = std::move(value);\
+ return *this;\
+ }\
+ auto& Set##name(std::optional<type>&& value) noexcept {\
+ name = std::move(value);\
+ return *this;\
+ }\
+ auto& Set##name(const std::optional<type>& value) noexcept {\
+ name = value;\
+ return *this;\
+ }\
+ auto& Drop##name() noexcept {\
+ name = {};\
+ return *this;\
+ }\
+ std::optional<type>& Mutable##name##Optional() noexcept {\
+ return name;\
+ }\
+private:
+
+#define YDB_ACCESSOR_OPT_MUTABLE_IMPL(name, type, declSpecifiers) \
+YDB_READONLY_ACCESSOR_OPT_IMPL(name, type, declSpecifiers)\
+public:\
+ const auto& Set##name(const type& value) const noexcept {\
+ name = value;\
+ return *this;\
+ }\
+ const auto& Set##name(type&& value) const noexcept {\
+ name = std::move(value);\
+ return *this;\
+ }\
+ const auto& Drop##name() const noexcept {\
+ name = {};\
+ return *this;\
+ }\
+ std::optional<type>& Mutable##name##Optional() const noexcept {\
+ return name;\
+ }\
+private:
+
+#define YDB_OPT(type, name) YDB_ACCESSOR_OPT_IMPL(name, type, private:)
+#define YDB_OPT_MUTABLE(type, name) YDB_ACCESSOR_OPT_MUTABLE_IMPL(name, type, mutable)
+#define YDB_OPT_PROTECTED(type, name) YDB_ACCESSOR_OPT_IMPL(name, type, protected:)
+#define YDB_READONLY_OPT(type, name) YDB_READONLY_ACCESSOR_OPT_IMPL(name, type, private:)
+#define YDB_READONLY_OPT_PROTECTED(type, name) YDB_READONLY_ACCESSOR_OPT_IMPL(name, type, protected:)