#ifndef MATRIX_H #define MATRIX_H #include #include #include "range.h" #include "matrix_proxy.h" #include "matrix_expression.h" /***************************************************** * matrix class ****************************************************/ class matrix : public matrix_expression { private: int _nr; /* number of rows */ int _nc; /* number of columns */ std::vector _data; /* underlying data storage */ public: matrix(int numRows=0, int numColumns=0, double value=0); // copy constructor based on an existing matrix_expression matrix(const matrix_expression& m); // Returns the number of rows int numRows() const; // Returns the number of columns int numColumns() const; // Change the apparent size of this matrix. // Overall number of elements must be preserved. void reshape(int r, int c); // we need following declaration to properly inherit the version of // operator() for ranges. Then we can define our additional ones. using matrix_expression::operator(); // Provides read-only access via indexing operator double operator()(int r, int c) const; // Provides write-access through indexing operator double& operator()(int r, int c); // assignment operator based on existing matrix_expression. // Note: current matrix will be resized if necessary matrix& operator=(const matrix_expression& m); matrix& operator=(const matrix& other); }; //------------------------------------------------------ // define additional support for reading a matrix //------------------------------------------------------ std::istream& operator>>(std::istream& in, matrix& m); #endif