From 19961facb54e077f4bf121d68444cbe03b5ad324 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Thu, 29 Jan 2026 15:12:00 -0500 Subject: [PATCH] xo-object2: implement APrintable for DArray --- CMakeLists.txt | 12 ++++++ include/xo/object2/DArray.hpp | 3 ++ .../xo/object2/number/IGCObject_DFloat.hpp | 1 + src/object2/CMakeLists.txt | 1 + src/object2/DArray.cpp | 41 +++++++++++++++++++ 5 files changed, 58 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 261b59d..83b2422 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -184,6 +184,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-array + FACET_PKG xo_printable2 + FACET Printable + REPR Array + INPUT idl/IPrintable_DArray.json5 + OUTPUT_HPP_DIR include/xo/object2 + OUTPUT_IMPL_SUBDIR array + OUTPUT_CPP_DIR src/object2 +) + # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-object2-facetimpl-gcobject-array diff --git a/include/xo/object2/DArray.hpp b/include/xo/object2/DArray.hpp index 097b9a4..f50936e 100644 --- a/include/xo/object2/DArray.hpp +++ b/include/xo/object2/DArray.hpp @@ -108,6 +108,9 @@ namespace xo { /** @defgroup darray-printable-methods **/ ///@{ + /** pretty-printing support **/ + bool pretty(const ppindentinfo & ppii) const; + ///@} /** @defgroup darray-gcobject-methods **/ ///@{ diff --git a/include/xo/object2/number/IGCObject_DFloat.hpp b/include/xo/object2/number/IGCObject_DFloat.hpp index b27163c..a5a01ff 100644 --- a/include/xo/object2/number/IGCObject_DFloat.hpp +++ b/include/xo/object2/number/IGCObject_DFloat.hpp @@ -14,6 +14,7 @@ #pragma once #include "GCObject.hpp" +#include #include #include #include "DFloat.hpp" diff --git a/src/object2/CMakeLists.txt b/src/object2/CMakeLists.txt index 2ea8a07..609290e 100644 --- a/src/object2/CMakeLists.txt +++ b/src/object2/CMakeLists.txt @@ -16,6 +16,7 @@ set(SELF_SRCS ISequence_Any.cpp ISequence_DArray.cpp ISequence_DList.cpp + IPrintable_DArray.cpp IPrintable_DList.cpp IPrintable_DBoolean.cpp IPrintable_DFloat.cpp diff --git a/src/object2/DArray.cpp b/src/object2/DArray.cpp index 1b4138c..b1343a6 100644 --- a/src/object2/DArray.cpp +++ b/src/object2/DArray.cpp @@ -4,11 +4,16 @@ **/ #include "DArray.hpp" +#include +#include +#include #include #include #include namespace xo { + using xo::print::APrintable; + using xo::facet::FacetRegistry; using xo::mm::AGCObject; using xo::facet::typeseq; @@ -62,6 +67,42 @@ namespace xo { } } + // printing support + + bool + DArray::pretty(const ppindentinfo & ppii) const + { + using xo::print::ppstate; + + ppstate * pps = ppii.pps(); + + if (ppii.upto()) { + /* perhaps print on one line */ + pps->write("["); + + for (size_t i = 0, n = this->size(); i < n; ++i ) { + if (i > 0) + pps->write(" "); + + obj elt + = FacetRegistry::instance().variant(this->at(i)); + + assert(elt.data()); + + if (!pps->print_upto(elt)) + return false; + + ++i; + } + + pps->write("]"); + return true; + } else { + pps->write("[...]"); + return false; + } + } + // gc hooks for IGCObject_DArray std::size_t