Wt::Matrix< T > Class Template Reference

#include <matrix.h>

Inheritance diagram for Wt::Matrix< T >:

Inheritance graph
[legend]
Collaboration diagram for Wt::Matrix< T >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef std::vector< T > Edge
typedef std::vector< EdgeMatrixBase
typedef T value_type

Public Member Functions

 Matrix ()
int numRows () const
int numCols () const
bool empty () const
iterator begin ()
iterator end ()
const_iterator begin () const
const_iterator end () const
T & operator() (int r, int c)
void push_back (const T &t)
iterator erase (iterator it)
iterator find (iterator start, iterator finish, const T &t) const
void remove (const T &t)

Public Attributes

sigc::signal4< void, int,
int, int, int
gridSizeChanged

Protected Member Functions

bool isRowEmpty (int row)
bool isColumnEmpty (int column)
void adjust ()

Private Attributes

int rows_
int columns_

Classes

class  const_iterator
class  iterator

Detailed Description

template<typename T>
class Wt::Matrix< T >

Definition at line 30 of file matrix.h.


Member Typedef Documentation

template<typename T>
typedef std::vector<T> Wt::Matrix< T >::Edge

Definition at line 32 of file matrix.h.

template<typename T>
typedef std::vector<Edge> Wt::Matrix< T >::MatrixBase

Definition at line 33 of file matrix.h.

template<typename T>
typedef T Wt::Matrix< T >::value_type

Definition at line 35 of file matrix.h.


Constructor & Destructor Documentation

template<typename T>
Wt::Matrix< T >::Matrix (  )  [inline]

Definition at line 110 of file matrix.h.

00110              :
00111             rows_(0),
00112     columns_(0) {}


Member Function Documentation

template<typename T>
void Wt::Matrix< T >::adjust (  )  [inline, protected]

Definition at line 261 of file matrix.h.

Referenced by Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::erase().

00261                   {
00262         const int old_rows = rows_;
00263         const int old_cols = columns_;
00264         int row_max, col_max;
00265 
00266         //first find non empty row starting from end
00267         for (row_max = rows_ - 1; row_max >= 0 &&
00268             isRowEmpty(row_max); row_max--) {}
00269 
00270         //now the max column starting from end
00271         for (col_max = columns_ - 1; col_max >= 0 &&
00272             isColumnEmpty(col_max); col_max--) {}
00273 
00274         if (row_max < rows_ - 1 || col_max < columns_ - 1) {
00275             MatrixBase& m = *this;
00276             m.resize(row_max + 1);
00277             rows_ = row_max + 1;
00278 
00279             if (col_max < columns_ - 1) {
00280                 for (int r = 0; r < rows_; r++) {
00281                     (*this)[r].resize(col_max + 1);
00282                 }
00283             }
00284             columns_ = col_max + 1;
00285         }
00286         if (rows_ != old_rows || columns_ != old_cols) {
00287             gridSizeChanged.emit(old_rows, old_cols, rows_, columns_);
00288         }
00289     }

template<typename T>
const_iterator Wt::Matrix< T >::begin (  )  const [inline]

Definition at line 134 of file matrix.h.

00134                                  {
00135         return const_iterator(this);
00136     }

template<typename T>
iterator Wt::Matrix< T >::begin (  )  [inline]

Definition at line 126 of file matrix.h.

Referenced by Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::remove().

00126                      {
00127         return iterator(this);
00128     }

template<typename T>
bool Wt::Matrix< T >::empty (  )  const [inline]

Definition at line 122 of file matrix.h.

Referenced by Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::isColumnEmpty(), and Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::isRowEmpty().

00122                        {
00123         return !rows_ && !columns_;
00124     }

template<typename T>
const_iterator Wt::Matrix< T >::end (  )  const [inline]

Definition at line 138 of file matrix.h.

00138                                {
00139         return const_iterator(this, -1, -1);
00140     }

template<typename T>
iterator Wt::Matrix< T >::end (  )  [inline]

Definition at line 130 of file matrix.h.

Referenced by Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::find(), and Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::remove().

00130                    {
00131         return iterator(this, -1, -1);
00132     }

template<typename T>
iterator Wt::Matrix< T >::erase ( iterator  it  )  [inline]

Definition at line 203 of file matrix.h.

Referenced by Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::remove().

00203                                 {
00204         *it = T();
00205         adjust();
00206         return ++it;
00207     }

template<typename T>
iterator Wt::Matrix< T >::find ( iterator  start,
iterator  finish,
const T &  t 
) const [inline]

Definition at line 209 of file matrix.h.

00209                                                                      {
00210         iterator it = start;
00211         for (; it != finish; ++it) {
00212             if (t == *it)
00213                 break;
00214         }
00215         return (it != finish) ? it : end();
00216     }

template<typename T>
bool Wt::Matrix< T >::isColumnEmpty ( int  column  )  [inline, protected]

Definition at line 247 of file matrix.h.

Referenced by Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::adjust().

00247                                    {
00248         bool empty = true;
00249 
00250         for (int r = 0; r < rows_; r++) {
00251             Matrix& self = *this;
00252             T empty_item;
00253             if (empty_item != self[r][column]) {
00254                 empty = false;
00255                 break;
00256             }
00257         }
00258         return empty;
00259     }

template<typename T>
bool Wt::Matrix< T >::isRowEmpty ( int  row  )  [inline, protected]

Definition at line 233 of file matrix.h.

Referenced by Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::adjust().

00233                              {
00234         bool empty = true;
00235 
00236         for (int c = 0; c < columns_; c++) {
00237             Matrix& self = *this;
00238             T empty_item;
00239             if (empty_item != self[row][c]) {
00240                 empty = false;
00241                 break;
00242             }
00243         }
00244         return empty;
00245     }

template<typename T>
int Wt::Matrix< T >::numCols (  )  const [inline]

Definition at line 118 of file matrix.h.

Referenced by Wt::Matrix< T >::iterator::iterator(), and Wt::Matrix< T >::iterator::operator++().

00118                         {
00119         return columns_;
00120     }

template<typename T>
int Wt::Matrix< T >::numRows (  )  const [inline]

Definition at line 114 of file matrix.h.

Referenced by Wt::Matrix< T >::iterator::iterator(), and Wt::Matrix< T >::iterator::operator++().

00114                         {
00115         return rows_;
00116     }

template<typename T>
T& Wt::Matrix< T >::operator() ( int  r,
int  c 
) [inline]

Definition at line 142 of file matrix.h.

00142                                 {
00143         const int old_rows = rows_;
00144         const int old_cols = columns_;
00145         int i;
00146 
00147         if (r >= old_rows) {
00148             MatrixBase& m = *this;
00149             m.resize(r + 1);
00150             rows_ = r + 1;
00151         }
00152 
00153         const int new_columns = std::max(c + 1, columns_);
00154         for (i = 0; i < rows_; i++) {
00155             (*this)[i].resize(new_columns);
00156         }
00157 
00158         if (c >= columns_) {
00159             columns_ = c + 1;
00160         }
00161 
00162         if (rows_ != old_rows || columns_ != old_cols) {
00163             gridSizeChanged.emit(old_rows, old_cols, rows_, columns_);
00164         }
00165         Matrix& self = *this;
00166         return self[r][c];
00167     }

template<typename T>
void Wt::Matrix< T >::push_back ( const T &  t  )  [inline]

Definition at line 169 of file matrix.h.

00169                                {
00170         Matrix& self = *this;
00171         int r, c;
00172         if (!rows_) {
00173             // start the matrix
00174             r = 0;
00175             c = 0;
00176         } else if (rows_ == 1) {
00177             // in the first line we keep adding columns
00178             r = 0;
00179             c = columns_;
00180         } else {
00181             int j;
00182             // we try to find the first empty item after the last non empty
00183             // if we can't find it before the end of the row we open a new row
00184             for (j = 0; j < columns_ &&
00185                 self[rows_ - 1][columns_ - 1 - j] == T(); j++) {}
00186             if (j == 0) {
00187                 // this row is full, open new row
00188                 r = rows_;
00189                 c = 0;
00190             } else if (j == columns_) {
00191                 // this row is empty, go at at start;
00192                 r = rows_ - 1;
00193                 c = 0;
00194             } else {
00195                 r = rows_ - 1;
00196                 c = columns_ - j;
00197             }
00198         }
00199 
00200         self(r, c) = t;
00201     }

template<typename T>
void Wt::Matrix< T >::remove ( const T &  t  )  [inline]

Definition at line 219 of file matrix.h.

00219                      {
00220         iterator it = begin();
00221         iterator e = end();
00222         while (it != e) {
00223             if (t == *it)
00224                 it = erase(it);
00225             else
00226                 ++it;
00227         }
00228     }


Member Data Documentation

template<typename T>
int Wt::Matrix< T >::columns_ [private]

Definition at line 293 of file matrix.h.

Referenced by Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::adjust(), Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::empty(), Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::isRowEmpty(), Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::numCols(), Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::operator()(), and Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::push_back().

template<typename T>
sigc::signal4<void, int, int, int, int> Wt::Matrix< T >::gridSizeChanged

Definition at line 230 of file matrix.h.

Referenced by Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::operator()().

template<typename T>
int Wt::Matrix< T >::rows_ [private]

Definition at line 292 of file matrix.h.

Referenced by Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::adjust(), Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::empty(), Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::isColumnEmpty(), Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::numRows(), Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::operator()(), and Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::push_back().


The documentation for this class was generated from the following file:

Generated Fri Jul 28 19:30:17 2006.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.