#include <matrix.h>
Inheritance diagram for Wt::Matrix< T >:
Public Types | |
typedef std::vector< T > | Edge |
typedef std::vector< Edge > | MatrixBase |
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 |
Definition at line 30 of file matrix.h.
typedef std::vector<T> Wt::Matrix< T >::Edge |
typedef std::vector<Edge> Wt::Matrix< T >::MatrixBase |
typedef T Wt::Matrix< T >::value_type |
Wt::Matrix< T >::Matrix | ( | ) | [inline] |
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 }
const_iterator Wt::Matrix< T >::begin | ( | ) | const [inline] |
iterator Wt::Matrix< T >::begin | ( | ) | [inline] |
Definition at line 126 of file matrix.h.
Referenced by Wt::Matrix< Wt::LayoutItemCompound< MatrixLayoutItemValue > >::remove().
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().
const_iterator Wt::Matrix< T >::end | ( | ) | const [inline] |
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().
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 }
iterator Wt::Matrix< T >::find | ( | iterator | start, | |
iterator | finish, | |||
const T & | t | |||
) | const [inline] |
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 }
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 }
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 }
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 }
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 }
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 }
void Wt::Matrix< T >::remove | ( | const T & | t | ) | [inline] |
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().
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()().
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().
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.