Reorder list templates.

This commit is contained in:
Egor Pugin 2021-04-07 00:29:07 +03:00
parent 409aa5296f
commit 6e3259593a

View File

@ -18,34 +18,6 @@
namespace tesseract {
template <typename CONTAINER, typename ITERATOR_TYPE, typename CLASSNAME>
class X_LIST : public CONTAINER {
public:
X_LIST() = default;
X_LIST(const X_LIST &) = delete;
X_LIST &operator=(const X_LIST &) = delete;
~X_LIST() {
clear();
}
/* delete elements */
void clear() {
CONTAINER::internal_clear([](void *link) {delete reinterpret_cast<CLASSNAME *>(link);});
}
/* Become a deep copy of src_list */
template <typename U>
void deep_copy(const U *src_list, CLASSNAME *(*copier)(const CLASSNAME *)) {
static_assert(std::is_base_of_v<X_LIST, U>);
X_ITER<ITERATOR_TYPE, CLASSNAME> from_it(const_cast<U *>(src_list));
X_ITER<ITERATOR_TYPE, CLASSNAME> to_it(this);
for (from_it.mark_cycle_pt(); !from_it.cycled_list(); from_it.forward())
to_it.add_after_then_move((*copier)(from_it.data()));
}
};
template <typename CONTAINER, typename CLASSNAME>
class X_ITER : public CONTAINER {
public:
@ -67,6 +39,32 @@ public:
}
};
template <typename CONTAINER, typename ITERATOR_TYPE, typename CLASSNAME>
class X_LIST : public CONTAINER {
public:
X_LIST() = default;
X_LIST(const X_LIST &) = delete;
X_LIST &operator=(const X_LIST &) = delete;
~X_LIST() {
clear();
}
/* delete elements */
void clear() {
CONTAINER::internal_clear([](void *link) {delete reinterpret_cast<CLASSNAME *>(link);});
}
/* Become a deep copy of src_list */
template <typename U>
void deep_copy(const U *src_list, CLASSNAME *(*copier)(const CLASSNAME *)) {
X_ITER<ITERATOR_TYPE, CLASSNAME> from_it(const_cast<U *>(src_list));
X_ITER<ITERATOR_TYPE, CLASSNAME> to_it(this);
for (from_it.mark_cycle_pt(); !from_it.cycled_list(); from_it.forward())
to_it.add_after_then_move((*copier)(from_it.data()));
}
};
} // namespace tesseract
#endif