From e88875f3405116dca927438682ac69235eb6cc53 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A1n=20Kupec?= Date: Tue, 31 Mar 2009 21:14:21 +0200 Subject: [PATCH] Pass table attributes via Table object to rows. --- src/Table.cc | 17 ++++++++--------- src/Table.h | 9 ++++++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Table.cc b/src/Table.cc index bd0da65..9e54111 100644 --- a/src/Table.cc +++ b/src/Table.cc @@ -53,9 +53,8 @@ void TableRow::dumbDumpTo (ostream &stream) const { stream << endl; } -void TableRow::dumpTo (ostream &stream, const vector& widths, - TableLineStyle st, unsigned margin) const { - const char * vline = st != none ? lines[st][0] : ""; +void TableRow::dumpTo (ostream &stream, const Table & parent) const { + const char * vline = parent._style != none ? lines[parent._style][0] : ""; unsigned int ssize = 0; // string size in columns bool seen_first = false; @@ -64,7 +63,7 @@ void TableRow::dumpTo (ostream &stream, const vector& widths, e = _columns.end (); stream.setf (ios::left, ios::adjustfield); - stream << string(margin, ' '); + stream << string(parent._margin, ' '); for (unsigned c = 0; i != e ; ++i, ++c) { if (seen_first) { stream.width (0); @@ -76,12 +75,12 @@ void TableRow::dumpTo (ostream &stream, const vector& widths, // stream.width (widths[c]); // that does not work with multibyte chars const string & s = *i; ssize = string_to_columns (s); - if (ssize > widths[c]) - stream << (s.substr(0, widths[c] - 2) + "->"); //! \todo FIXME cut at the correct place + if (ssize > parent._max_width[c]) + stream << (s.substr(0, parent._max_width[c] - 2) + "->"); //! \todo FIXME cut at the correct place else { stream << s; - stream.width (widths[c] - ssize); + stream.width (parent._max_width[c] - ssize); } stream << ""; } @@ -180,7 +179,7 @@ void Table::dumpTo (ostream &stream) const { } if (_has_header) { - _header.dumpTo (stream, _max_width, _style, _margin ); + _header.dumpTo (stream, *this); dumpRule (stream); } @@ -189,7 +188,7 @@ void Table::dumpTo (ostream &stream) const { e = _rows.end (), i; for (i = b; i != e; ++i) { - i->dumpTo (stream, _max_width, _style, _margin); + i->dumpTo (stream, *this); } } diff --git a/src/Table.h b/src/Table.h index caaaaf4..ac441dd 100644 --- a/src/Table.h +++ b/src/Table.h @@ -35,6 +35,8 @@ enum TableLineStyle { _End, ///< sentinel }; +class Table; + class TableRow { public: //! Constructor. Reserve place for c columns. @@ -49,9 +51,8 @@ public: //! tab separated output void dumbDumpTo (ostream &stream) const; - //! output with field widths - void dumpTo (ostream &stream, const vector& widths, - TableLineStyle st, unsigned margin) const; + //! output with \a parent table attributes + void dumpTo (ostream & stream, const Table & parent) const; typedef vector container; @@ -121,6 +122,8 @@ private: vector _abbrev_col; //! left/right margin in number of spaces unsigned _margin; + + friend class TableRow; }; inline -- 2.7.4