2 matrix.hh -- declare and implement 2d arrays
4 source file of the Flower Library
6 (c) 2006--2007 Joe Neeman <joeneeman@gmail.com>
12 #include "std-vector.hh"
14 template<class T, class A=std::allocator<T> >
23 Matrix<T, A> (vsize rows, vsize columns, T const &t)
24 : data_(rows * columns, t)
29 const T &at (vsize row, vsize col) const
31 assert (row < rank_ && col * rank_ + row < data_.size ());
33 return data_[col * rank_ + row];
36 T &at (vsize row, vsize col)
38 assert (row < rank_ && col * rank_ + row < data_.size ());
40 return data_[col * rank_ + row];
43 void resize (vsize rows, vsize columns, T const &t)
46 data_.resize (rows * columns, t);
50 new_data.resize (rows * columns, t);
51 vsize cur_cols = rank_ ? data_.size () / rank_: 0;
53 for (vsize i = 0; i < cur_cols; i++)
54 for (vsize j = 0; j < rank_; j++)
55 new_data[i*rows + j] = data_[i*rank_ + j];
66 #endif /* MATRIX_HH */