xo-alloc2: work on AllocIterator [WIP]
This commit is contained in:
parent
bc1f669ec7
commit
1383c477f0
8 changed files with 271 additions and 0 deletions
13
xo-alloc2/include/xo/alloc2/AllocIterator.hpp
Normal file
13
xo-alloc2/include/xo/alloc2/AllocIterator.hpp
Normal file
|
|
@ -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 */
|
||||
43
xo-alloc2/include/xo/alloc2/alloc/AAllocIterator.hpp
Normal file
43
xo-alloc2/include/xo/alloc2/alloc/AAllocIterator.hpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/** @file AAllocIterator.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "alloc/AllocInfo.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
using Copaque = const void *;
|
||||
using Opaque = void *;
|
||||
|
||||
/** forward decl for obj<AAllocIterator> **/
|
||||
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<AAllocIterator>;
|
||||
|
||||
/** 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 */
|
||||
24
xo-alloc2/include/xo/alloc2/alloc/AllocIterator.hpp
Normal file
24
xo-alloc2/include/xo/alloc2/alloc/AllocIterator.hpp
Normal file
|
|
@ -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 */
|
||||
47
xo-alloc2/include/xo/alloc2/alloc/IAllocIterator_Any.hpp
Normal file
47
xo-alloc2/include/xo/alloc2/alloc/IAllocIterator_Any.hpp
Normal file
|
|
@ -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<xo::mm::AAllocIterator, DVariantPlaceholder> {
|
||||
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 */
|
||||
60
xo-alloc2/include/xo/alloc2/alloc/IAllocIterator_Xfer.hpp
Normal file
60
xo-alloc2/include/xo/alloc2/alloc/IAllocIterator_Xfer.hpp
Normal file
|
|
@ -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 <typename DRepr,
|
||||
typename IAllocIterator_DRepr>
|
||||
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 <typename DRepr, typename IAllocIterator_DRepr>
|
||||
int32_t
|
||||
IAllocIterator_Xfer<DRepr, IAllocIterator_DRepr>::s_typeseq
|
||||
= facet::typeseq::id<DRepr>();
|
||||
|
||||
template <typename DRepr, typename IAllocIterator_DRepr>
|
||||
bool
|
||||
IAllocIterator_Xfer<DRepr, IAllocIterator_DRepr>::_valid
|
||||
= facet::valid_facet_implementation<AAllocIterator, IAllocIterator_Xfer>();
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IAllocIterator_Xfer.hpp */
|
||||
42
xo-alloc2/include/xo/alloc2/alloc/RAllocIterator.hpp
Normal file
42
xo-alloc2/include/xo/alloc2/alloc/RAllocIterator.hpp
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/** @file RAllocIterator.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "AAllocIterator.hpp"
|
||||
#include <xo/facet/RRouter.hpp"
|
||||
//#include <string>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
/* @class RAllocIterator */
|
||||
template <typename Object>
|
||||
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 <typename Object>
|
||||
bool
|
||||
RAllocIterator<Object>::_valid = facet::valid_object_router<Object>();
|
||||
} /*namespace mm*/
|
||||
|
||||
namespace facet {
|
||||
template <typename Object>
|
||||
struct RoutingFor<xo::mm::AAllocIterator, Object> {
|
||||
using RoutingType = xo::mm::RAllocIterator<Object>;
|
||||
};
|
||||
}
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end RAllocIterator.hpp */
|
||||
|
|
@ -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
|
||||
|
|
|
|||
40
xo-alloc2/src/alloc2/IAllocIterator_Any.cpp
Normal file
40
xo-alloc2/src/alloc2/IAllocIterator_Any.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/** @file IAllocIterator_Any.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "alloc/IAllocIterator_Any.hpp"
|
||||
#include <iostream>
|
||||
|
||||
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<DArena>
|
||||
*/
|
||||
|
||||
std::cerr << "fatal"
|
||||
<< ": attempt to call uninitialized"
|
||||
<< " IAllocIterator_Any method"
|
||||
<< std::endl;
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
int32_t
|
||||
IAllocIterator_Any::s_typeseq = typeseq::id<DVariantPlaceholder>();
|
||||
|
||||
bool
|
||||
IAllocIterator_Any::_valid = valid_facet_implementation<AAllocIterator,
|
||||
IAllocIterator_Any>();
|
||||
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IAllocIterator_Any.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue