aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/deprecated/autoarray
diff options
context:
space:
mode:
authorvitalyisaev <vitalyisaev@ydb.tech>2023-11-30 13:26:22 +0300
committervitalyisaev <vitalyisaev@ydb.tech>2023-11-30 15:44:45 +0300
commit0a98fece5a9b54f16afeb3a94b3eb3105e9c3962 (patch)
tree291d72dbd7e9865399f668c84d11ed86fb190bbf /library/cpp/deprecated/autoarray
parentcb2c8d75065e5b3c47094067cb4aa407d4813298 (diff)
downloadydb-0a98fece5a9b54f16afeb3a94b3eb3105e9c3962.tar.gz
YQ Connector:Use docker-compose in integrational tests
Diffstat (limited to 'library/cpp/deprecated/autoarray')
-rw-r--r--library/cpp/deprecated/autoarray/README.md3
-rw-r--r--library/cpp/deprecated/autoarray/autoarray.cpp1
-rw-r--r--library/cpp/deprecated/autoarray/autoarray.h264
-rw-r--r--library/cpp/deprecated/autoarray/ya.make7
4 files changed, 275 insertions, 0 deletions
diff --git a/library/cpp/deprecated/autoarray/README.md b/library/cpp/deprecated/autoarray/README.md
new file mode 100644
index 0000000000..1d83147cee
--- /dev/null
+++ b/library/cpp/deprecated/autoarray/README.md
@@ -0,0 +1,3 @@
+Pre-C++11 vector-like container.
+
+Just use std::vector. If you need to fill your vector with custom-constructed data, use reserve+emplace_back (but make sure that your elements are movable).
diff --git a/library/cpp/deprecated/autoarray/autoarray.cpp b/library/cpp/deprecated/autoarray/autoarray.cpp
new file mode 100644
index 0000000000..15167f27f6
--- /dev/null
+++ b/library/cpp/deprecated/autoarray/autoarray.cpp
@@ -0,0 +1 @@
+#include "autoarray.h"
diff --git a/library/cpp/deprecated/autoarray/autoarray.h b/library/cpp/deprecated/autoarray/autoarray.h
new file mode 100644
index 0000000000..2aa12c5916
--- /dev/null
+++ b/library/cpp/deprecated/autoarray/autoarray.h
@@ -0,0 +1,264 @@
+#pragma once
+
+#include <util/system/compat.h>
+#include <util/system/yassert.h>
+#include <util/system/defaults.h>
+#include <util/system/sys_alloc.h>
+
+#include <util/generic/typetraits.h>
+#include <utility>
+
+#include <new>
+#include <util/generic/noncopyable.h>
+
+struct autoarray_getindex {
+ autoarray_getindex() = default;
+};
+
+struct aarr_b0 {
+ aarr_b0() = default;
+};
+
+struct aarr_nofill {
+ aarr_nofill() = default;
+};
+
+template <typename T>
+struct ynd_type_traits {
+ enum {
+ empty_destructor = TTypeTraits<T>::IsPod,
+ };
+};
+
+template <class T>
+class autoarray : TNonCopyable {
+protected:
+ T* arr;
+ size_t _size;
+
+private:
+ void AllocBuf(size_t siz) {
+ arr = nullptr;
+ _size = 0;
+ if (siz) {
+ arr = (T*)y_allocate(sizeof(T) * siz);
+ _size = siz;
+ }
+ }
+
+public:
+ using value_type = T;
+ using iterator = T*;
+ using const_iterator = const T*;
+
+ autoarray()
+ : arr(nullptr)
+ , _size(0)
+ {
+ }
+ autoarray(size_t siz) {
+ AllocBuf(siz);
+ T* curr = arr;
+ try {
+ for (T* end = arr + _size; curr != end; ++curr)
+ new (curr) T();
+ } catch (...) {
+ for (--curr; curr >= arr; --curr)
+ curr->~T();
+ y_deallocate(arr);
+ throw;
+ }
+ }
+ template <class A>
+ explicit autoarray(size_t siz, A& fill) {
+ AllocBuf(siz);
+ T* curr = arr;
+ try {
+ for (T* end = arr + _size; curr != end; ++curr)
+ new (curr) T(fill);
+ } catch (...) {
+ for (--curr; curr >= arr; --curr)
+ curr->~T();
+ y_deallocate(arr);
+ throw;
+ }
+ }
+ explicit autoarray(size_t siz, autoarray_getindex) {
+ AllocBuf(siz);
+ size_t nCurrent = 0;
+ try {
+ for (nCurrent = 0; nCurrent < _size; ++nCurrent)
+ new (&arr[nCurrent]) T(nCurrent);
+ } catch (...) {
+ for (size_t n = 0; n < nCurrent; ++n)
+ arr[n].~T();
+ y_deallocate(arr);
+ throw;
+ }
+ }
+ explicit autoarray(size_t siz, aarr_b0) {
+ AllocBuf(siz);
+ memset(arr, 0, _size * sizeof(T));
+ }
+ explicit autoarray(size_t siz, aarr_nofill) {
+ AllocBuf(siz);
+ }
+ template <class A>
+ explicit autoarray(const A* fill, size_t siz) {
+ AllocBuf(siz);
+ size_t nCurrent = 0;
+ try {
+ for (nCurrent = 0; nCurrent < _size; ++nCurrent)
+ new (&arr[nCurrent]) T(fill[nCurrent]);
+ } catch (...) {
+ for (size_t n = 0; n < nCurrent; ++n)
+ arr[n].~T();
+ y_deallocate(arr);
+ throw;
+ }
+ }
+ template <class A, class B>
+ explicit autoarray(const A* fill, const B* cfill, size_t siz) {
+ AllocBuf(siz);
+ size_t nCurrent = 0;
+ try {
+ for (nCurrent = 0; nCurrent < _size; ++nCurrent)
+ new (&arr[nCurrent]) T(fill[nCurrent], cfill);
+ } catch (...) {
+ for (size_t n = 0; n < nCurrent; ++n)
+ arr[n].~T();
+ y_deallocate(arr);
+ throw;
+ }
+ }
+ template <class A>
+ explicit autoarray(const A* fill, size_t initsiz, size_t fullsiz) {
+ AllocBuf(fullsiz);
+ size_t nCurrent = 0;
+ try {
+ for (nCurrent = 0; nCurrent < ((initsiz < _size) ? initsiz : _size); ++nCurrent)
+ new (&arr[nCurrent]) T(fill[nCurrent]);
+ for (; nCurrent < _size; ++nCurrent)
+ new (&arr[nCurrent]) T();
+ } catch (...) {
+ for (size_t n = 0; n < nCurrent; ++n)
+ arr[n].~T();
+ y_deallocate(arr);
+ throw;
+ }
+ }
+ template <class A>
+ explicit autoarray(const A* fill, size_t initsiz, size_t fullsiz, const T& dummy) {
+ AllocBuf(fullsiz);
+ size_t nCurrent = 0;
+ try {
+ for (nCurrent = 0; nCurrent < ((initsiz < _size) ? initsiz : _size); ++nCurrent)
+ new (&arr[nCurrent]) T(fill[nCurrent]);
+ for (; nCurrent < _size; ++nCurrent)
+ new (&arr[nCurrent]) T(dummy);
+ } catch (...) {
+ for (size_t n = 0; n < nCurrent; ++n)
+ arr[n].~T();
+ y_deallocate(arr);
+ throw;
+ }
+ }
+
+ template <class... R>
+ explicit autoarray(size_t siz, R&&... fill) {
+ AllocBuf(siz);
+ T* curr = arr;
+ try {
+ for (T* end = arr + _size; curr != end; ++curr)
+ new (curr) T(std::forward<R>(fill)...);
+ } catch (...) {
+ for (--curr; curr >= arr; --curr)
+ curr->~T();
+ y_deallocate(arr);
+ throw;
+ }
+ }
+ ~autoarray() {
+ if (_size) {
+ if (!ynd_type_traits<T>::empty_destructor)
+ for (T *curr = arr, *end = arr + _size; curr != end; ++curr)
+ curr->~T();
+ y_deallocate(arr);
+ }
+ }
+ T& operator[](size_t pos) {
+ Y_ASSERT(pos < _size);
+ return arr[pos];
+ }
+ const T& operator[](size_t pos) const {
+ Y_ASSERT(pos < _size);
+ return arr[pos];
+ }
+ size_t size() const {
+ return _size;
+ }
+ void swap(autoarray& with) {
+ T* tmp_arr = arr;
+ size_t tmp_size = _size;
+ arr = with.arr;
+ _size = with._size;
+ with.arr = tmp_arr;
+ with._size = tmp_size;
+ }
+ void resize(size_t siz) {
+ autoarray<T> tmp(arr, _size, siz);
+ swap(tmp);
+ }
+ void resize(size_t siz, const T& dummy) {
+ autoarray<T> tmp(arr, _size, siz, dummy);
+ swap(tmp);
+ }
+ T* rawpointer() {
+ return arr;
+ }
+ const T* operator~() const {
+ return arr;
+ }
+ T* begin() {
+ return arr;
+ }
+ T* end() {
+ return arr + _size;
+ }
+ T& back() {
+ Y_ASSERT(_size);
+ return arr[_size - 1];
+ }
+ bool empty() const {
+ return !_size;
+ }
+ bool operator!() const {
+ return !_size;
+ }
+ size_t operator+() const {
+ return _size;
+ }
+ const T* begin() const {
+ return arr;
+ }
+ const T* end() const {
+ return arr + _size;
+ }
+ const T& back() const {
+ Y_ASSERT(_size);
+ return arr[_size - 1];
+ }
+ //operator T*() { return arr; }
+};
+
+template <class T>
+inline bool operator==(const autoarray<T>& a, const autoarray<T>& b) {
+ size_t count = a.size();
+ if (count != b.size())
+ return false;
+ for (size_t i = 0; i < count; ++i) {
+ if (a[i] != b[i])
+ return false;
+ }
+ return true;
+}
diff --git a/library/cpp/deprecated/autoarray/ya.make b/library/cpp/deprecated/autoarray/ya.make
new file mode 100644
index 0000000000..4b055f8c29
--- /dev/null
+++ b/library/cpp/deprecated/autoarray/ya.make
@@ -0,0 +1,7 @@
+LIBRARY()
+
+SRCS(
+ autoarray.cpp
+)
+
+END()