xo-facet xo-object2: facet fixes + IPrintable_DString

This commit is contained in:
Roland Conybeare 2026-01-14 16:32:58 -05:00
commit 8a5cd339e8
11 changed files with 135 additions and 2 deletions

View file

@ -64,6 +64,18 @@ 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
FACET_PKG xo_printable2
FACET Printable
REPR String
INPUT idl/IPrintable_DString.json5
OUTPUT_HPP_DIR include/xo/object2/string
OUTPUT_IMPL_SUBDIR .
OUTPUT_CPP_DIR src/object2
)
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-object2-facetimpl-gcobject-string

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

View file

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

View file

@ -11,6 +11,7 @@ set(SELF_SRCS
IPrintable_DList.cpp
IPrintable_DFloat.cpp
IPrintable_DInteger.cpp
IPrintable_DString.cpp
DList.cpp
DFloat.cpp
DInteger.cpp

View file

@ -5,6 +5,7 @@
#include "DInteger.hpp"
#include <xo/indentlog/print/pretty.hpp>
#include <xo/indentlog/scope.hpp>
namespace xo {
using xo::facet::typeseq;

View file

@ -4,6 +4,8 @@
**/
#include "DList.hpp"
#include "IPrintable_DList.hpp"
#include <xo/gc/GCObject.hpp>
#include <xo/printable2/Printable.hpp>
#include <xo/facet/FacetRegistry.hpp>
#include <xo/indentlog/print/pretty.hpp>
@ -125,7 +127,9 @@ namespace xo {
obj<APrintable> elt
= FacetRegistry::instance().variant<APrintable, AGCObject>(l->head_);
assert(elt);
assert(elt.data());
if (!pps->print_upto(elt))
return false;

View file

@ -4,11 +4,13 @@
**/
#include "DString.hpp"
#include <xo/indentlog/print/pretty.hpp>
#include <algorithm>
#include <cstring>
namespace xo {
using xo::facet::typeseq;
using xo::print::ppdetail_atomic;
namespace scm {
DString *
@ -113,6 +115,12 @@ namespace xo {
return shallow_size();
}
bool
DString::pretty(const ppindentinfo & ppii) const
{
return ppdetail_atomic<const char *>::print_pretty(ppii, &(chars_[0]));
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -12,6 +12,7 @@
**/
#include "IPrintable_DList.hpp"
#include <xo/indentlog/scope.hpp>
namespace xo {
namespace scm {

View file

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

View file

@ -13,6 +13,7 @@
#include <xo/object2/IPrintable_DList.hpp>
#include <xo/object2/IPrintable_DFloat.hpp>
#include <xo/object2/IPrintable_DInteger.hpp>
#include <xo/object2/string/IPrintable_DString.hpp>
#include <xo/printable2/detail/APrintable.hpp>
#include <xo/alloc2/alloc/AAllocator.hpp>
@ -45,6 +46,7 @@ namespace xo {
FacetRegistry::register_impl<APrintable, DInteger>();
FacetRegistry::register_impl<AGCObject, DString>();
FacetRegistry::register_impl<APrintable, DString>();
log && log(xtag("DList.tseq", typeseq::id<DList>()));
log && log(xtag("DFloat.tseq", typeseq::id<DFloat>()));

View file

@ -89,6 +89,8 @@ namespace ut {
FacetRegistry::instance().dump(&std::cerr);
for (std::size_t i_tc = 0, n_tc = s_testcase_v.size(); i_tc < n_tc; ++i_tc) {
log && log("printable1 test:", xtag("i_tc", i_tc));
try {
const testcase_pp & tc = s_testcase_v[i_tc];
@ -130,7 +132,7 @@ namespace ut {
pps.pretty(l0_po);
REQUIRE(ss.str() == string(tc.expected_));
CHECK(ss.str() == string(tc.expected_));
} catch (std::exception & ex) {
std::cerr << "caught exception: " << ex.what() << std::endl;
REQUIRE(false);