From 59c0311ed755b50b11635b43964f53d9b3f5942b Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 17 Dec 2025 10:21:57 -0500 Subject: [PATCH] xo-alloc2: work on AllocIterator [WIP] --- include/xo/alloc2/AllocIterator.hpp | 13 ++++ include/xo/alloc2/alloc/AAllocIterator.hpp | 43 +++++++++++++ include/xo/alloc2/alloc/AllocIterator.hpp | 24 ++++++++ .../xo/alloc2/alloc/IAllocIterator_Any.hpp | 47 +++++++++++++++ .../xo/alloc2/alloc/IAllocIterator_Xfer.hpp | 60 +++++++++++++++++++ include/xo/alloc2/alloc/RAllocIterator.hpp | 42 +++++++++++++ src/alloc2/CMakeLists.txt | 2 + src/alloc2/IAllocIterator_Any.cpp | 40 +++++++++++++ 8 files changed, 271 insertions(+) create mode 100644 include/xo/alloc2/AllocIterator.hpp create mode 100644 include/xo/alloc2/alloc/AAllocIterator.hpp create mode 100644 include/xo/alloc2/alloc/AllocIterator.hpp create mode 100644 include/xo/alloc2/alloc/IAllocIterator_Any.hpp create mode 100644 include/xo/alloc2/alloc/IAllocIterator_Xfer.hpp create mode 100644 include/xo/alloc2/alloc/RAllocIterator.hpp create mode 100644 src/alloc2/IAllocIterator_Any.cpp diff --git a/include/xo/alloc2/AllocIterator.hpp b/include/xo/alloc2/AllocIterator.hpp new file mode 100644 index 0000000..a741dd7 --- /dev/null +++ b/include/xo/alloc2/AllocIterator.hpp @@ -0,0 +1,13 @@ +/** @file AllocIterator.hpp + * + * @author Roland Conybeare, Dec 2025 + **/ + +#pragma once + +#include "alloc/AAllocIterator.hpp" +#include "alloc/IAllocIterator_Any.hpp" +#include "alloc/IAllocIterator_Xfer.hpp" +#include "alloc/RAllocIterator.hpp" + +/* end AllocIterator.hpp */ diff --git a/include/xo/alloc2/alloc/AAllocIterator.hpp b/include/xo/alloc2/alloc/AAllocIterator.hpp new file mode 100644 index 0000000..c548493 --- /dev/null +++ b/include/xo/alloc2/alloc/AAllocIterator.hpp @@ -0,0 +1,43 @@ +/** @file AAllocIterator.hpp + * + * @author Roland Conybeare, Dec 2025 + **/ + +#pragma once + +#include "alloc/AllocInfo.hpp" +#include + +namespace xo { + namespace mm { + using Copaque = const void *; + using Opaque = void *; + + /** forward decl for obj **/ + struct ObjAllocIterator; + + /** @class AAllocIterator + * @brief Abstract facet for iterating over allocs + * + * Iterator refers to an AllocInfo instance. + **/ + struct AAllocIterator { + using obj_AAllocIterator = xo::facet::obj; + + /** RTTI: unique id# for actual runtime *data* representation **/ + virtual int32_t _typeseq() const noexcept = 0; + /** retrieve AllocInfo for current iterator position + **/ + virtual AllocInfo deref(Copaque d) const noexcept = 0; + /** compare alloc iterators @p d and @p other for equality **/ + virtual int compare(Copaque d, + const obj_AAllocIterator & other) const noexcept = 0; + /** advance iterator to next position **/ + virtual void next(Opaque d) const noexcept = 0; + /** retreat iterator to previous position **/ + virtual void prev(Opaque d) const noexcept = 0; + }; + } /*namespace mm*/ +} /*namespace xo*/ + +/* end AllocIterator.hpp */ diff --git a/include/xo/alloc2/alloc/AllocIterator.hpp b/include/xo/alloc2/alloc/AllocIterator.hpp new file mode 100644 index 0000000..af5c7e8 --- /dev/null +++ b/include/xo/alloc2/alloc/AllocIterator.hpp @@ -0,0 +1,24 @@ +/** @file AllocIterator.hpp + * + * @author Roland Conybeare, Dec 2025 + **/ + +#pragma once + +namespace xo { + namespace mm { + + /** @class AllocIterator + * @brief iterator over arena allocations. + * + * Intended for instrumentation/diagnostics. + * Not needed for normal operator + **/ + struct AllocIterator { + + }; + + } /*namespace mm*/ +} /*namespace xo*/ + +/* end AllocIterator.hpp */ diff --git a/include/xo/alloc2/alloc/IAllocIterator_Any.hpp b/include/xo/alloc2/alloc/IAllocIterator_Any.hpp new file mode 100644 index 0000000..388c5aa --- /dev/null +++ b/include/xo/alloc2/alloc/IAllocIterator_Any.hpp @@ -0,0 +1,47 @@ +/** @file IAllocIter_Any.hpp + * + * @author Roland Conybeare, Dec 2025 + **/ + +#include "AAllocIterator.hpp" + +namespace xo { + namespace mm { struct IAllocIterator_Any; } + + namespace facet { + template <> + struct FacetImplementation { + using ImplType = xo::mm::IAllocIterator_Any; + }; + } + + namespace mm { + /** @class IAllocIterator_Any + * @brief AllocIterator implementation for empty variant instance + **/ + struct IAllocIterator_Any : public AAllocIterator { + const AAllocIterator * iface() const { return std::launder(this); } + + // from AAllocIterator + int32_t _typeseq() const noexcept override { return s_typeseq; } + + // const methods + [[noreturn]] AllocInfo deref(Copaque) const noexcept override { _fatal(); } + [[noreturn]] int compare(Copaque, + const obj_AAllocIterator &) const noexcept override { _fatal(); } + + // non-const methods + [[noreturn]] void next(Opaque) const noexcept override { _fatal(); } + [[noreturn]] void prev(Opaque) const noexcept override { _fatal(); } + + private: + [[noreturn]] static void _fatal(); + + public: + static int32_t s_typeseq; + static bool _valid; + }; + } /*namespace mm*/ +} /*namespace xo*/ + +/* end IAllocIter_Any.hpp */ diff --git a/include/xo/alloc2/alloc/IAllocIterator_Xfer.hpp b/include/xo/alloc2/alloc/IAllocIterator_Xfer.hpp new file mode 100644 index 0000000..604b4f0 --- /dev/null +++ b/include/xo/alloc2/alloc/IAllocIterator_Xfer.hpp @@ -0,0 +1,60 @@ +/** @file IAllocIterator_Xfer.hpp + * + * @author Roland Conybeare, Dec 2025 + **/ + +#include "AAllocIterator.hpp" + +namespace xo { + namespace mm { + /** @class IAllocIterator_Xfer + * @brief Adapts typed alloc iterator implementation + * @tparam IAllocIterator_DRepr to type-erased + * @ref AAllocIterator instance + **/ + template + struct IAllocIterator_Xfer : public AAllocIterator { + using Impl = IAllocIterator_DRepr; + + static const DRepr & _dcast(Copaque d) { return *(const DRepr *)d; } + static DRepr & _dcast(Opaque d) { return *(DRepr *)d; } + + // from AAllocIterator + + // const methods + + int32_t _typeseq() const noexcept override { return s_typeseq; } + AllocInfo deref(Copaque d) + const noexcept override { return I::deref(_dcast(d)); } + int compare(Copaque d, + const obj_AAllocIterator & other) + const noexcept override + { return I::compare(_dcast(d), other); } + + // non-const methods + + void next(Opaque d) const noexcept override { I::prev(_dcast(d)); } + void prev(Opaque d) const noexcept override { I::next(_dcast(d)); } + + private: + using I = Impl; + + public: + static int32_t s_typeseq; + static bool _valid; + }; + + template + int32_t + IAllocIterator_Xfer::s_typeseq + = facet::typeseq::id(); + + template + bool + IAllocIterator_Xfer::_valid + = facet::valid_facet_implementation(); + } /*namespace mm*/ +} /*namespace xo*/ + +/* end IAllocIterator_Xfer.hpp */ diff --git a/include/xo/alloc2/alloc/RAllocIterator.hpp b/include/xo/alloc2/alloc/RAllocIterator.hpp new file mode 100644 index 0000000..9a986f6 --- /dev/null +++ b/include/xo/alloc2/alloc/RAllocIterator.hpp @@ -0,0 +1,42 @@ +/** @file RAllocIterator.hpp + * + * @author Roland Conybeare, Dec 2025 + **/ + +#include "AAllocIterator.hpp" +#include + +namespace xo { + namespace mm { + /* @class RAllocIterator */ + template + struct RAllocIterator : public Object { + private: + using O = Object; + public: + using ObjectType = Object; + using DataPtr = Object::DataPtr; + + RAllocIterator() {} + RAllocIterator(Object::DataPtr data) : Object{std::move(data)} {} + + int32_t _typeseq() const noexcept { return O::iface()->_typeseq(); } + + static bool _valid; + }; + + template + bool + RAllocIterator::_valid = facet::valid_object_router(); + } /*namespace mm*/ + + namespace facet { + template + struct RoutingFor { + using RoutingType = xo::mm::RAllocIterator; + }; + } +} /*namespace xo*/ + +/* end RAllocIterator.hpp */ diff --git a/src/alloc2/CMakeLists.txt b/src/alloc2/CMakeLists.txt index 0e10689..0b94e80 100644 --- a/src/alloc2/CMakeLists.txt +++ b/src/alloc2/CMakeLists.txt @@ -10,6 +10,8 @@ set(SELF_SRCS IAllocator_Any.cpp IAllocator_DArena.cpp + IAllocIterator_Any.cpp + ICollector_Any.cpp IGCObject_Any.cpp IAllocator_DX1Collector.cpp diff --git a/src/alloc2/IAllocIterator_Any.cpp b/src/alloc2/IAllocIterator_Any.cpp new file mode 100644 index 0000000..f21acc0 --- /dev/null +++ b/src/alloc2/IAllocIterator_Any.cpp @@ -0,0 +1,40 @@ +/** @file IAllocIterator_Any.cpp + * + * @author Roland Conybeare, Dec 2025 + **/ + +#include "alloc/IAllocIterator_Any.hpp" +#include + +namespace xo { + namespace mm { + using xo::facet::DVariantPlaceholder; + using xo::facet::typeseq; + using xo::facet::valid_facet_implementation; + + void + IAllocIterator_Any::_fatal() { + /* control here on uninitialized IAllocator_Any. + * Initialized instance will have specific implementation type + * e.g. IAllocator_Xfer + */ + + std::cerr << "fatal" + << ": attempt to call uninitialized" + << " IAllocIterator_Any method" + << std::endl; + std::terminate(); + } + + int32_t + IAllocIterator_Any::s_typeseq = typeseq::id(); + + bool + IAllocIterator_Any::_valid = valid_facet_implementation(); + + + } /*namespace mm*/ +} /*namespace xo*/ + +/* end IAllocIterator_Any.cpp */