Mailinglist Archive: zypp-commit (233 mails)

< Previous Next >
[zypp-commit] <libzypp> ma-misc : backup
  • From: Michael Andres <ma@xxxxxxx>
  • Date: Tue, 3 Nov 2009 11:35:00 +0100
  • Message-id: <E1N5GjD-0001cM-DV@xxxxxxxxxxxxxxxx>
ref: refs/heads/ma-misc
commit 3fde09c61eb0343e46d4e46a91bfb0a633a83d53
Author: Michael Andres <ma@xxxxxxx>
Date: Tue Nov 3 11:35:00 2009 +0100

backup
---
devel/devel.ma/Main.cc | 89 ++++++++++++++++++++++++++++++++++-------------
1 files changed, 64 insertions(+), 25 deletions(-)

diff --git a/devel/devel.ma/Main.cc b/devel/devel.ma/Main.cc
index 9704d9e..482520d 100644
--- a/devel/devel.ma/Main.cc
+++ b/devel/devel.ma/Main.cc
@@ -165,48 +165,76 @@ namespace zypp
private:
std::string _str;
};
-
-
-
/////////////////////////////////////////////////////////////////
} //table
///////////////////////////////////////////////////////////////////

- class TableData
- {
- public:
- TableData() {}
- TableData( const std::string & str_r ) : _str( str_r ) {}
- public:
- size_type hSize() const { return _str.size(); }
- size_type vSize() const { return _str.empty() ? 0 : 1; }
- private:
- std::string _str;
- };
-
- typedef shared_ptr<TableData> TableDataPtr;
-
class Table : public table::Decorated
{
public:
typedef size_t size_type;
- typedef table::Cell Cell;

public:
-
- void addItem( const TableDataPtr & data_r, unsigned row_r, unsigned
col_r );
+ template<class _Tp>
+ void addItem( const _Tp & data_r, unsigned row_r, unsigned col_r )
+ { addItem( Cell( str::asString( data_r ) ), row_r, col_r ); }

public:
- bool empty() const { return _table.empty(); }
- size_type rows() const { return _table.size(); }
- size_type cols() const { return _table.empty() ? 0 : _table[0].size();
}
+ bool empty() const { return _rows.empty(); }
+ size_type rows() const { return _rows.size(); }
+ size_type cols() const { return _rows.empty() ? 0 : _rows[0].size(); }

private:
+ typedef table::Cell Cell;
typedef std::vector<Cell> Cells;
- struct Row : public Decorated
- { Cells _cells; };
+ struct Row : public Cells, public Decorated
+ {};
typedef std::vector<Row> Rows;
private:
+ bool haveCell( unsigned row_r, unsigned col_r ) const
+ { return row_r < rows() && col_r < cols(); }
+ const Cell & cell( unsigned row_r, unsigned col_r ) const
+ { return _rows[row_r][col_r]; }
+ Cell & cell( unsigned row_r, unsigned col_r )
+ { return _rows[row_r][col_r]; }
+ void assertCols( size_type num_r )
+ {
+ if ( num_r > cols() )
+ for_( it, _rows.begin(), _rows.end() )
+ {
+ it->resize( num_r );
+ }
+ }
+ void assertRows( size_type num_r )
+ {
+ while ( num_r > rows() )
+ {
+ _rows.push_back( Row() );
+ _rows.back().resize( cols() );
+ }
+ }
+ void assertCell( unsigned row_r, unsigned col_r )
+ {
+ if ( empty() )
+ {
+ assertRows( row_r+1 );
+ assertCols( col_r+1 );
+ }
+ else
+ {
+ assertCols( col_r+1 );
+ assertRows( row_r+1 );
+ }
+ }
+ Cell & addCell( unsigned row_r, unsigned col_r )
+ {
+ assertCell( col_r,row_r );
+ return cell( row_r, col_r );
+ }
+ private:
+ void addItem( const Cell & data_r, unsigned row_r, unsigned col_r )
+ { addCell( row_r, col_r ) = data_r; }
+ private:
Rows _rows;
Decoration _defaultRowDecoration;
Decoration _defaultCellDecoration;
@@ -248,6 +276,17 @@ try {
Table t;
USR << t << endl;

+ t.addItem( 2, 0, 0 );
+ USR << t << endl;
+
+ t.addItem( "foo", 2, 2 );
+ USR << t << endl;
+
+ t.addItem( Arch_x86_64, 2, 2 );
+ USR << t << endl;
+
+ t.addItem( Date::now(), 2, 2 );
+ USR << t << endl;

#if 0
upgrade();
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >