30 template <
class contents>
40 int rows()
const {
return _rows; }
45 contents &
get(
int row,
int column);
46 const contents &
get(
int row,
int column)
const;
49 bool put(
int row,
int column,
const contents &to_put);
104 int compute_index(
int row,
int column)
const;
144 #undef static_class_name
145 #define static_class_name() "matrix"
148 template <
class contents>
150 :
basis::array<contents>(r*c, dat), _rows(r), _cols(c) {}
152 template <
class contents>
154 :
basis::array<contents>(0), _rows(0), _cols(0)
157 template <
class contents>
160 if (&to_copy ==
this)
return *
this;
162 _rows = to_copy._rows;
163 _cols = to_copy._cols;
167 template <
class contents>
171 template <
class contents>
175 template <
class contents>
179 template <
class contents>
183 template <
class contents>
185 {
return column + row * _cols; }
187 template <
class contents>
190 if ( (_rows == rows_in) && (_cols == columns_in) ) {
192 for (
int i = 0; i < basis::array<contents>::length(); i++)
201 this->insert(0, rows_in * columns_in);
206 template <
class contents>
209 if ( (_rows == new_rows) && (_cols == new_columns) )
return;
213 new_this[r][c] = (*
this)[r][c];
217 template <
class contents>
220 if ( (row >= rows()) || (column >= columns()) )
222 (operator [](row))[column] = to_put;
226 template <
class contents>
228 int columns_in)
const
231 submatrix(to_return, row, column, rows_in, columns_in);
235 template <
class contents>
237 int rows_in,
int columns_in)
const
240 if ( (row >= rows()) || (row + rows_in >= rows()) )
return;
241 if ( (column >= columns()) || (column + columns_in >= columns()) )
return;
242 sub.
reset(rows_in, columns_in);
243 for (
int r = row; r < row + rows_in; r++)
244 for (
int c = column; c < column + columns_in; c++)
245 sub[r - row][c - column] = (*
this)[r][c];
248 template <
class contents>
252 transpose(to_return);
256 template <
class contents>
259 resultant.
reset(columns(), rows());
260 for (
int i = 0; i < rows(); i++)
261 for (
int j = 0; j < columns(); j++)
262 resultant[j][i] = (*
this)[i][j];
265 template <
class contents>
269 if (row >= rows())
return to_return;
270 to_return.
reset(columns());
271 for (
int i = 0; i < columns(); i++)
272 to_return[i] = get(row, i);
276 template <
class contents>
280 if (column >= columns())
return to_return;
281 to_return.
reset(rows());
282 for (
int i = 0; i < rows(); i++)
283 to_return[i] = get(i, column);
287 template <
class contents>
292 const int start = compute_index(row_to_zap, 0);
303 template <
class contents>
307 bounds_halt(column_to_zap, 0, columns() - 1,
false);
310 for (
int r = rows(); r >= 0; r--) {
311 const int loc = compute_index(r, column_to_zap);
318 template <
class contents>
327 for (
int c = 0; c < columns(); c++)
328 put(position, c, contents());
332 template <
class contents>
338 for (
int r = rows(); r >= 0; r--)
342 for (
int r = 0; r < rows(); r++)
343 put(r, position, contents());
347 #undef static_class_name
Represents a sequential, ordered, contiguous collection of objects.
outcome insert(int index, int new_indices)
Adds "new_indices" new positions for objects into the array at "index".
void reset(int number=0, const contents *initial_contents=NULL_POINTER)
Resizes this array and sets the contents from an array of contents.
const contents & get(int index) const
Accesses individual objects stored in "this" at the "index" position.
const contents & operator[](int index) const
Synonym for get that provides the expected array indexing syntax.
outcome zap(int start, int end)
Deletes from "this" the objects inclusively between "start" and "end".
array & operator=(const array< contents > ©_from)
Copies the array in "copy_from" into this.
Provides a dynamically resizable ASCII character string.
A matrix of double floating point numbers.
double_matrix(int rows=0, int cols=0, double *data=NULL_POINTER)
double_matrix(const matrix< double > &to_copy)
int_matrix(const matrix< int > &to_copy)
int_matrix(int rows=0, int cols=0, int *data=NULL_POINTER)
Represents a two-dimensional array of objects.
bool zap_column(int column_to_zap)
removes a row or column from the matrix.
contents & get(int row, int column)
matrix(int rows=0, int cols=0, contents *data=NULL_POINTER)
the "data" array must have at least "rows" * "cols" contents in it.
void submatrix(matrix &sub, int row, int column, int rows, int cols) const
like submatrix() above, but stores into the "sub" parameter.
void transpose(matrix &resultant) const
stores the transpose of this matrix in "resultant".
bool insert_row(int before_row)
inserts a row before the "before_" parameter.
matrix submatrix(int row, int column, int rows, int columns) const
returns a submatrix of this one starting at "row" and "column".
bool insert_column(int before_column)
inserts a column before the "before_" parameter.
bool put(int row, int column, const contents &to_put)
stores "to_put" into the matrix at "row" and "column".
void reset(int rows=0, int columns=0)
empties the matrix and changes its size.
matrix & operator=(const matrix &to_copy)
basis::array< contents > get_row(int row)
return the vector at the "row", or an empty array if "row" is invalid.
bool zap_row(int row_to_zap)
contents * operator[](int row)
dangerous: indexes by "row" into the underlying contents.
matrix transpose() const
provides the transposed form of this matrix.
basis::array< contents > get_column(int column)
return the vector at the "column", or an empty array if it's invalid.
const contents & get(int row, int column) const
retrieves the contents from the specified "row" and "column".
void redimension(int new_rows, int new_columns)
changes the size to contain "new_rows" by "new_columns" elements.
matrix(const matrix &to_copy)
string_matrix(int rows=0, int cols=0, basis::astring *data=NULL_POINTER)
string_matrix(const matrix< basis::astring > &to_copy)
#define NULL_POINTER
The value representing a pointer to nothing.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
#define bounds_halt(value, low, high, to_return)
Verifies that "value" is between "low" and "high", inclusive.
The guards collection helps in testing preconditions and reporting errors.
type minimum(type a, type b)
maximum returns the greater of two values.
A dynamic container class that holds any kind of object via pointers.