xo-object2: implement APrintable for DArray
This commit is contained in:
parent
6df599673a
commit
8f531065a9
5 changed files with 58 additions and 0 deletions
|
|
@ -4,11 +4,16 @@
|
|||
**/
|
||||
|
||||
#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/tag.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
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<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
|
||||
|
||||
std::size_t
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue