From d2d3b34ce724ce597df9cc8d660fddb39ba847b7 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 14 Jan 2026 16:32:58 -0500 Subject: [PATCH] xo-facet xo-object2: facet fixes + IPrintable_DString --- xo-facet/codegen/facet.hpp.j2 | 4 ++ xo-facet/codegen/genfacet | 4 ++ xo-facet/codegen/router_facet.hpp.j2 | 5 +- xo-object2/CMakeLists.txt | 12 ++++ xo-object2/idl/IPrintable_DString.json5 | 13 ++++ .../xo/object2/string/IPrintable_DString.hpp | 61 +++++++++++++++++++ xo-object2/src/object2/CMakeLists.txt | 1 + xo-object2/src/object2/DInteger.cpp | 1 + xo-object2/src/object2/DList.cpp | 6 +- xo-object2/src/object2/DString.cpp | 8 +++ xo-object2/src/object2/IPrintable_DList.cpp | 1 + xo-object2/src/object2/IPrintable_DString.cpp | 28 +++++++++ .../src/object2/object2_register_facets.cpp | 2 + xo-object2/utest/Printable.test.cpp | 4 +- xo-printable2/idl/Printable.json5 | 4 ++ .../include/xo/printable2/Printable.hpp | 5 +- .../xo/printable2/detail/APrintable.hpp | 12 ++-- .../xo/printable2/detail/IPrintable_Any.hpp | 6 +- .../xo/printable2/detail/IPrintable_Xfer.hpp | 6 +- .../xo/printable2/detail/RPrintable.hpp | 16 +++-- .../src/printable2/IPrintable_Any.cpp | 3 + 21 files changed, 176 insertions(+), 26 deletions(-) create mode 100644 xo-object2/idl/IPrintable_DString.json5 create mode 100644 xo-object2/include/xo/object2/string/IPrintable_DString.hpp create mode 100644 xo-object2/src/object2/IPrintable_DString.cpp diff --git a/xo-facet/codegen/facet.hpp.j2 b/xo-facet/codegen/facet.hpp.j2 index 2eeaa5df..82678c54 100644 --- a/xo-facet/codegen/facet.hpp.j2 +++ b/xo-facet/codegen/facet.hpp.j2 @@ -18,4 +18,8 @@ #include "{{impl_hpp_subdir}}/{{iface_facet_xfer_hpp_fname}}" #include "{{impl_hpp_subdir}}/{{router_facet_hpp_fname}}" +{% for include_fname in user_hpp_includes %} +#include {{include_fname}} +{% endfor %} + /* end {{facet_hpp_fname}} */ diff --git a/xo-facet/codegen/genfacet b/xo-facet/codegen/genfacet index 788faf46..4d4f3fe5 100755 --- a/xo-facet/codegen/genfacet +++ b/xo-facet/codegen/genfacet @@ -93,6 +93,8 @@ def gen_facet(env, # extra include files (or perhaps other definitions) facet_includes = idl['includes'] + # extra (post) includes for user .hpp e.g. Sequence.hpp + user_hpp_includes = idl['user_hpp_includes'] # arbitrary text after includes, before opening namespaces facet_pretext = idl['pretext'] # detail @@ -163,6 +165,8 @@ def gen_facet(env, 'facet_ns2': facet_ns2, 'facet_name_lc': facet_name_lc, 'facet_hpp_fname': facet_hpp_fname, + # + 'user_hpp_includes': user_hpp_includes, #'name': facet_name, 'idl_fname': idl_fname, # diff --git a/xo-facet/codegen/router_facet.hpp.j2 b/xo-facet/codegen/router_facet.hpp.j2 index 7dba7672..b8d70733 100644 --- a/xo-facet/codegen/router_facet.hpp.j2 +++ b/xo-facet/codegen/router_facet.hpp.j2 @@ -46,6 +46,9 @@ public: {% endif %} {{router_facet}}() {} {{router_facet}}(Object::DataPtr data) : Object{std::move(data)} {} + {{router_facet}}(const {{abstract_facet}} * iface, void * data) + requires std::is_same_v + : Object(iface, data) {} {% if using_dox %} ///@} @@ -61,7 +64,7 @@ public: } {% endfor %} - // non-const methods + // non-const methods (still const in router!) {% for md in nonconst_methods %} {{md.return_type}} {{md.name}}({{md.args | argsnodata}}) {{md | staticqual}} { return O::iface()->{{md.name}}({{md.args | argrouting}}); diff --git a/xo-object2/CMakeLists.txt b/xo-object2/CMakeLists.txt index 31b408a1..19a59363 100644 --- a/xo-object2/CMakeLists.txt +++ b/xo-object2/CMakeLists.txt @@ -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 diff --git a/xo-object2/idl/IPrintable_DString.json5 b/xo-object2/idl/IPrintable_DString.json5 new file mode 100644 index 00000000..f032ca46 --- /dev/null +++ b/xo-object2/idl/IPrintable_DString.json5 @@ -0,0 +1,13 @@ +{ + mode: "implementation", + includes: [ "", + "" ], + 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" ], +} diff --git a/xo-object2/include/xo/object2/string/IPrintable_DString.hpp b/xo-object2/include/xo/object2/string/IPrintable_DString.hpp new file mode 100644 index 00000000..d1d3f22a --- /dev/null +++ b/xo-object2/include/xo/object2/string/IPrintable_DString.hpp @@ -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 +#include +#include "DString.hpp" + +namespace xo { namespace scm { class IPrintable_DString; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::print::IPrintable_Xfer + ; + }; + } +} + +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 */ \ No newline at end of file diff --git a/xo-object2/src/object2/CMakeLists.txt b/xo-object2/src/object2/CMakeLists.txt index 4c74529f..5764d98b 100644 --- a/xo-object2/src/object2/CMakeLists.txt +++ b/xo-object2/src/object2/CMakeLists.txt @@ -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 diff --git a/xo-object2/src/object2/DInteger.cpp b/xo-object2/src/object2/DInteger.cpp index 8e1b9594..6c670ccd 100644 --- a/xo-object2/src/object2/DInteger.cpp +++ b/xo-object2/src/object2/DInteger.cpp @@ -5,6 +5,7 @@ #include "DInteger.hpp" #include +#include namespace xo { using xo::facet::typeseq; diff --git a/xo-object2/src/object2/DList.cpp b/xo-object2/src/object2/DList.cpp index b43d1a9f..19e09e11 100644 --- a/xo-object2/src/object2/DList.cpp +++ b/xo-object2/src/object2/DList.cpp @@ -4,6 +4,8 @@ **/ #include "DList.hpp" +#include "IPrintable_DList.hpp" +#include #include #include #include @@ -125,7 +127,9 @@ namespace xo { obj elt = FacetRegistry::instance().variant(l->head_); - assert(elt); + + + assert(elt.data()); if (!pps->print_upto(elt)) return false; diff --git a/xo-object2/src/object2/DString.cpp b/xo-object2/src/object2/DString.cpp index 3278d258..517f3f97 100644 --- a/xo-object2/src/object2/DString.cpp +++ b/xo-object2/src/object2/DString.cpp @@ -4,11 +4,13 @@ **/ #include "DString.hpp" +#include #include #include 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::print_pretty(ppii, &(chars_[0])); + } + } /*namespace scm*/ } /*namespace xo*/ diff --git a/xo-object2/src/object2/IPrintable_DList.cpp b/xo-object2/src/object2/IPrintable_DList.cpp index 19e5a875..bdcf6694 100644 --- a/xo-object2/src/object2/IPrintable_DList.cpp +++ b/xo-object2/src/object2/IPrintable_DList.cpp @@ -12,6 +12,7 @@ **/ #include "IPrintable_DList.hpp" +#include namespace xo { namespace scm { diff --git a/xo-object2/src/object2/IPrintable_DString.cpp b/xo-object2/src/object2/IPrintable_DString.cpp new file mode 100644 index 00000000..f47aa3fa --- /dev/null +++ b/xo-object2/src/object2/IPrintable_DString.cpp @@ -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 */ diff --git a/xo-object2/src/object2/object2_register_facets.cpp b/xo-object2/src/object2/object2_register_facets.cpp index 8b9e8106..9cf67988 100644 --- a/xo-object2/src/object2/object2_register_facets.cpp +++ b/xo-object2/src/object2/object2_register_facets.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -45,6 +46,7 @@ namespace xo { FacetRegistry::register_impl(); FacetRegistry::register_impl(); + FacetRegistry::register_impl(); log && log(xtag("DList.tseq", typeseq::id())); log && log(xtag("DFloat.tseq", typeseq::id())); diff --git a/xo-object2/utest/Printable.test.cpp b/xo-object2/utest/Printable.test.cpp index 47bfcf1b..c1b63dc4 100644 --- a/xo-object2/utest/Printable.test.cpp +++ b/xo-object2/utest/Printable.test.cpp @@ -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); diff --git a/xo-printable2/idl/Printable.json5 b/xo-printable2/idl/Printable.json5 index e71d827c..1cf52da6 100644 --- a/xo-printable2/idl/Printable.json5 +++ b/xo-printable2/idl/Printable.json5 @@ -1,8 +1,11 @@ { mode: "facet", includes: [""], + // extra includes in Printable.hpp + user_hpp_includes: ["\"detail/ppdetail_Printable.hpp\""], namespace1: "xo", namespace2: "print", + pretext: [], facet: "Printable", detail_subdir: "detail", brief: "pretty-printable objects", @@ -30,6 +33,7 @@ args: [ {type: "const ppindentinfo &", name: "ppii"}, ], + const: true, }, ], nonconst_methods: [], diff --git a/xo-printable2/include/xo/printable2/Printable.hpp b/xo-printable2/include/xo/printable2/Printable.hpp index 2e2064f5..1789f1e0 100644 --- a/xo-printable2/include/xo/printable2/Printable.hpp +++ b/xo-printable2/include/xo/printable2/Printable.hpp @@ -2,7 +2,7 @@ * * Generated automagically from ingredients: * 1. code generator: - * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] * arguments: * --input [idl/Printable.json5] * 2. jinja2 template for facet .hpp file: @@ -18,7 +18,6 @@ #include "detail/IPrintable_Xfer.hpp" #include "detail/RPrintable.hpp" -// todo: additional includes in idl above #include "detail/ppdetail_Printable.hpp" -/* end Printable.hpp */ +/* end Printable.hpp */ \ No newline at end of file diff --git a/xo-printable2/include/xo/printable2/detail/APrintable.hpp b/xo-printable2/include/xo/printable2/detail/APrintable.hpp index c9217ba8..e5b757de 100644 --- a/xo-printable2/include/xo/printable2/detail/APrintable.hpp +++ b/xo-printable2/include/xo/printable2/detail/APrintable.hpp @@ -2,7 +2,7 @@ * * Generated automagically from ingredients: * 1. code generator: - * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] * arguments: * --input [idl/Printable.json5] * 2. jinja2 template for abstract facet .hpp file: @@ -19,6 +19,7 @@ #include #include + namespace xo { namespace print { @@ -35,6 +36,8 @@ public: // types /** integer identifying a type **/ using typeseq = xo::facet::typeseq; + using Copaque = const void *; + using Opaque = void *; /** dynamic pretty-printing state during layout **/ using ppindentinfo = xo::print::ppindentinfo; ///@} @@ -45,9 +48,8 @@ public: /** RTTI: unique id# for actual runtime data representation **/ virtual typeseq _typeseq() const noexcept = 0; /** Pretty-printing support for this object. - See [xo-indentlog/xo/indentlog/pretty.hpp] - **/ - virtual bool pretty(Copaque data, const ppindentinfo & ppii) const = 0; +See [xo-indentlog/xo/indentlog/pretty.hpp] **/ + virtual bool pretty(Copaque data, const ppindentinfo & ppii) const = 0; // nonconst methods ///@} @@ -69,4 +71,4 @@ using IPrintable_ImplType = xo::facet::FacetImplType; } /*namespace print*/ } /*namespace xo*/ -/* */ +/* APrintable.hpp */ \ No newline at end of file diff --git a/xo-printable2/include/xo/printable2/detail/IPrintable_Any.hpp b/xo-printable2/include/xo/printable2/detail/IPrintable_Any.hpp index 794284d8..ae3faf0f 100644 --- a/xo-printable2/include/xo/printable2/detail/IPrintable_Any.hpp +++ b/xo-printable2/include/xo/printable2/detail/IPrintable_Any.hpp @@ -2,7 +2,7 @@ * * Generated automagically from ingredients: * 1. code generator: - * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] * arguments: * --input [idl/Printable.json5] * 2. jinja2 template for abstract facet .hpp file: @@ -56,7 +56,7 @@ namespace print { // const methods typeseq _typeseq() const noexcept override { return s_typeseq; } - [[noreturn]] bool pretty(Copaque, const ppindentinfo &) const override { _fatal(); } + [[noreturn]] bool pretty(Copaque, const ppindentinfo &) const override { _fatal(); } // nonconst methods @@ -83,4 +83,4 @@ namespace print { } /*namespace print */ } /*namespace xo */ -/* IPrintable_Any.hpp */ +/* IPrintable_Any.hpp */ \ No newline at end of file diff --git a/xo-printable2/include/xo/printable2/detail/IPrintable_Xfer.hpp b/xo-printable2/include/xo/printable2/detail/IPrintable_Xfer.hpp index 8ee71003..78de7e43 100644 --- a/xo-printable2/include/xo/printable2/detail/IPrintable_Xfer.hpp +++ b/xo-printable2/include/xo/printable2/detail/IPrintable_Xfer.hpp @@ -2,7 +2,7 @@ * * Generated automagically from ingredients: * 1. code generator: - * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] * arguments: * --input [idl/Printable.json5] * 2. jinja2 template for abstract facet .hpp file: @@ -41,7 +41,7 @@ namespace print { // const methods typeseq _typeseq() const noexcept override { return s_typeseq; } - bool pretty(Copaque data, const ppindentinfo & ppii) const override { + bool pretty(Copaque data, const ppindentinfo & ppii) const override { return I::pretty(_dcast(data), ppii); } @@ -78,4 +78,4 @@ namespace print { } /*namespace print */ } /*namespace xo*/ -/* end IPrintable_Xfer.hpp */ +/* end IPrintable_Xfer.hpp */ \ No newline at end of file diff --git a/xo-printable2/include/xo/printable2/detail/RPrintable.hpp b/xo-printable2/include/xo/printable2/detail/RPrintable.hpp index 12a6105c..8d24b17a 100644 --- a/xo-printable2/include/xo/printable2/detail/RPrintable.hpp +++ b/xo-printable2/include/xo/printable2/detail/RPrintable.hpp @@ -2,7 +2,7 @@ * * Generated automagically from ingredients: * 1. code generator: - * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] * arguments: * --input [idl/Printable.json5] * 2. jinja2 template for abstract facet .hpp file: @@ -30,8 +30,8 @@ public: ///@{ using ObjectType = Object; using DataPtr = Object::DataPtr; + using typeseq = xo::reflect::typeseq; using ppindentinfo = APrintable::ppindentinfo; - using typeseq = xo::facet::typeseq; ///@} /** @defgroup print-printable-router-ctors **/ @@ -39,8 +39,8 @@ public: RPrintable() {} RPrintable(Object::DataPtr data) : Object{std::move(data)} {} RPrintable(const APrintable * iface, void * data) - requires std::is_same_v - : Object(iface, data) {} + requires std::is_same_v + : Object(iface, data) {} ///@} /** @defgroup print-printable-router-methods **/ @@ -48,13 +48,11 @@ public: // const methods typeseq _typeseq() const noexcept { return O::iface()->_typeseq(); } - bool pretty(const ppindentinfo & ppii) const { + bool pretty(const ppindentinfo & ppii) const { return O::iface()->pretty(O::data(), ppii); } - // non-const methods - // << do something for non-const methods >> - // + // non-const methods (still const in router!) ///@} /** @defgroup print-printable-member-vars **/ @@ -79,4 +77,4 @@ namespace xo { namespace facet { }; } } -/* end RPrintable.hpp */ +/* end RPrintable.hpp */ \ No newline at end of file diff --git a/xo-printable2/src/printable2/IPrintable_Any.cpp b/xo-printable2/src/printable2/IPrintable_Any.cpp index ecef6484..8ff043f1 100644 --- a/xo-printable2/src/printable2/IPrintable_Any.cpp +++ b/xo-printable2/src/printable2/IPrintable_Any.cpp @@ -32,6 +32,9 @@ bool IPrintable_Any::_valid = valid_facet_implementation(); +// nonconst methods + + } /*namespace print*/ } /*namespace xo*/