xo-object2: tidy IGCObject_DList

This commit is contained in:
Roland Conybeare 2026-01-15 00:32:50 -05:00
commit 503fd41c78
12 changed files with 159 additions and 89 deletions

View file

@ -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

15
idl/IGCObject_DList.json5 Normal file
View file

@ -0,0 +1,15 @@
{
mode: "implementation",
includes: [
// "<xo/gc/GCObject.hpp>",
// "<xo/alloc2/Allocator.hpp>"
],
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" ],
}

View file

@ -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<AAllocator> mm) const noexcept;
size_type forward_children(obj<ACollector> gc) noexcept;
/** first member of list **/
obj<AGCObject> head_;
/** remainder of list **/

View file

@ -1,47 +0,0 @@
/** @file IGCObject_DList.hpp
*
* @author Roland Conybeare, Dec 2025
**/
#pragma once
#include <xo/alloc2/Allocator.hpp>
#include <xo/gc/Collector.hpp>
#include <xo/gc/detail/AGCObject.hpp>
#include <xo/gc/detail/IGCObject_Xfer.hpp>
//#include "DList.hpp" // circular
namespace xo {
namespace scm { struct IGCObject_DList; }
namespace scm { struct DList; }
namespace facet {
template <>
struct FacetImplementation<xo::mm::AGCObject,
xo::scm::DList>
{
using ImplType = xo::mm::IGCObject_Xfer
<xo::scm::DList,
xo::scm::IGCObject_DList>;
};
}
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<AAllocator> mm) noexcept;
static size_type forward_children(DList & d, obj<ACollector> gc) noexcept;
};
} /*namespace scm*/
} /*namespace xo*/
/* end IGCObject_DList.hpp */

View file

@ -5,7 +5,7 @@
#pragma once
#include "IGCObject_DList.hpp"
#include "list/IGCObject_DList.hpp"
#include "DList.hpp"
namespace xo {

View file

@ -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<xo::mm::AGCObject,
xo::scm::DList>
{
using ImplType = xo::mm::IGCObject_Xfer
<xo::scm::DList,
xo::scm::IGCObject_DList>;
};
}
}
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<AAllocator> mm) noexcept;
// non-const methods
/** during GC: forward immdiate children **/
static size_type forward_children(DList & self, obj<ACollector> gc) noexcept;
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -5,9 +5,11 @@
#include "DList.hpp"
#include "list/IPrintable_DList.hpp"
#include "list/IGCObject_DList.hpp"
#include <xo/gc/GCObject.hpp>
#include <xo/printable2/Printable.hpp>
#include <xo/facet/FacetRegistry.hpp>
#include <xo/facet/facet_implementation.hpp>
#include <xo/indentlog/print/pretty.hpp>
#include <xo/indentlog/print/tag.hpp>
@ -145,6 +147,36 @@ namespace xo {
return false;
}
}
auto
DList::shallow_size() const noexcept -> size_type
{
return sizeof(DList);
}
DList *
DList::shallow_copy(obj<AAllocator> mm) const noexcept
{
DList * copy = (DList *)mm.alloc_copy((std::byte *)this);
if (copy)
*copy = *this;
return copy;
}
auto
DList::forward_children(obj<ACollector> gc) noexcept -> size_type
{
scope log(XO_DEBUG(true));
gc.forward_inplace(head_.iface(), (void **)&(head_.data_));
auto iface = xo::facet::impl_for<AGCObject,DList>();
gc.forward_inplace(&iface, (void **)(&rest_));
return shallow_size();
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -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 <xo/indentlog/scope.hpp>
#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<AAllocator> mm) noexcept
auto
IGCObject_DList::shallow_copy(const DList & self, obj<AAllocator> 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<ACollector> gc) noexcept
auto
IGCObject_DList::forward_children(DList & self, obj<ACollector> 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<AGCObject, DList>();
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 */

View file

@ -5,7 +5,7 @@
#include "object2_register_facets.hpp"
#include <xo/object2/IGCObject_DList.hpp>
#include <xo/object2/list/IGCObject_DList.hpp>
#include <xo/object2/IGCObject_DFloat.hpp>
#include <xo/object2/IGCObject_DInteger.hpp>
#include <xo/object2/string/IGCObject_DString.hpp>

View file

@ -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"

View file

@ -9,7 +9,7 @@
#include "object2_register_facets.hpp"
#include <xo/object2/DList.hpp>
#include <xo/object2/IGCObject_DList.hpp>
#include <xo/object2/list/IGCObject_DList.hpp>
#include <xo/object2/list/IPrintable_DList.hpp>
#include <xo/object2/DString.hpp>

View file

@ -9,7 +9,7 @@
#include "object2_register_types.hpp"
#include "IGCObject_DFloat.hpp"
#include "IGCObject_DList.hpp"
#include "list/IGCObject_DList.hpp"
#include <xo/gc/Collector.hpp>
#include <xo/gc/DX1Collector.hpp>