refactor: + xo-stringtable2 w/ DString impl
This commit is contained in:
parent
e33ab0ae98
commit
ee982276c9
5 changed files with 215 additions and 0 deletions
74
include/xo/alloc2/CollectorTypeRegistry.hpp
Normal file
74
include/xo/alloc2/CollectorTypeRegistry.hpp
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/** @file CollectorTypeRegistry.hpp
|
||||
*
|
||||
* @brief Runtime type registration for gc-aware types
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Collector.hpp"
|
||||
#include <functional>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
/** @class CollectorTypeRegistry
|
||||
*
|
||||
* @brief Runtime registry for gc-aware types
|
||||
*
|
||||
* Singleton to remember known gc-aware types;
|
||||
* use to simplify registering such types
|
||||
* with a collector instance.
|
||||
*
|
||||
* Remark: splitting work here between
|
||||
* 1. static initializer work: tracking gc-aware types,
|
||||
* 2. runtime post-configuration work: report
|
||||
* gc-aware types to GC instances
|
||||
*
|
||||
* Use:
|
||||
* 1. subsystem foo provides function foo_register_types(obj<ACollector> gc)
|
||||
* Function calls
|
||||
* gc.install_type(impl_for<AGCObject, DQuux>())
|
||||
* for each gc-aware type provided by subsystem foo
|
||||
*
|
||||
* Example: in file xo-object2/src/object2/object2_register_types.cpp, see
|
||||
* object2_register_types()
|
||||
*
|
||||
* 2. during subsystem init, call
|
||||
* CollectorTypeRegistry::instance().register_types(&foo_register_types);
|
||||
*
|
||||
* Example: in file xo-object2/src/object2/init_object2.cpp, see
|
||||
* InitSubsys<S_object2_tag>::init()
|
||||
*
|
||||
* 3. during Collector setup, call
|
||||
* obj<ACollector> gc = ...;
|
||||
* CollectorTypeRegistry::instance().install_types(gc);
|
||||
*
|
||||
* Example: in file xo-object2/utest/X1Collector.test.cpp
|
||||
* TEST_CASE("x1")
|
||||
**/
|
||||
class CollectorTypeRegistry {
|
||||
public:
|
||||
using init_function_type = std::function<bool (obj<ACollector>)>;
|
||||
|
||||
public:
|
||||
/** singleton instance **/
|
||||
static CollectorTypeRegistry & instance();
|
||||
|
||||
/** remember a gc-aware type-registration function **/
|
||||
void register_types(init_function_type init_fn);
|
||||
|
||||
/** register known GC-aware types with @p gc.
|
||||
* Calls @c gc.isntall_type() for each
|
||||
* such type.
|
||||
**/
|
||||
bool install_types(obj<ACollector> gc);
|
||||
|
||||
private:
|
||||
/** initialization steps for a new Collector instance **/
|
||||
std::vector<init_function_type> init_seq_v_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/* end CollectorTypeRegistry.hpp */
|
||||
|
|
@ -6,6 +6,11 @@ set(SELF_SRCS
|
|||
init_alloc2.cpp
|
||||
alloc2_register_facets.cpp
|
||||
|
||||
CollectorTypeRegistry.cpp
|
||||
|
||||
ICollector_Any.cpp
|
||||
IGCObject_Any.cpp
|
||||
|
||||
AAllocator.cpp
|
||||
IAllocator_Any.cpp
|
||||
IAllocator_DArena.cpp
|
||||
|
|
|
|||
48
src/alloc2/CollectorTypeRegistry.cpp
Normal file
48
src/alloc2/CollectorTypeRegistry.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/** @file CollectorTypeRegistry.cpp
|
||||
**/
|
||||
|
||||
#include "CollectorTypeRegistry.hpp"
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
CollectorTypeRegistry &
|
||||
CollectorTypeRegistry::instance()
|
||||
{
|
||||
static CollectorTypeRegistry s_instance;
|
||||
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
void
|
||||
CollectorTypeRegistry::register_types(init_function_type fn)
|
||||
{
|
||||
scope log(XO_DEBUG(true));
|
||||
|
||||
init_seq_v_.push_back(fn);
|
||||
}
|
||||
|
||||
bool
|
||||
CollectorTypeRegistry::install_types(obj<ACollector> gc)
|
||||
{
|
||||
scope log(XO_DEBUG(true));
|
||||
|
||||
bool ok = true;
|
||||
|
||||
size_t i = 0;
|
||||
size_t n = init_seq_v_.size();
|
||||
log && log("run n init steps", xtag("n", n));
|
||||
|
||||
for (const auto & fn : init_seq_v_) {
|
||||
log && log("do install fn (", i+1, "/", n, ")");
|
||||
|
||||
ok = ok & fn(gc);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end CollectorTypeRegistry.cpp */
|
||||
40
src/alloc2/ICollector_Any.cpp
Normal file
40
src/alloc2/ICollector_Any.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/** @file ICollector_Any.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "gc/ICollector_Any.hpp"
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
|
||||
namespace xo {
|
||||
using xo::facet::DVariantPlaceholder;
|
||||
using xo::facet::typeseq;
|
||||
using xo::facet::valid_facet_implementation;
|
||||
|
||||
namespace mm {
|
||||
|
||||
void
|
||||
ICollector_Any::_fatal() {
|
||||
/* control here on uninitialized ICollector_Any.
|
||||
* Initialized instance will have specific implementation type
|
||||
* e.g. ICollector_Xfer<DCollector>
|
||||
*/
|
||||
|
||||
std::cerr << "fatal"
|
||||
<< ": attempt to call uninitialized"
|
||||
<< " ICollector_Any method"
|
||||
<< std::endl;
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
typeseq
|
||||
ICollector_Any::s_typeseq = typeseq::id<DVariantPlaceholder>();
|
||||
|
||||
bool
|
||||
ICollector_Any::_valid = valid_facet_implementation<ACollector, ICollector_Any>();
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/** end ICollector_Any.cpp */
|
||||
48
src/alloc2/IGCObject_Any.cpp
Normal file
48
src/alloc2/IGCObject_Any.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/** @file IGCObject_Any.cpp
|
||||
*
|
||||
**/
|
||||
|
||||
#include "gc/IGCObject_Any.hpp"
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
|
||||
using xo::facet::DVariantPlaceholder;
|
||||
using xo::facet::typeseq;
|
||||
using xo::facet::valid_facet_implementation;
|
||||
|
||||
void
|
||||
IGCObject_Any::_fatal()
|
||||
{
|
||||
/* control here on uninitialized IAllocator_Any.
|
||||
* Initialized instance will have specific implementation type
|
||||
*/
|
||||
std::cerr << "fatal"
|
||||
<< ": attempt to call uninitialized"
|
||||
<< " IGCObject_Any method"
|
||||
<< std::endl;
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
typeseq
|
||||
IGCObject_Any::s_typeseq = typeseq::id<DVariantPlaceholder>();
|
||||
|
||||
bool
|
||||
IGCObject_Any::_valid
|
||||
= valid_facet_implementation<AGCObject, IGCObject_Any>();
|
||||
|
||||
// nonconst methods
|
||||
|
||||
auto
|
||||
IGCObject_Any::forward_children(Opaque, obj<ACollector>) const noexcept -> size_type
|
||||
{
|
||||
_fatal();
|
||||
}
|
||||
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IGCObject_Any.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue