xo-alloc2: still more header org-streamlining

This commit is contained in:
Roland Conybeare 2025-12-14 17:28:19 -05:00
commit 1b5067d643
13 changed files with 28 additions and 15 deletions

View file

@ -0,0 +1,53 @@
/** @file AGCObject.hpp
*
* @author Roland Conybeare, Dec 2025
**/
#pragma once
#include "Allocator.hpp"
#include "xo/facet/facet_implementation.hpp"
#include "xo/facet/typeseq.hpp"
#include "xo/facet/obj.hpp" // for obj<AAllocator> in shallow_copy
#include <cstdint>
#include <cstddef>
namespace xo {
namespace mm {
using Copaque = const void *;
using Opaque = void *;
/** @class AObject
* @brief Abstract facet for collector-eligible data
*
* Data that supports AGCObject can have memory managed
* by ACollector
**/
struct AGCObject {
using size_type = std::size_t;
/** RTTI: unique id# for actual runtime data representation **/
virtual int32_t _typeseq() const noexcept = 0;
virtual size_type shallow_size(Copaque d) const noexcept = 0;
virtual Opaque * shallow_copy(Copaque d,
obj<AAllocator> mm) const noexcept = 0;
virtual size_type forward_children(Opaque d) const noexcept = 0;
};
// implementation IGCObject_DRepr of AGCObject for state DRepr
// should provide a specialization:
//
// template <>
// struct xo::facet::FacetImplementation<AGCObjectx, DRepr> {
// using ImplType = IGCObject_DRepr;
// };
//
// then IGCObject_ImplType<DRepr> --> IGCObject_DRepr
//
template <typename DRepr>
using IGCObject_ImplType = xo::facet::FacetImplType<AGCObject, DRepr>;
} /*namespace mm*/
} /*namespace xo*/
/* end AGCObject.hpp */

View file

@ -0,0 +1,48 @@
/** @file IGCObject_Any.hpp
*
* @author Roland Conybeare, Dec 2025
**/
#pragma once
#include "AGCObject.hpp"
#include <new>
namespace xo {
namespace mm { struct IGCObject_Any; }
namespace facet {
template <>
struct FacetImplementation<xo::mm::AGCObject, DVariantPlaceholder> {
using ImplType = xo::mm::IGCObject_Any;
};
}
namespace mm {
/** @class IGCObject_Any
* @brief AGCObject implementation for empty variant instance
**/
struct IGCObject_Any : public AGCObject {
using size_type = std::size_t;
const AGCObject * iface() const { return std::launder(this); }
// from AGCObject
int32_t _typeseq() const noexcept override { return s_typeseq; }
[[noreturn]] size_type shallow_size(Copaque) const noexcept override { _fatal(); }
[[noreturn]] Opaque * shallow_copy(Copaque,
obj<AAllocator>) const noexcept override { _fatal(); }
[[noreturn]] size_type forward_children(Opaque) const noexcept override { _fatal(); }
private:
[[noreturn]] static void _fatal();
public:
static int32_t s_typeseq;
static bool _valid;
};
} /*namespace mm*/
} /*namespace xo*/
/* end IGCObject_Any.hpp */

View file

@ -0,0 +1,62 @@
/** @file IGCObject_Xfer.hpp
*
* @author Roland Conybeare, Dec 2025
**/
#pragma once
#include "AGCObject.hpp"
namespace xo {
namespace mm {
/** @class IGCObject_Xfer
*
* Adapts typed GC object implementation @tparam IGCObject_DRepr
* to type-erased @ref AGCObject interface
**/
template <typename DRepr, typename IGCObject_DRepr>
struct IGCObject_Xfer : public AGCObject {
using Impl = IGCObject_DRepr;
using size_type = AGCObject::size_type;
static const DRepr & _dcast(Copaque d) { return *(const DRepr *)d; }
static DRepr & _dcast(Opaque d) { return *(DRepr *)d; }
// from AGCObject
// const methods
int32_t _typeseq() const noexcept override { return s_typeseq; }
size_type shallow_size(Copaque d) const noexcept override {
return I::shallow_copy(_dcast(d));
}
Opaque * shallow_copy(Copaque d, obj<AAllocator> mm) const noexcept override {
return I::shallow_size(_dcast(d), mm);
}
// non-const methods
size_type forward_children(Opaque d) const noexcept override {
return I::forward_children(d);
}
private:
using I = Impl;
public:
static int32_t s_typeseq;
static bool _valid;
};
template <typename DRepr, typename IGCObject_DRepr>
int32_t
IGCObject_Xfer<DRepr, IGCObject_DRepr>::s_typeseq = facet::typeseq::id<DRepr>();
template <typename DRepr, typename IGCObject_DRepr>
bool
IGCObject_Xfer<DRepr, IGCObject_DRepr>::_valid = facet::valid_facet_implementation<AGCObject, IGCObject_Xfer>();
} /*namespace mm*/
} /*namespace xo*/
/* end IGCObject_Xfer.hpp */

View file

@ -0,0 +1,47 @@
/** @file RGCObject.hpp
*
* @author Roland Conybeare, Dec 2025
**/
#pragma once
#include "AGCObject.hpp"
#include <xo/facet/RRouter.hpp>
namespace xo {
namespace mm {
/** @class RGCObject **/
template <typename Object>
struct RGCObject : public Object {
private:
using O = Object;
public:
using ObjectType = Object;
using DataPtr = Object::DataPtr;
using size_type = std::size_t;
RGCObject() = default;
RGCObject(Object::DataPtr data) : Object{std::move(data)} {}
int32_t _typeseq() const noexcept { return O::iface()->_typeseq(); }
size_type shallow_size() const noexcept { O::iface()->shallow_size(O::data()); }
Opaque * shallow_copy(obj<AAllocator> mm) const noexcept { O::iface()->shallow_copy(O::data(), mm); }
size_type forward_children() noexcept { O::iface()->forward_children(O::data()); }
static bool _valid;
};
template <typename Object>
bool
RGCObject<Object>::_valid = facet::valid_object_router<RGCObject>();
} /*namespace mm*/
namespace facet {
template <typename Object>
struct RoutingFor<xo::mm::AGCObject, Object> {
using RoutingType = xo::mm::RGCObject<Object>;
};
}
} /*namespace xo*/
/* end RGCObject.hpp */