xo-object2: + DBoolean w/ AGCObject, APrintable facets

This commit is contained in:
Roland Conybeare 2026-01-23 15:44:13 -05:00
commit b12555067c
12 changed files with 390 additions and 0 deletions

View file

@ -28,6 +28,8 @@ xo_add_genfacet(
OUTPUT_CPP_DIR src/object2
)
# ----------------------------------------------------------------
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-object2-facetimpl-sequence-list
@ -64,6 +66,34 @@ xo_add_genfacetimpl(
OUTPUT_CPP_DIR src/object2
)
# ----------------------------------------------------------------
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-object2-facetimpl-printable-boolean
FACET_PKG xo_printable2
FACET Printable
REPR Boolean
INPUT idl/IPrintable_DBoolean.json5
OUTPUT_HPP_DIR include/xo/object2
OUTPUT_IMPL_SUBDIR boolean
OUTPUT_CPP_DIR src/object2
)
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-object2-facetimpl-gcobject-boolean
FACET_PKG xo_gc
FACET GCObject
REPR Boolean
INPUT idl/IGCObject_DBoolean.json5
OUTPUT_HPP_DIR include/xo/object2
OUTPUT_IMPL_SUBDIR boolean
OUTPUT_CPP_DIR src/object2
)
# ----------------------------------------------------------------
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-object2-facetimpl-printable-float
@ -88,6 +118,8 @@ xo_add_genfacetimpl(
OUTPUT_CPP_DIR src/object2
)
# ----------------------------------------------------------------
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-object2-facetimpl-printable-integer
@ -112,6 +144,8 @@ xo_add_genfacetimpl(
OUTPUT_CPP_DIR src/object2
)
# ----------------------------------------------------------------
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-object2-facetimpl-printable-string
@ -136,6 +170,8 @@ xo_add_genfacetimpl(
OUTPUT_CPP_DIR src/object2
)
# ----------------------------------------------------------------
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-object2-facetimpl-sequence-array

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 DBoolean",
using_doxygen: true,
repr: "DBoolean",
doc: [ "implement AGCObject for DBoolean" ],
}

View file

@ -0,0 +1,13 @@
{
mode: "implementation",
includes: [ "<xo/printable2/Printable.hpp>",
"<xo/printable2/detail/IPrintable_Xfer.hpp>" ],
local_types: [ ],
namespace1: "xo",
namespace2: "scm",
facet_idl: "idl/Printable.json5",
brief: "provide APrintable interface for DBoolean",
using_doxygen: true,
repr: "DBoolean",
doc: [ "implement APrintable for DBoolean" ],
}

View file

@ -0,0 +1,57 @@
/** @file DBoolean.hpp
*
* @author Roland Conybeare, Dec 2025
**/
#pragma once
#include <xo/gc/Collector.hpp>
#include <xo/alloc2/Allocator.hpp>
#include <xo/indentlog/print/ppindentinfo.hpp>
#include <xo/facet/obj.hpp>
#include <cstdint>
namespace xo {
namespace scm {
struct DBoolean {
using AAllocator = xo::mm::AAllocator;
using ACollector = xo::mm::ACollector;
using ppindentinfo = xo::print::ppindentinfo;
using value_type = long;
explicit DBoolean(bool x) : value_{x} {}
/** will likely want this to default to ANumeric, once we have it **/
template <typename AFacet>
static obj<AFacet, DBoolean> box(obj<AAllocator> mm, bool x);
/** allocate boxed value @p x using memory from @p mm **/
static DBoolean * _box(obj<AAllocator> mm, bool x);
bool value() const noexcept { return value_; }
bool pretty(const ppindentinfo & ppii) const;
operator bool() const noexcept { return value_; }
// GCObject facet
std::size_t shallow_size() const noexcept;
DBoolean * shallow_copy(obj<AAllocator> mm) const noexcept;
std::size_t forward_children(obj<ACollector> gc) noexcept;
private:
/** boxed boolean value **/
bool value_;
};
template <typename AFacet>
obj<AFacet, DBoolean>
DBoolean::box(obj<AAllocator> mm, bool x) {
return obj<AFacet,DBoolean>(_box(mm, x));
}
} /*nmaespace obj*/
} /*namespace xo*/
/* end DBoolean.hpp */

View file

@ -0,0 +1,67 @@
/** @file IGCObject_DBoolean.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IGCObject_DBoolean.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_repr.hpp.j2]
* 3. idl for facet methods
* [idl/IGCObject_DBoolean.json5]
**/
#pragma once
#include "GCObject.hpp"
#include <xo/gc/GCObject.hpp>
#include <xo/alloc2/Allocator.hpp>
#include "DBoolean.hpp"
namespace xo { namespace scm { class IGCObject_DBoolean; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::mm::AGCObject,
xo::scm::DBoolean>
{
using ImplType = xo::mm::IGCObject_Xfer
<xo::scm::DBoolean,
xo::scm::IGCObject_DBoolean>;
};
}
}
namespace xo {
namespace scm {
/** @class IGCObject_DBoolean
**/
class IGCObject_DBoolean {
public:
/** @defgroup scm-gcobject-dboolean-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-dboolean-methods **/
///@{
// const methods
/** memory consumption for this instance **/
static size_type shallow_size(const DBoolean & self) noexcept;
/** copy instance using allocator **/
static Opaque shallow_copy(const DBoolean & self, obj<AAllocator> mm) noexcept;
// non-const methods
/** during GC: forward immdiate children **/
static size_type forward_children(DBoolean & self, obj<ACollector> gc) noexcept;
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -0,0 +1,62 @@
/** @file IPrintable_DBoolean.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IPrintable_DBoolean.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_repr.hpp.j2]
* 3. idl for facet methods
* [idl/IPrintable_DBoolean.json5]
**/
#pragma once
#include "Printable.hpp"
#include <xo/printable2/Printable.hpp>
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
#include "DBoolean.hpp"
namespace xo { namespace scm { class IPrintable_DBoolean; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::print::APrintable,
xo::scm::DBoolean>
{
using ImplType = xo::print::IPrintable_Xfer
<xo::scm::DBoolean,
xo::scm::IPrintable_DBoolean>;
};
}
}
namespace xo {
namespace scm {
/** @class IPrintable_DBoolean
**/
class IPrintable_DBoolean {
public:
/** @defgroup scm-printable-dboolean-type-traits **/
///@{
using ppindentinfo = xo::print::APrintable::ppindentinfo;
using Copaque = xo::print::APrintable::Copaque;
using Opaque = xo::print::APrintable::Opaque;
///@}
/** @defgroup scm-printable-dboolean-methods **/
///@{
// const methods
/** Pretty-printing support for this object.
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
static bool pretty(const DBoolean & self, const ppindentinfo & ppii);
// non-const methods
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -4,6 +4,7 @@ set(SELF_LIB xo_object2)
set(SELF_SRCS
IGCObject_DArray.cpp
IGCObject_DFloat.cpp
IGCObject_DBoolean.cpp
IGCObject_DInteger.cpp
IGCObject_DList.cpp
IGCObject_DString.cpp
@ -11,6 +12,7 @@ set(SELF_SRCS
ISequence_DArray.cpp
ISequence_DList.cpp
IPrintable_DList.cpp
IPrintable_DBoolean.cpp
IPrintable_DFloat.cpp
IPrintable_DInteger.cpp
IPrintable_DString.cpp
@ -18,6 +20,7 @@ set(SELF_SRCS
DList.cpp
DFloat.cpp
DInteger.cpp
DBoolean.cpp
DString.cpp
init_object2.cpp
object2_register_types.cpp

View file

@ -0,0 +1,57 @@
/** @file DBoolean.cpp
*
* @author Roland Conybeare, Jan 2026
**/
#include "DBoolean.hpp"
#include <xo/indentlog/print/pretty.hpp>
#include <xo/indentlog/scope.hpp>
namespace xo {
using xo::facet::typeseq;
using xo::print::ppdetail_atomic;
namespace scm {
DBoolean *
DBoolean::_box(obj<AAllocator> mm, bool x)
{
void * mem = mm.alloc(typeseq::id<DBoolean>(),
sizeof(DBoolean));
return new (mem) DBoolean(x);
}
bool
DBoolean::pretty(const ppindentinfo & ppii) const
{
return ppdetail_atomic<long>::print_pretty(ppii, value_);
}
size_t
DBoolean::shallow_size() const noexcept
{
return sizeof(DBoolean);
}
DBoolean *
DBoolean::shallow_copy(obj<AAllocator> mm) const noexcept
{
DBoolean * copy = (DBoolean *)mm.alloc_copy((std::byte *)this);
if (copy)
*copy = *this;
return copy;
}
size_t
DBoolean::forward_children(obj<ACollector>) noexcept
{
return shallow_size();
}
} /*namespace scm*/
} /*namespace xo*/
/* end DBoolean.cpp */

View file

@ -0,0 +1,39 @@
/** @file IGCObject_DBoolean.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IGCObject_DBoolean.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/IGCObject_DBoolean.json5]
**/
#include "boolean/IGCObject_DBoolean.hpp"
namespace xo {
namespace scm {
auto
IGCObject_DBoolean::shallow_size(const DBoolean & self) noexcept -> size_type
{
return self.shallow_size();
}
auto
IGCObject_DBoolean::shallow_copy(const DBoolean & self, obj<AAllocator> mm) noexcept -> Opaque
{
return self.shallow_copy(mm);
}
auto
IGCObject_DBoolean::forward_children(DBoolean & self, obj<ACollector> gc) noexcept -> size_type
{
return self.forward_children(gc);
}
} /*namespace scm*/
} /*namespace xo*/
/* end IGCObject_DBoolean.cpp */

View file

@ -0,0 +1,28 @@
/** @file IPrintable_DBoolean.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IPrintable_DBoolean.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/IPrintable_DBoolean.json5]
**/
#include "boolean/IPrintable_DBoolean.hpp"
namespace xo {
namespace scm {
auto
IPrintable_DBoolean::pretty(const DBoolean & self, const ppindentinfo & ppii) -> bool
{
return self.pretty(ppii);
}
} /*namespace scm*/
} /*namespace xo*/
/* end IPrintable_DBoolean.cpp */

View file

@ -7,11 +7,13 @@
#include <xo/object2/array/IGCObject_DArray.hpp>
#include <xo/object2/list/IGCObject_DList.hpp>
#include <xo/object2/boolean/IGCObject_DBoolean.hpp>
#include <xo/object2/number/IGCObject_DFloat.hpp>
#include <xo/object2/number/IGCObject_DInteger.hpp>
#include <xo/object2/string/IGCObject_DString.hpp>
#include <xo/object2/list/IPrintable_DList.hpp>
#include <xo/object2/boolean/IPrintable_DBoolean.hpp>
#include <xo/object2/number/IPrintable_DFloat.hpp>
#include <xo/object2/number/IPrintable_DInteger.hpp>
#include <xo/object2/string/IPrintable_DString.hpp>
@ -29,9 +31,11 @@ namespace xo {
using xo::mm::AAllocator;
using xo::mm::AGCObject;
using xo::scm::DList;
using xo::scm::DBoolean;
using xo::scm::DFloat;
using xo::scm::DString;
using xo::scm::DArray;
using xo::facet::DVariantPlaceholder;
using xo::facet::FacetRegistry;
using xo::facet::typeseq;
@ -45,6 +49,9 @@ namespace xo {
FacetRegistry::register_impl<APrintable, DList>();
FacetRegistry::register_impl<ASequence, DList>();
FacetRegistry::register_impl<AGCObject, DBoolean>();
FacetRegistry::register_impl<APrintable, DBoolean>();
FacetRegistry::register_impl<AGCObject, DFloat>();
FacetRegistry::register_impl<APrintable, DFloat>();
@ -57,7 +64,10 @@ namespace xo {
FacetRegistry::register_impl<AGCObject, DArray>();
FacetRegistry::register_impl<ASequence, DArray>();
log && log(xtag("DVariantPlaceholder.tseq", typeseq::id<DVariantPlaceholder>()));
log && log(xtag("DList.tseq", typeseq::id<DList>()));
log && log(xtag("DBoolean.tseq", typeseq::id<DFloat>()));
log && log(xtag("DFloat.tseq", typeseq::id<DFloat>()));
log && log(xtag("DInteger.tseq", typeseq::id<DInteger>()));
log && log(xtag("DString.tseq", typeseq::id<DString>()));

View file

@ -5,6 +5,7 @@
#include "object2_register_types.hpp"
#include "boolean/IGCObject_DBoolean.hpp"
#include "number/IGCObject_DFloat.hpp"
#include "number/IGCObject_DInteger.hpp"
#include "string/IGCObject_DString.hpp"
@ -33,6 +34,8 @@ namespace xo {
bool ok = true;
ok &= gc.install_type(impl_for<AGCObject, DBoolean>());
ok &= gc.install_type(impl_for<AGCObject, DFloat>());
ok &= gc.install_type(impl_for<AGCObject, DInteger>());