matrix.h

Go to the documentation of this file.
00001 #ifndef MATRIX_CLASS
00002 #define MATRIX_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : matrix                                                            *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1993-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include <basis/array.h>
00019 
00021 
00025 template <class contents>
00026 class matrix : protected array<contents>
00027 {
00028 public:
00029   matrix(int rows = 0, int cols = 0, contents *data = NIL);
00031   matrix(const matrix &to_copy);
00032 
00033   inline ~matrix() {}
00034 
00035   inline int rows() const { return _rows; }
00036   inline int columns() const { return _cols; }
00037 
00038   matrix &operator = (const matrix &to_copy);
00039 
00040   contents &get(int row, int column);
00041   const contents &get(int row, int column) const;
00043 
00044   bool put(int row, int column, const contents &to_put);
00046 
00047   contents *operator[] (int row);
00049 
00054   const contents *operator[] (int row) const;
00056 
00057   matrix submatrix(int row, int column, int rows, int columns) const;
00059 
00061   void submatrix(matrix &sub, int row, int column, int rows, int cols) const;
00063 
00064   matrix transpose() const;
00066   void transpose(matrix &resultant) const;
00068 
00069   array<contents> get_row(int row);
00071   array<contents> get_column(int column);
00073 
00074   bool insert_row(int before_row);
00076 
00078   bool insert_column(int before_column);
00080 
00081   void reset(int rows = 0, int columns = 0);
00083 
00084   void redimension(int new_rows, int new_columns);
00086 
00089   bool zap_row(int row_to_zap);
00090   bool zap_column(int column_to_zap);
00092 
00095 private:
00096   int _rows;  
00097   int _cols;  
00098 
00099   int compute_index(int row, int column) const;
00101 };
00102 
00104 
00106 class int_matrix : public matrix<int>
00107 {
00108 public:
00109   int_matrix(int rows = 0, int cols = 0, int *data = NIL)
00110       : matrix<int>(rows, cols, data) {}
00111   int_matrix(const matrix<int> &to_copy) : matrix<int>(to_copy) {}
00112 };
00113 
00115 class string_matrix : public matrix<istring>
00116 {
00117 public:
00118   string_matrix(int rows = 0, int cols = 0, istring *data = NIL)
00119       : matrix<istring>(rows, cols, data) {}
00120   string_matrix(const matrix<istring> &to_copy) : matrix<istring>(to_copy) {}
00121 };
00122 
00124 class double_matrix : public matrix<double>
00125 {
00126 public:
00127   double_matrix(int rows = 0, int cols = 0, double *data = NIL)
00128       : matrix<double>(rows, cols, data) {}
00129   double_matrix(const matrix<double> &to_copy) : matrix<double>(to_copy) {}
00130 };
00131 
00132 #endif
00133 

Generated on Fri Nov 28 04:29:12 2008 for HOOPLE Libraries by  doxygen 1.5.1