From 287fce9b7b12e37f7231a678849dea2af48beef4 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Mon, 5 Jan 2026 17:10:22 -0500 Subject: [PATCH] xo-object2: Printable+DList [WIP] --- .../include/xo/facet/facet_implementation.hpp | 7 +-- xo-object2/CMakeLists.txt | 18 ++++-- xo-object2/idl/IPrintable_DFloat.json5 | 2 +- xo-object2/idl/IPrintable_DList.json5 | 12 ++++ xo-object2/include/xo/object2/DList.hpp | 3 + .../include/xo/object2/IPrintable_DList.hpp | 57 +++++++++++++++++++ xo-object2/src/object2/CMakeLists.txt | 1 + xo-object2/src/object2/DList.cpp | 25 ++++++++ xo-object2/src/object2/IPrintable_DList.cpp | 28 +++++++++ 9 files changed, 142 insertions(+), 11 deletions(-) create mode 100644 xo-object2/idl/IPrintable_DList.json5 create mode 100644 xo-object2/include/xo/object2/IPrintable_DList.hpp create mode 100644 xo-object2/src/object2/IPrintable_DList.cpp diff --git a/xo-facet/include/xo/facet/facet_implementation.hpp b/xo-facet/include/xo/facet/facet_implementation.hpp index 7ef18847..5669860a 100644 --- a/xo-facet/include/xo/facet/facet_implementation.hpp +++ b/xo-facet/include/xo/facet/facet_implementation.hpp @@ -92,7 +92,7 @@ namespace xo { //static_assert(false && "expect specialization which should provide ImplType trait"); }; - /** Retrieve facet implementation for a (facet, datatype) pair **/ + /** Retrieve facet implementation for a (facet, datatype) pair **/ template using FacetImplType = FacetImplementation::ImplType; @@ -123,11 +123,6 @@ namespace xo { * = valid_facet_implementation(); **/ struct DVariantPlaceholder {}; - - /** PLAN: - * expect also will need runtime version of FacetImplementation. - **/ - } /*namespace facet*/ } /*namespace xo*/ diff --git a/xo-object2/CMakeLists.txt b/xo-object2/CMakeLists.txt index 70df940d..2df2cb2c 100644 --- a/xo-object2/CMakeLists.txt +++ b/xo-object2/CMakeLists.txt @@ -27,6 +27,7 @@ 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 FACET_PKG xo_object2 @@ -38,13 +39,10 @@ xo_add_genfacetimpl( OUTPUT_CPP_DIR src/object2 ) -#get_target_property(xo_printable2_dir share_xo_printable2 path) -#message(STATUS "xo_printable2_dir=${xo_printable2_dir}") - +# note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-object2-facetimpl-printable-float FACET_PKG xo_printable2 -# FACET_DIR ${xo_printable2_dir} FACET Printable REPR Float INPUT idl/IPrintable_DFloat.json5 @@ -53,6 +51,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-list + FACET_PKG xo_printable2 + FACET Printable + REPR List + INPUT idl/IPrintable_DList.json5 + OUTPUT_HPP_DIR include/xo/object2 + OUTPUT_IMPL_SUBDIR . + OUTPUT_CPP_DIR src/object2 +) + # ---------------------------------------------------------------- # must complete definition of expression lib before configuring examples diff --git a/xo-object2/idl/IPrintable_DFloat.json5 b/xo-object2/idl/IPrintable_DFloat.json5 index ef51cf70..10673d3f 100644 --- a/xo-object2/idl/IPrintable_DFloat.json5 +++ b/xo-object2/idl/IPrintable_DFloat.json5 @@ -8,5 +8,5 @@ brief: "provide APrintable interface for DFloat", using_doxygen: true, repr: "DFloat", - doc: [ "doc for something or other" ], + doc: [ "implement APrintable for DFloat" ], } diff --git a/xo-object2/idl/IPrintable_DList.json5 b/xo-object2/idl/IPrintable_DList.json5 new file mode 100644 index 00000000..478ce7c2 --- /dev/null +++ b/xo-object2/idl/IPrintable_DList.json5 @@ -0,0 +1,12 @@ +{ + mode: "implementation", + includes: [ "", + "" ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/Printable.json5", + brief: "provide APrintable interface for DList", + using_doxygen: true, + repr: "DList", + doc: [ "implement APrintable for DList" ], +} diff --git a/xo-object2/include/xo/object2/DList.hpp b/xo-object2/include/xo/object2/DList.hpp index 65ed0ad4..f6296933 100644 --- a/xo-object2/include/xo/object2/DList.hpp +++ b/xo-object2/include/xo/object2/DList.hpp @@ -40,6 +40,9 @@ namespace xo { /** return element at 0-based index @p ix **/ obj at(size_type ix) const; + /** pretty-printing driver; combine layout+printing **/ + bool pretty(const ppindentinfo & ppii) const; + /** first member of list **/ obj head_; /** remainder of list **/ diff --git a/xo-object2/include/xo/object2/IPrintable_DList.hpp b/xo-object2/include/xo/object2/IPrintable_DList.hpp new file mode 100644 index 00000000..6a38f020 --- /dev/null +++ b/xo-object2/include/xo/object2/IPrintable_DList.hpp @@ -0,0 +1,57 @@ +/** @file IPrintable_DList.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/home/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DList.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DList.json5] + **/ + +#pragma once + +#include +#include +#include "DList.hpp" + +namespace xo { namespace scm { class IPrintable_DList; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::print::IPrintable_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IPrintable_DList + **/ + class IPrintable_DList { + public: + /** @defgroup scm-printable-dlist-type-traits **/ + ///@{ + using ppindentinfo = xo::print::APrintable::ppindentinfo; + ///@} + /** @defgroup scm-printable-dlist-methods **/ + ///@{ + /** Pretty-printing support for this object. +See [xo-indentlog/xo/indentlog/pretty.hpp] **/ + static bool pretty(const DList & self, const ppindentinfo & ppii); + + ///@} + }; + + } /*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 9ef4c63c..62754f96 100644 --- a/xo-object2/src/object2/CMakeLists.txt +++ b/xo-object2/src/object2/CMakeLists.txt @@ -8,6 +8,7 @@ set(SELF_SRCS ISequence_Any.cpp ISequence_DList.cpp IPrintable_DFloat.cpp + IPrintable_DList.cpp DList.cpp DFloat.cpp object2_register_types.cpp diff --git a/xo-object2/src/object2/DList.cpp b/xo-object2/src/object2/DList.cpp index a30aef82..ea725773 100644 --- a/xo-object2/src/object2/DList.cpp +++ b/xo-object2/src/object2/DList.cpp @@ -84,6 +84,31 @@ namespace xo { return l->head_; } +#ifdef NOT_YET + bool + DList::pretty(const ppindentinfo & ppii) const + { + /* adapted from ppstate.pretty_struct(), see also */ + + using xo::print::ppstate; + + ppstate * pps = ppii.pps(); + + if (ppii.upto()) { +/* perhaps print on one line */ + if (!pps->print_upto("(") + return false; + + /* TODO: probably use iterators here, when available */ + const DList * l = this; + while (!l->is_empty()) { + obj(l->head_.data()); + + } + } + } +#endif + } /*namespace scm*/ } /*namespace xo*/ diff --git a/xo-object2/src/object2/IPrintable_DList.cpp b/xo-object2/src/object2/IPrintable_DList.cpp new file mode 100644 index 00000000..880af691 --- /dev/null +++ b/xo-object2/src/object2/IPrintable_DList.cpp @@ -0,0 +1,28 @@ +/** @file IPrintable_DList.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/home/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DList.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DList.json5] +**/ + +#include "IPrintable_DList.hpp" + +namespace xo { + namespace scm { + auto + IPrintable_DList::pretty(const DList & self, const ppindentinfo & ppii) -> bool + { + return self.pretty(ppii); + } + + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IPrintable_DList.cpp */ \ No newline at end of file