From c9a239f6108162a526782f5f5aac3b48d9eab337 Mon Sep 17 00:00:00 2001 From: Klaus Kaempf Date: Wed, 25 Jul 2007 15:04:12 +0000 Subject: [PATCH] - provide number of columns from TableRow - check sort column against _max_cols todo: provide error reporting / exception ? --- src/zypper-tabulator.cc | 9 +++++++++ src/zypper-tabulator.h | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/zypper-tabulator.cc b/src/zypper-tabulator.cc index 9dbf424..2040ea3 100644 --- a/src/zypper-tabulator.cc +++ b/src/zypper-tabulator.cc @@ -23,6 +23,10 @@ void TableRow::add (const string& s) { _columns.push_back (s); } +unsigned int TableRow::cols( void ) const { + return _columns.size(); +} + // 1st implementation: no width calculation, just tabs void TableRow::dumbDumpTo (ostream &stream) const { bool seen_first = false; @@ -130,6 +134,11 @@ void Table::style (TableStyle st) { } void Table::sort (unsigned by_column) { + if (by_column >= _max_col) { +#warning Provide proper error handling here + return; + } + TableRow::Less comp (by_column); _rows.sort (comp); } diff --git a/src/zypper-tabulator.h b/src/zypper-tabulator.h index e198fe7..8765c69 100644 --- a/src/zypper-tabulator.h +++ b/src/zypper-tabulator.h @@ -43,6 +43,9 @@ public: void add (const string& s); + // return number of columns + unsigned int cols( void ) const; + //! tab separated output void dumbDumpTo (ostream &stream) const; //! output with field widths @@ -89,7 +92,7 @@ public: typedef list container; void style (TableStyle st); - void sort (unsigned by_column); + void sort (unsigned by_column); // columns start with 0... Table () : _has_header (false), -- 2.7.4