00001
00002
00003
00004
00005
00006
00007
00008 #ifndef QAF_UTIL_MATRIX_H
00009 #define QAF_UTIL_MATRIX_H
00010
00011 #include <stdexcept>
00012
00013 namespace qaf {
00014
00018 template <typename T>
00019 class Matrix {
00020 public:
00024 const int rows, columns;
00025
00026
00031 Matrix ( int _rows, int _columns ) : rows(_rows), columns(_columns) {
00032 data = new T[rows * columns * sizeof(T)];
00033 }
00034
00038 Matrix ( Matrix<T> & orig ) : rows(orig.rows), columns(orig.columns) {
00039 data = new T[rows * columns * sizeof(T)];
00040
00041 for ( int i = 0; i < rows; i++ )
00042 for ( int j = 0; j < columns; j++ )
00043 data[i * columns + j] = orig.data[i * columns + j];
00044 }
00045
00053 inline T & cell ( int row, int column ) const {
00054
00055 if ( row < 0 || row >= rows || column < 0 || column >= columns )
00056 throw std::out_of_range("Matrix index out of range");
00057
00058 return data[row * columns + column];
00059 }
00060
00061
00066 virtual ~Matrix () {
00067 delete[] data;
00068 }
00069
00070 private:
00071 T * data;
00072 };
00073
00074 }
00075
00076
00077
00078 #endif