From 503fd41c782f596ba3ff6fcfcc7f33d35520eab9 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Thu, 15 Jan 2026 00:32:50 -0500 Subject: [PATCH] xo-object2: tidy IGCObject_DList --- CMakeLists.txt | 12 ++++ idl/IGCObject_DList.json5 | 15 +++++ include/xo/object2/DList.hpp | 7 +++ include/xo/object2/IGCObject_DList.hpp | 47 --------------- include/xo/object2/ListOps.hpp | 2 +- include/xo/object2/list/IGCObject_DList.hpp | 65 +++++++++++++++++++++ src/object2/DList.cpp | 32 ++++++++++ src/object2/IGCObject_DList.cpp | 58 +++++++----------- src/object2/object2_register_facets.cpp | 2 +- src/object2/object2_register_types.cpp | 2 +- utest/Printable.test.cpp | 2 +- utest/X1Collector.test.cpp | 2 +- 12 files changed, 158 insertions(+), 88 deletions(-) create mode 100644 idl/IGCObject_DList.json5 delete mode 100644 include/xo/object2/IGCObject_DList.hpp create mode 100644 include/xo/object2/list/IGCObject_DList.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 81000f8..5304655 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,18 @@ xo_add_genfacetimpl( OUTPUT_CPP_DIR src/object2 ) +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-object2-facetimpl-gcobject-list + FACET_PKG xo_gc + FACET GCObject + REPR List + INPUT idl/IGCObject_DList.json5 + OUTPUT_HPP_DIR include/xo/object2 + OUTPUT_IMPL_SUBDIR list + OUTPUT_CPP_DIR src/object2 +) + # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-object2-facetimpl-printable-float diff --git a/idl/IGCObject_DList.json5 b/idl/IGCObject_DList.json5 new file mode 100644 index 0000000..342fc29 --- /dev/null +++ b/idl/IGCObject_DList.json5 @@ -0,0 +1,15 @@ +{ + mode: "implementation", + includes: [ +// "", +// "" + ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/GCObject.json5", + brief: "provide AGCObject interface for DList", + using_doxygen: true, + repr: "DList", + doc: [ "implement AGCObject for DList" ], +} diff --git a/include/xo/object2/DList.hpp b/include/xo/object2/DList.hpp index eecb431..611fb66 100644 --- a/include/xo/object2/DList.hpp +++ b/include/xo/object2/DList.hpp @@ -19,6 +19,7 @@ namespace xo { using size_type = std::size_t; using AGCObject = xo::mm::AGCObject; using AAllocator = xo::mm::AAllocator; + using ACollector = xo::mm::ACollector; using ppindentinfo = xo::print::ppindentinfo; public: @@ -51,6 +52,12 @@ namespace xo { /** pretty-printing driver; combine layout+printing **/ bool pretty(const ppindentinfo & ppii) const; + // GCObject facet + + size_type shallow_size() const noexcept; + DList * shallow_copy(obj mm) const noexcept; + size_type forward_children(obj gc) noexcept; + /** first member of list **/ obj head_; /** remainder of list **/ diff --git a/include/xo/object2/IGCObject_DList.hpp b/include/xo/object2/IGCObject_DList.hpp deleted file mode 100644 index eba4a7d..0000000 --- a/include/xo/object2/IGCObject_DList.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/** @file IGCObject_DList.hpp - * - * @author Roland Conybeare, Dec 2025 - **/ - -#pragma once - -#include -#include -#include -#include -//#include "DList.hpp" // circular - -namespace xo { - namespace scm { struct IGCObject_DList; } - namespace scm { struct DList; } - - namespace facet { - template <> - struct FacetImplementation - { - using ImplType = xo::mm::IGCObject_Xfer - ; - }; - } - - namespace scm { - /* changes here coordinate with: - * IGCObject_XFer - */ - struct IGCObject_DList { - public: - using AAllocator = xo::mm::AAllocator; - using ACollector = xo::mm::ACollector; - using size_type = std::size_t; - - static size_type shallow_size(const DList & d) noexcept; - static DList * shallow_copy(const DList & d, obj mm) noexcept; - static size_type forward_children(DList & d, obj gc) noexcept; - }; - - } /*namespace scm*/ -} /*namespace xo*/ - -/* end IGCObject_DList.hpp */ diff --git a/include/xo/object2/ListOps.hpp b/include/xo/object2/ListOps.hpp index 90041ca..9816111 100644 --- a/include/xo/object2/ListOps.hpp +++ b/include/xo/object2/ListOps.hpp @@ -5,7 +5,7 @@ #pragma once -#include "IGCObject_DList.hpp" +#include "list/IGCObject_DList.hpp" #include "DList.hpp" namespace xo { diff --git a/include/xo/object2/list/IGCObject_DList.hpp b/include/xo/object2/list/IGCObject_DList.hpp new file mode 100644 index 0000000..e87cdd9 --- /dev/null +++ b/include/xo/object2/list/IGCObject_DList.hpp @@ -0,0 +1,65 @@ +/** @file IGCObject_DList.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DList.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DList.json5] + **/ + +#pragma once + +#include "GCObject.hpp" +#include "DList.hpp" + +namespace xo { namespace scm { class IGCObject_DList; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::mm::IGCObject_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IGCObject_DList + **/ + class IGCObject_DList { + public: + /** @defgroup scm-gcobject-dlist-type-traits **/ + ///@{ + using size_type = xo::mm::AGCObject::size_type; + using AAllocator = xo::mm::AGCObject::AAllocator; + using ACollector = xo::mm::AGCObject::ACollector; + using Copaque = xo::mm::AGCObject::Copaque; + using Opaque = xo::mm::AGCObject::Opaque; + ///@} + /** @defgroup scm-gcobject-dlist-methods **/ + ///@{ + // const methods + /** memory consumption for this instance **/ + static size_type shallow_size(const DList & self) noexcept; + /** copy instance using allocator **/ + static Opaque shallow_copy(const DList & self, obj mm) noexcept; + + // non-const methods + /** during GC: forward immdiate children **/ + static size_type forward_children(DList & self, obj gc) noexcept; + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/src/object2/DList.cpp b/src/object2/DList.cpp index ccd5193..769ef1e 100644 --- a/src/object2/DList.cpp +++ b/src/object2/DList.cpp @@ -5,9 +5,11 @@ #include "DList.hpp" #include "list/IPrintable_DList.hpp" +#include "list/IGCObject_DList.hpp" #include #include #include +#include #include #include @@ -145,6 +147,36 @@ namespace xo { return false; } } + + auto + DList::shallow_size() const noexcept -> size_type + { + return sizeof(DList); + } + + DList * + DList::shallow_copy(obj mm) const noexcept + { + DList * copy = (DList *)mm.alloc_copy((std::byte *)this); + + if (copy) + *copy = *this; + + return copy; + } + + auto + DList::forward_children(obj gc) noexcept -> size_type + { + scope log(XO_DEBUG(true)); + + gc.forward_inplace(head_.iface(), (void **)&(head_.data_)); + + auto iface = xo::facet::impl_for(); + gc.forward_inplace(&iface, (void **)(&rest_)); + + return shallow_size(); + } } /*namespace scm*/ } /*namespace xo*/ diff --git a/src/object2/IGCObject_DList.cpp b/src/object2/IGCObject_DList.cpp index 4266075..0658468 100644 --- a/src/object2/IGCObject_DList.cpp +++ b/src/object2/IGCObject_DList.cpp @@ -1,53 +1,39 @@ /** @file IGCObject_DList.cpp * - * @author Roland Conybeare, Dec 2025 - **/ + * Generated automagically from ingredients: + * 1. code generator: + * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DList.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DList.json5] +**/ -#include "IGCObject_DList.hpp" -#include "DList.hpp" -#include +#include "list/IGCObject_DList.hpp" namespace xo { - using xo::mm::AGCObject; - using xo::mm::AAllocator; - //using xo::facet::with_facet; - using xo::facet::obj; - using xo::facet::typeseq; - using std::size_t; - namespace scm { - size_t - IGCObject_DList::shallow_size(const DList &) noexcept + auto + IGCObject_DList::shallow_size(const DList & self) noexcept -> size_type { - return sizeof(DList); + return self.shallow_size(); } - DList * - IGCObject_DList::shallow_copy(const DList & src, - obj mm) noexcept + auto + IGCObject_DList::shallow_copy(const DList & self, obj mm) noexcept -> Opaque { - DList * copy = (DList *)mm.alloc_copy((std::byte *)&src); - - if (copy) - *copy = src; - - return copy; + return self.shallow_copy(mm); } - size_t - IGCObject_DList::forward_children(DList & src, - obj gc) noexcept + auto + IGCObject_DList::forward_children(DList & self, obj gc) noexcept -> size_type { - scope log(XO_DEBUG(true)); - - gc.forward_inplace(src.head_.iface(), (void **)&(src.head_.data_)); - - auto iface = xo::facet::impl_for(); - gc.forward_inplace(&iface, (void **)(&src.rest_)); - - return shallow_size(src); + return self.forward_children(gc); } + } /*namespace scm*/ } /*namespace xo*/ -/* end IGCObject_DList.cpp */ +/* end IGCObject_DList.cpp */ \ No newline at end of file diff --git a/src/object2/object2_register_facets.cpp b/src/object2/object2_register_facets.cpp index 704af85..b9a8d3a 100644 --- a/src/object2/object2_register_facets.cpp +++ b/src/object2/object2_register_facets.cpp @@ -5,7 +5,7 @@ #include "object2_register_facets.hpp" -#include +#include #include #include #include diff --git a/src/object2/object2_register_types.cpp b/src/object2/object2_register_types.cpp index ff2c6eb..a7e95da 100644 --- a/src/object2/object2_register_types.cpp +++ b/src/object2/object2_register_types.cpp @@ -5,7 +5,7 @@ #include "object2_register_types.hpp" -#include "IGCObject_DList.hpp" +#include "list/IGCObject_DList.hpp" #include "IGCObject_DFloat.hpp" #include "IGCObject_DInteger.hpp" #include "string/IGCObject_DString.hpp" diff --git a/utest/Printable.test.cpp b/utest/Printable.test.cpp index 45e824e..76a2b17 100644 --- a/utest/Printable.test.cpp +++ b/utest/Printable.test.cpp @@ -9,7 +9,7 @@ #include "object2_register_facets.hpp" #include -#include +#include #include #include diff --git a/utest/X1Collector.test.cpp b/utest/X1Collector.test.cpp index 2ad9381..f100f38 100644 --- a/utest/X1Collector.test.cpp +++ b/utest/X1Collector.test.cpp @@ -9,7 +9,7 @@ #include "object2_register_types.hpp" #include "IGCObject_DFloat.hpp" -#include "IGCObject_DList.hpp" +#include "list/IGCObject_DList.hpp" #include #include