aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/deprecated/accessors
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
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/deprecated/accessors')
-rw-r--r--library/cpp/deprecated/accessors/README.md5
-rw-r--r--library/cpp/deprecated/accessors/accessors.cpp1
-rw-r--r--library/cpp/deprecated/accessors/accessors.h83
-rw-r--r--library/cpp/deprecated/accessors/accessors_impl.cpp1
-rw-r--r--library/cpp/deprecated/accessors/accessors_impl.h420
-rw-r--r--library/cpp/deprecated/accessors/accessors_ut.cpp92
-rw-r--r--library/cpp/deprecated/accessors/memory_traits.cpp1
-rw-r--r--library/cpp/deprecated/accessors/memory_traits.h168
-rw-r--r--library/cpp/deprecated/accessors/ut/ya.make9
-rw-r--r--library/cpp/deprecated/accessors/ya.make11
10 files changed, 791 insertions, 0 deletions
diff --git a/library/cpp/deprecated/accessors/README.md b/library/cpp/deprecated/accessors/README.md
new file mode 100644
index 00000000000..498f1203e00
--- /dev/null
+++ b/library/cpp/deprecated/accessors/README.md
@@ -0,0 +1,5 @@
+Unified accessors for Arcadia containers and user types.
+
+Accessors implemented here mix different kinds of access at the wrong abstraction level, so they shouldn't be used.
+
+If you want begin/end/size for your containers, use std::begin, std::end, std::size. If you need generic reserve / resize / clear / insert, just use appropriate container methods or do your own overloads in place.
diff --git a/library/cpp/deprecated/accessors/accessors.cpp b/library/cpp/deprecated/accessors/accessors.cpp
new file mode 100644
index 00000000000..7d37e586fa6
--- /dev/null
+++ b/library/cpp/deprecated/accessors/accessors.cpp
@@ -0,0 +1 @@
+#include "accessors.h"
diff --git a/library/cpp/deprecated/accessors/accessors.h b/library/cpp/deprecated/accessors/accessors.h
new file mode 100644
index 00000000000..6d4b1da3ad7
--- /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);
+ }
+}
diff --git a/library/cpp/deprecated/accessors/accessors_impl.cpp b/library/cpp/deprecated/accessors/accessors_impl.cpp
new file mode 100644
index 00000000000..0bf74cab7b2
--- /dev/null
+++ b/library/cpp/deprecated/accessors/accessors_impl.cpp
@@ -0,0 +1 @@
+#include "accessors_impl.h"
diff --git a/library/cpp/deprecated/accessors/accessors_impl.h b/library/cpp/deprecated/accessors/accessors_impl.h
new file mode 100644
index 00000000000..6b2b987351f
--- /dev/null
+++ b/library/cpp/deprecated/accessors/accessors_impl.h
@@ -0,0 +1,420 @@
+#pragma once
+
+#include "memory_traits.h"
+
+namespace NAccessors {
+ namespace NPrivate {
+ template <typename Ta>
+ struct TMemoryAccessorBase {
+ enum {
+ SimpleMemory = TMemoryTraits<Ta>::SimpleMemory,
+ ContinuousMemory = TMemoryTraits<Ta>::ContinuousMemory,
+ };
+
+ struct TBadAccessor;
+ };
+
+ template <typename Ta>
+ struct TBegin: public TMemoryAccessorBase<Ta> {
+ using TElementType = typename TMemoryTraits<Ta>::TElementType;
+
+ template <typename Tb>
+ struct TNoMemoryIndirectionBegin {
+ static const TElementType* Get(const Tb& b) {
+ return (const TElementType*)&b;
+ }
+ };
+
+ template <typename Tb>
+ struct TIndirectMemoryRegionBegin {
+ Y_HAS_MEMBER(Begin);
+ Y_HAS_MEMBER(begin);
+
+ template <typename Tc>
+ struct TByBegin {
+ static const TElementType* Get(const Tc& b) {
+ return (const TElementType*)b.Begin();
+ }
+ };
+
+ template <typename Tc>
+ struct TBybegin {
+ static const TElementType* Get(const Tc& b) {
+ return (const TElementType*)b.begin();
+ }
+ };
+
+ using TGet = std::conditional_t<THasBegin<Tb>::value, TByBegin<Tb>, TBybegin<Tb>>;
+
+ static const TElementType* Get(const Tb& b) {
+ return TGet::Get(b);
+ }
+ };
+
+ using TGet = std::conditional_t<
+ TMemoryAccessorBase<Ta>::SimpleMemory,
+ TNoMemoryIndirectionBegin<Ta>,
+ std::conditional_t<
+ TMemoryAccessorBase<Ta>::ContinuousMemory,
+ TIndirectMemoryRegionBegin<Ta>,
+ typename TMemoryAccessorBase<Ta>::TBadAccessor>>;
+
+ static const TElementType* Get(const Ta& b) {
+ return TGet::Get(b);
+ }
+ };
+
+ template <typename Ta>
+ struct TEnd: public TMemoryAccessorBase<Ta> {
+ using TElementType = typename TMemoryTraits<Ta>::TElementType;
+
+ template <typename Tb>
+ struct TNoMemoryIndirectionEnd {
+ static const TElementType* Get(const Tb& b) {
+ return (const TElementType*)(&b + 1);
+ }
+ };
+
+ template <typename Tb>
+ struct TIndirectMemoryRegionEnd {
+ Y_HAS_MEMBER(End);
+ Y_HAS_MEMBER(end);
+
+ template <typename Tc>
+ struct TByEnd {
+ static const TElementType* Get(const Tc& b) {
+ return (const TElementType*)b.End();
+ }
+ };
+
+ template <typename Tc>
+ struct TByend {
+ static const TElementType* Get(const Tc& b) {
+ return (const TElementType*)b.end();
+ }
+ };
+
+ using TGet = std::conditional_t<THasEnd<Tb>::value, TByEnd<Tb>, TByend<Tb>>;
+
+ static const TElementType* Get(const Tb& b) {
+ return TGet::Get(b);
+ }
+ };
+
+ using TGet = std::conditional_t<
+ TMemoryAccessorBase<Ta>::SimpleMemory,
+ TNoMemoryIndirectionEnd<Ta>,
+ std::conditional_t<
+ TMemoryAccessorBase<Ta>::ContinuousMemory,
+ TIndirectMemoryRegionEnd<Ta>,
+ typename TMemoryAccessorBase<Ta>::TBadAccessor>>;
+
+ static const TElementType* Get(const Ta& b) {
+ return TGet::Get(b);
+ }
+ };
+
+ template <typename Ta, bool Init>
+ struct TClear: public TMemoryAccessorBase<Ta> {
+ template <typename Tb>
+ struct TNoMemoryIndirectionClear {
+ static void Do(Tb& b) {
+ Zero(b);
+ }
+ };
+
+ template <typename Tb>
+ struct TIndirectMemoryRegionClear {
+ Y_HAS_MEMBER(Clear);
+ Y_HAS_MEMBER(clear);
+
+ template <typename Tc>
+ struct TByClear {
+ static void Do(Tc& b) {
+ b.Clear();
+ }
+ };
+
+ template <typename Tc>
+ struct TByclear {
+ static void Do(Tc& b) {
+ b.clear();
+ }
+ };
+
+ template <typename Tc>
+ struct TByNone {
+ static void Do(Tc& b) {
+ if (!Init)
+ b = Tc();
+ }
+ };
+
+ using TDo = std::conditional_t<
+ THasClear<Tb>::value,
+ TByClear<Tb>,
+ std::conditional_t<
+ THasclear<Tb>::value,
+ TByclear<Tb>,
+ TByNone<Tb>>>;
+
+ static void Do(Tb& b) {
+ TDo::Do(b);
+ }
+ };
+
+ using TDo = std::conditional_t<TMemoryAccessorBase<Ta>::SimpleMemory, TNoMemoryIndirectionClear<Ta>, TIndirectMemoryRegionClear<Ta>>;
+
+ static void Do(Ta& b) {
+ TDo::Do(b);
+ }
+ };
+
+ template <typename Tb>
+ struct TReserve {
+ Y_HAS_MEMBER(Reserve);
+ Y_HAS_MEMBER(reserve);
+
+ template <typename Tc>
+ struct TByReserve {
+ static void Do(Tc& b, size_t sz) {
+ b.Reserve(sz);
+ }
+ };
+
+ template <typename Tc>
+ struct TByreserve {
+ static void Do(Tc& b, size_t sz) {
+ b.reserve(sz);
+ }
+ };
+
+ template <typename Tc>
+ struct TByNone {
+ static void Do(Tc&, size_t) {
+ }
+ };
+
+ using TDo = std::conditional_t<
+ THasReserve<Tb>::value,
+ TByReserve<Tb>,
+ std::conditional_t<
+ THasreserve<Tb>::value,
+ TByreserve<Tb>,
+ TByNone<Tb>>>;
+
+ static void Do(Tb& b, size_t sz) {
+ TDo::Do(b, sz);
+ }
+ };
+
+ template <typename Tb>
+ struct TResize {
+ Y_HAS_MEMBER(Resize);
+ Y_HAS_MEMBER(resize);
+
+ template <typename Tc>
+ struct TByResize {
+ static void Do(Tc& b, size_t sz) {
+ b.Resize(sz);
+ }
+ };
+
+ template <typename Tc>
+ struct TByresize {
+ static void Do(Tc& b, size_t sz) {
+ b.resize(sz);
+ }
+ };
+
+ using TDo = std::conditional_t<THasResize<Tb>::value, TByResize<Tb>, TByresize<Tb>>;
+
+ static void Do(Tb& b, size_t sz) {
+ TDo::Do(b, sz);
+ }
+ };
+
+ template <typename Tb>
+ struct TAppend {
+ Y_HAS_MEMBER(Append);
+ Y_HAS_MEMBER(append);
+ Y_HAS_MEMBER(push_back);
+
+ template <typename Tc>
+ struct TByAppend {
+ using TElementType = typename TMemoryTraits<Tc>::TElementType;
+
+ static void Do(Tc& b, const TElementType& val) {
+ b.Append(val);
+ }
+ };
+
+ template <typename Tc>
+ struct TByappend {
+ using TElementType = typename TMemoryTraits<Tc>::TElementType;
+
+ static void Do(Tc& b, const TElementType& val) {
+ b.append(val);
+ }
+ };
+
+ template <typename Tc>
+ struct TBypush_back {
+ using TElementType = typename TMemoryTraits<Tc>::TElementType;
+
+ static void Do(Tc& b, const TElementType& val) {
+ b.push_back(val);
+ }
+ };
+
+ using TDo = std::conditional_t<
+ THasAppend<Tb>::value,
+ TByAppend<Tb>,
+ std::conditional_t<
+ THasappend<Tb>::value,
+ TByappend<Tb>,
+ TBypush_back<Tb>>>;
+
+ using TElementType = typename TMemoryTraits<Tb>::TElementType;
+
+ static void Do(Tb& b, const TElementType& val) {
+ TDo::Do(b, val);
+ }
+ };
+
+ template <typename Tb>
+ struct TAppendRegion {
+ Y_HAS_MEMBER(Append);
+ Y_HAS_MEMBER(append);
+ Y_HAS_MEMBER(insert);
+
+ template <typename Tc>
+ struct TByAppend {
+ using TElementType = typename TMemoryTraits<Tc>::TElementType;
+
+ static void Do(Tc& b, const TElementType* beg, const TElementType* end) {
+ b.Append(beg, end);
+ }
+ };
+
+ template <typename Tc>
+ struct TByappend {
+ using TElementType = typename TMemoryTraits<Tc>::TElementType;
+
+ static void Do(Tc& b, const TElementType* beg, const TElementType* end) {
+ b.append(beg, end);
+ }
+ };
+
+ template <typename Tc>
+ struct TByinsert {
+ using TElementType = typename TMemoryTraits<Tc>::TElementType;
+
+ static void Do(Tc& b, const TElementType* beg, const TElementType* end) {
+ b.insert(b.end(), beg, end);
+ }
+ };
+
+ template <typename Tc>
+ struct TByNone {
+ using TElementType = typename TMemoryTraits<Tc>::TElementType;
+
+ static void Do(Tc& b, const TElementType* beg, const TElementType* end) {
+ for (const TElementType* it = beg; it != end; ++it)
+ TAppend<Tc>::Do(b, *it);
+ }
+ };
+
+ using TDo = std::conditional_t<
+ THasAppend<Tb>::value,
+ TByAppend<Tb>,
+ std::conditional_t<
+ THasappend<Tb>::value,
+ TByappend<Tb>,
+ std::conditional_t<
+ THasinsert<Tb>::value,
+ TByinsert<Tb>,
+ TByNone<Tb>>>>;
+
+ using TElementType = typename TMemoryTraits<Tb>::TElementType;
+
+ static void Do(Tb& b, const TElementType* beg, const TElementType* end) {
+ TDo::Do(b, beg, end);
+ }
+ };
+
+ template <typename Ta>
+ struct TAssign: public TMemoryAccessorBase<Ta> {
+ using TElementType = typename TMemoryTraits<Ta>::TElementType;
+
+ template <typename Tb>
+ struct TNoMemoryIndirectionAssign {
+ static void Do(Tb& b, const TElementType* beg, const TElementType* end) {
+ if (sizeof(Tb) == sizeof(TElementType) && end - beg > 0) {
+ memcpy(&b, beg, sizeof(Tb));
+ } else if (end - beg > 0) {
+ memcpy(&b, beg, Min<size_t>((end - beg) * sizeof(TElementType), sizeof(Tb)));
+ } else {
+ Zero(b);
+ }
+ }
+ };
+
+ template <typename Tb>
+ struct TIndirectMemoryRegionAssign {
+ Y_HAS_MEMBER(Assign);
+ Y_HAS_MEMBER(assign);
+
+ template <typename Tc>
+ struct TByAssign {
+ static void Do(Tc& b, const TElementType* beg, const TElementType* end) {
+ b.Assign(beg, end);
+ }
+ };
+
+ template <typename Tc>
+ struct TByassign {
+ static void Do(Tc& b, const TElementType* beg, const TElementType* end) {
+ b.assign(beg, end);
+ }
+ };
+
+ template <typename Tc>
+ struct TByClearAppend {
+ static void Do(Tc& b, const TElementType* beg, const TElementType* end) {
+ TClear<Tc, false>::Do(b);
+ TAppendRegion<Tc>::Do(b, beg, end);
+ }
+ };
+
+ template <typename Tc>
+ struct TByConstruction {
+ static void Do(Tc& b, const TElementType* beg, const TElementType* end) {
+ b = Tc(beg, end);
+ }
+ };
+
+ using TDo = std::conditional_t<
+ THasAssign<Tb>::value,
+ TByAssign<Tb>,
+ std::conditional_t<
+ THasassign<Tb>::value,
+ TByassign<Tb>,
+ std::conditional_t<
+ TMemoryTraits<Tb>::OwnsMemory,
+ TByClearAppend<Tb>,
+ TByConstruction<Tb>>>>;
+
+ static void Do(Tb& b, const TElementType* beg, const TElementType* end) {
+ TDo::Do(b, beg, end);
+ }
+ };
+
+ using TDo = std::conditional_t<TMemoryAccessorBase<Ta>::SimpleMemory, TNoMemoryIndirectionAssign<Ta>, TIndirectMemoryRegionAssign<Ta>>;
+
+ static void Do(Ta& b, const TElementType* beg, const TElementType* end) {
+ TDo::Do(b, beg, end);
+ }
+ };
+ }
+}
diff --git a/library/cpp/deprecated/accessors/accessors_ut.cpp b/library/cpp/deprecated/accessors/accessors_ut.cpp
new file mode 100644
index 00000000000..a9bdc9fcc42
--- /dev/null
+++ b/library/cpp/deprecated/accessors/accessors_ut.cpp
@@ -0,0 +1,92 @@
+#include "accessors.h"
+
+#include <library/cpp/testing/unittest/registar.h>
+
+#include <util/generic/buffer.h>
+#include <util/generic/vector.h>
+
+#include <array>
+
+class TAccessorsTest: public TTestBase {
+ UNIT_TEST_SUITE(TAccessorsTest);
+ UNIT_TEST(TestAccessors);
+ UNIT_TEST_SUITE_END();
+
+private:
+ template <typename T>
+ void TestRead(const T& t, const char* comm) {
+ const char* beg = (const char*)NAccessors::Begin(t);
+ const char* end = (const char*)NAccessors::End(t);
+ long sz = NAccessors::Size(t) * sizeof(typename TMemoryTraits<T>::TElementType);
+
+ UNIT_ASSERT_VALUES_EQUAL_C(end - beg, sz, comm);
+ }
+
+ template <typename T>
+ void TestWrite(const char* comm) {
+ typename TMemoryTraits<T>::TElementType val[4] = {'t', 'e', 's', 't'};
+ T t;
+ NAccessors::Init(t);
+ NAccessors::Reserve(t, 6);
+
+ size_t sz = NAccessors::Size(t);
+ UNIT_ASSERT_VALUES_EQUAL_C(0u, sz, comm);
+
+ NAccessors::Append(t, 'a');
+ sz = NAccessors::Size(t);
+ UNIT_ASSERT_VALUES_EQUAL_C(1u, sz, comm);
+
+ NAccessors::Append(t, val, val + 4);
+ sz = NAccessors::Size(t);
+ UNIT_ASSERT_VALUES_EQUAL_C(5u, sz, comm);
+
+ NAccessors::Clear(t);
+
+ sz = NAccessors::Size(t);
+ UNIT_ASSERT_VALUES_EQUAL_C(0u, sz, comm);
+ }
+
+ void TestAccessors() {
+ TestRead('a', "char");
+ TestRead(1, "int");
+
+ int t[4] = {0, 1, 2, 3};
+
+ TestRead(t, "int[4]");
+
+ TStringBuf sbuf = "test";
+
+ TestRead(sbuf, "TStringBuf");
+
+ TUtf16String wtr;
+ wtr.resize(10, 1024);
+
+ TestRead(wtr, "TUtf16String");
+
+ TBuffer buf;
+ buf.Resize(30);
+
+ TestRead(buf, "TBuffer");
+
+ TVector<ui64> vec(10, 100);
+
+ TestRead(vec, "TVector<ui64>");
+
+ TestWrite<TString>("TString");
+ TestWrite<TVector<char>>("TVector<char>");
+ TestWrite<TBuffer>("TBuffer");
+ TestWrite<TVector<ui64>>("TVector<ui64>");
+ TestWrite<TUtf16String>("TUtf16String");
+
+ std::array<TString, 10> sarr;
+ NAccessors::Init(sarr);
+ NAccessors::Clear(sarr);
+
+ std::array<char, 10> carr;
+ NAccessors::Init(carr);
+ NAccessors::Clear(carr);
+ TestRead(carr, "std::array<char, 10>");
+ }
+};
+
+UNIT_TEST_SUITE_REGISTRATION(TAccessorsTest)
diff --git a/library/cpp/deprecated/accessors/memory_traits.cpp b/library/cpp/deprecated/accessors/memory_traits.cpp
new file mode 100644
index 00000000000..df53026cf4f
--- /dev/null
+++ b/library/cpp/deprecated/accessors/memory_traits.cpp
@@ -0,0 +1 @@
+#include "memory_traits.h"
diff --git a/library/cpp/deprecated/accessors/memory_traits.h b/library/cpp/deprecated/accessors/memory_traits.h
new file mode 100644
index 00000000000..aa837705d3d
--- /dev/null
+++ b/library/cpp/deprecated/accessors/memory_traits.h
@@ -0,0 +1,168 @@
+#pragma once
+
+#include <util/generic/array_ref.h>
+#include <util/memory/blob.h>
+#include <util/memory/tempbuf.h>
+#include <util/generic/buffer.h>
+#include <util/generic/strbuf.h>
+#include <util/generic/string.h>
+#include <util/generic/vector.h>
+#include <util/generic/typetraits.h>
+
+#include <array>
+#include <string>
+#include <utility>
+
+template <typename T>
+struct TMemoryTraits {
+ enum {
+ SimpleMemory = std::is_arithmetic<T>::value,
+ ContinuousMemory = SimpleMemory,
+ OwnsMemory = SimpleMemory,
+ };
+
+ using TElementType = T;
+};
+
+template <typename T, size_t n>
+struct TMemoryTraits<T[n]> {
+ enum {
+ SimpleMemory = TMemoryTraits<T>::SimpleMemory,
+ ContinuousMemory = SimpleMemory,
+ OwnsMemory = SimpleMemory,
+ };
+
+ using TElementType = T;
+};
+
+template <typename T, size_t n>
+struct TMemoryTraits<std::array<T, n>> {
+ enum {
+ SimpleMemory = TMemoryTraits<T>::SimpleMemory,
+ ContinuousMemory = SimpleMemory,
+ OwnsMemory = SimpleMemory,
+ };
+
+ using TElementType = T;
+};
+
+template <typename A, typename B>
+struct TMemoryTraits<std::pair<A, B>> {
+ enum {
+ SimpleMemory = TMemoryTraits<A>::SimpleMemory && TMemoryTraits<B>::SimpleMemory,
+ ContinuousMemory = SimpleMemory,
+ OwnsMemory = SimpleMemory,
+ };
+
+ using TElementType = std::pair<A, B>;
+};
+
+template <>
+struct TMemoryTraits<TBuffer> {
+ enum {
+ SimpleMemory = false,
+ ContinuousMemory = true,
+ OwnsMemory = true,
+ };
+
+ using TElementType = char;
+};
+
+template <>
+struct TMemoryTraits<TTempBuf> {
+ enum {
+ SimpleMemory = false,
+ ContinuousMemory = true,
+ OwnsMemory = true,
+ };
+
+ using TElementType = char;
+};
+
+template <>
+struct TMemoryTraits< ::TBlob> {
+ enum {
+ SimpleMemory = false,
+ ContinuousMemory = true,
+ OwnsMemory = true,
+ };
+
+ using TElementType = char;
+};
+
+template <typename T>
+struct TElementDependentMemoryTraits {
+ enum {
+ SimpleMemory = false,
+ ContinuousMemory = TMemoryTraits<T>::SimpleMemory,
+ };
+
+ using TElementType = T;
+};
+
+template <typename T, typename TAlloc>
+struct TMemoryTraits<std::vector<T, TAlloc>>: public TElementDependentMemoryTraits<T> {
+ enum {
+ OwnsMemory = TMemoryTraits<T>::OwnsMemory
+ };
+};
+
+template <typename T, typename TAlloc>
+struct TMemoryTraits<TVector<T, TAlloc>>: public TMemoryTraits<std::vector<T, TAlloc>> {
+};
+
+template <typename T>
+struct TMemoryTraits<TTempArray<T>>: public TElementDependentMemoryTraits<T> {
+ enum {
+ OwnsMemory = TMemoryTraits<T>::OwnsMemory
+ };
+};
+
+template <typename T, typename TCharTraits, typename TAlloc>
+struct TMemoryTraits<std::basic_string<T, TCharTraits, TAlloc>>: public TElementDependentMemoryTraits<T> {
+ enum {
+ OwnsMemory = TMemoryTraits<T>::OwnsMemory
+ };
+};
+
+template <>
+struct TMemoryTraits<TString>: public TElementDependentMemoryTraits<char> {
+ enum {
+ OwnsMemory = true
+ };
+};
+
+template <>
+struct TMemoryTraits<TUtf16String>: public TElementDependentMemoryTraits<wchar16> {
+ enum {
+ OwnsMemory = true
+ };
+};
+
+template <typename T>
+struct TMemoryTraits<TArrayRef<T>>: public TElementDependentMemoryTraits<T> {
+ enum {
+ OwnsMemory = false
+ };
+};
+
+template <typename TCharType, typename TCharTraits>
+struct TMemoryTraits<TBasicStringBuf<TCharType, TCharTraits>>: public TElementDependentMemoryTraits<TCharType> {
+ enum {
+ OwnsMemory = false
+ };
+};
+
+template <>
+struct TMemoryTraits<TStringBuf>: public TElementDependentMemoryTraits<char> {
+ enum {
+ OwnsMemory = false
+ };
+};
+
+template <>
+struct TMemoryTraits<TWtringBuf>: public TElementDependentMemoryTraits<wchar16> {
+ enum {
+ OwnsMemory = false
+ };
+};
diff --git a/library/cpp/deprecated/accessors/ut/ya.make b/library/cpp/deprecated/accessors/ut/ya.make
new file mode 100644
index 00000000000..5ea976566f6
--- /dev/null
+++ b/library/cpp/deprecated/accessors/ut/ya.make
@@ -0,0 +1,9 @@
+UNITTEST_FOR(library/cpp/deprecated/accessors)
+
+OWNER(velavokr)
+
+SRCS(
+ accessors_ut.cpp
+)
+
+END()
diff --git a/library/cpp/deprecated/accessors/ya.make b/library/cpp/deprecated/accessors/ya.make
new file mode 100644
index 00000000000..e322026a1cb
--- /dev/null
+++ b/library/cpp/deprecated/accessors/ya.make
@@ -0,0 +1,11 @@
+LIBRARY()
+
+OWNER(elric)
+
+SRCS(
+ accessors.cpp
+ accessors_impl.cpp
+ memory_traits.cpp
+)
+
+END()