xo-object2: implement APrintable for DArray
This commit is contained in:
parent
eef4a1db5d
commit
19961facb5
5 changed files with 58 additions and 0 deletions
|
|
@ -184,6 +184,18 @@ xo_add_genfacetimpl(
|
||||||
OUTPUT_CPP_DIR src/object2
|
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
|
# note: manual target; generated code committed to git
|
||||||
xo_add_genfacetimpl(
|
xo_add_genfacetimpl(
|
||||||
TARGET xo-object2-facetimpl-gcobject-array
|
TARGET xo-object2-facetimpl-gcobject-array
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,9 @@ namespace xo {
|
||||||
/** @defgroup darray-printable-methods **/
|
/** @defgroup darray-printable-methods **/
|
||||||
///@{
|
///@{
|
||||||
|
|
||||||
|
/** pretty-printing support **/
|
||||||
|
bool pretty(const ppindentinfo & ppii) const;
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
/** @defgroup darray-gcobject-methods **/
|
/** @defgroup darray-gcobject-methods **/
|
||||||
///@{
|
///@{
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "GCObject.hpp"
|
#include "GCObject.hpp"
|
||||||
|
#include <xo/object2/number/GCObjectConversion_DFloat.hpp>
|
||||||
#include <xo/gc/GCObject.hpp>
|
#include <xo/gc/GCObject.hpp>
|
||||||
#include <xo/alloc2/Allocator.hpp>
|
#include <xo/alloc2/Allocator.hpp>
|
||||||
#include "DFloat.hpp"
|
#include "DFloat.hpp"
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ set(SELF_SRCS
|
||||||
ISequence_Any.cpp
|
ISequence_Any.cpp
|
||||||
ISequence_DArray.cpp
|
ISequence_DArray.cpp
|
||||||
ISequence_DList.cpp
|
ISequence_DList.cpp
|
||||||
|
IPrintable_DArray.cpp
|
||||||
IPrintable_DList.cpp
|
IPrintable_DList.cpp
|
||||||
IPrintable_DBoolean.cpp
|
IPrintable_DBoolean.cpp
|
||||||
IPrintable_DFloat.cpp
|
IPrintable_DFloat.cpp
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,16 @@
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "DArray.hpp"
|
#include "DArray.hpp"
|
||||||
|
#include <xo/printable2/Printable.hpp>
|
||||||
|
#include <xo/facet/FacetRegistry.hpp>
|
||||||
|
#include <xo/indentlog/print/pretty.hpp>
|
||||||
#include <xo/indentlog/print/tostr.hpp>
|
#include <xo/indentlog/print/tostr.hpp>
|
||||||
#include <xo/indentlog/print/tag.hpp>
|
#include <xo/indentlog/print/tag.hpp>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace xo {
|
namespace xo {
|
||||||
|
using xo::print::APrintable;
|
||||||
|
using xo::facet::FacetRegistry;
|
||||||
using xo::mm::AGCObject;
|
using xo::mm::AGCObject;
|
||||||
using xo::facet::typeseq;
|
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<APrintable> elt
|
||||||
|
= FacetRegistry::instance().variant<APrintable,AGCObject>(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
|
// gc hooks for IGCObject_DArray
|
||||||
|
|
||||||
std::size_t
|
std::size_t
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue