/** @file PolyForwarderUtil.hpp * * @author Roland Conybeare, Feb 2026 **/ #pragma once #include "Collector.hpp" #include namespace xo { namespace mm { /** Utility class for forwarding support on * faceted object pointers that have some primary * facet _other_ than AGCObject. * * For fop with AGCObject facet, with collector gc: * * obj gc = ..; * obj ptr = ..; * * gc.forward_inplace(&ptr); * * for fop with some other facet: * * obj ptr = ..; * PolyForwarderUtil::forward_inplace(gc, &ptr); * * or * poly_forward_inplace(gc, &ptr); **/ class PolyForwarderUtil { public: template static void forward_inplace(obj gc, obj * p_ptr) { using xo::facet::FacetRegistry; /** * p_ptr * v FacetRegistry * +--------+---------+ .variant() +-----------+---------+ * | AFacet | DRepr x | -----------------> | AGCobject | DRepr x | * +--------+-------|-+ +-----------+-------|-+ * | | * | /-------------------------------------------/ * | | * v v * +-------+ * | DRepr | * +-------+ **/ if (*p_ptr) { auto gco = FacetRegistry::instance().variant(*p_ptr); gc.forward_inplace(gco.iface(), (void **)&(p_ptr->data_)); } else { // nullptr is trivial to forward } } }; template void poly_forward_inplace(obj gc, obj * p_ptr) { PolyForwarderUtil::forward_inplace(gc, p_ptr); } } /*namespace mm*/ } /*namespace xo*/ /* end PolyForwarderUtil.hpp */