/* file with definitions of types to map C++ data into MatLab data
Copyright (C) 2014 Martin Sanz Sabater (martin.sanz@uv.es),
Departament d'Òptica, Universitat de València
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#ifndef CMATRIX_H
#define CMATRIX_H
class CMatrix
{
protected:
double *m_dataValues;
int m_rows, m_cols;
void printRow(int rowNum, std::ostream& os)
{
// os << "\n";
}
public:
typedef double Scalar;
CMatrix()
{
m_rows = 0;
m_cols = 0;
m_dataValues = NULL;
};
CMatrix(int rows, int cols)
{
m_rows = rows;
m_cols = cols;
m_dataValues = new double[m_rows*m_cols];
};
~CMatrix()
{
if (m_dataValues != NULL)
delete [] m_dataValues;
};
void resize(int rows, int cols)
{
if (m_dataValues != NULL)
delete [] m_dataValues;
m_rows = rows;
m_cols = cols;
m_dataValues = new double[m_rows*m_cols];
}
void set(int row, int col, double value)
{
m_dataValues[row + col*m_rows] = value;
}
size_t cols() const
{
return m_cols;
}
size_t rows() const
{
return m_rows;
}
double coeff(int row, int col) const
{
return m_dataValues[row + col*m_rows];
}
void print(std::ostream& os)
{
for (int i=0; i