aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/deprecated/accessors/accessors.h
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/deprecated/accessors/accessors.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/deprecated/accessors/accessors.h')
-rw-r--r--library/cpp/deprecated/accessors/accessors.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/library/cpp/deprecated/accessors/accessors.h b/library/cpp/deprecated/accessors/accessors.h
new file mode 100644
index 0000000000..6d4b1da3ad
--- /dev/null
+++ b/library/cpp/deprecated/accessors/accessors.h
@@ -0,0 +1,83 @@
+#pragma once
+
+#include "accessors_impl.h"
+
+namespace NAccessors {
+ /*
+ * Adds API compatibility between different types representing memory regions.
+ *
+ * i.e. this will work:
+ *
+ * TString t;
+ * const char* beg = NAccessors::Begin(t); // t.begin()
+ * const char* end = NAccessors::End(t); // t.end()
+ * size_t sz = NAccessors::Size(t); // t.size()
+ *
+ * as well as this:
+ *
+ * ui64 t;
+ * const ui64* beg = NAccessors::Begin(t); // &t
+ * const ui64* end = NAccessors::End(t); // &t + 1
+ * size_t sz = NAccessors::Size(t); // 1
+ *
+ * Both will give you begin, end and size of the underlying memory region.
+ */
+
+ template <typename T>
+ inline const typename TMemoryTraits<T>::TElementType* Begin(const T& t) {
+ return NPrivate::TBegin<T>::Get(t);
+ }
+
+ template <typename T>
+ inline const typename TMemoryTraits<T>::TElementType* End(const T& t) {
+ return NPrivate::TEnd<T>::Get(t);
+ }
+
+ template <typename T>
+ inline size_t Size(const T& t) {
+ return End(t) - Begin(t);
+ }
+
+ /**
+ * This gives some unification in terms of memory manipulation.
+ */
+
+ template <typename T>
+ inline void Reserve(T& t, size_t sz) {
+ NPrivate::TReserve<T>::Do(t, sz);
+ }
+
+ template <typename T>
+ inline void Resize(T& t, size_t sz) {
+ NPrivate::TResize<T>::Do(t, sz);
+ }
+
+ template <typename T>
+ inline void Clear(T& t) {
+ NPrivate::TClear<T, false>::Do(t);
+ }
+
+ template <typename T>
+ inline void Init(T& t) {
+ NPrivate::TClear<T, true>::Do(t);
+ }
+
+ template <typename T>
+ inline void Append(T& t, const typename TMemoryTraits<T>::TElementType& v) {
+ NPrivate::TAppend<T>::Do(t, v);
+ }
+
+ template <typename T>
+ inline void Append(T& t,
+ const typename TMemoryTraits<T>::TElementType* beg,
+ const typename TMemoryTraits<T>::TElementType* end) {
+ NPrivate::TAppendRegion<T>::Do(t, beg, end);
+ }
+
+ template <typename T>
+ inline void Assign(T& t,
+ const typename TMemoryTraits<T>::TElementType* beg,
+ const typename TMemoryTraits<T>::TElementType* end) {
+ NPrivate::TAssign<T>::Do(t, beg, end);
+ }
+}