File indexing completed on 2024-04-28 03:40:44

0001 /*************************************************************************************
0002  *  Copyright (C) 2013 by Aleix Pol <aleixpol@kde.org>                               *
0003  *  Copyright (C) 2014 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com>      *
0004  *                                                                                   *
0005  *  This program is free software; you can redistribute it and/or                    *
0006  *  modify it under the terms of the GNU General Public License                      *
0007  *  as published by the Free Software Foundation; either version 2                   *
0008  *  of the License, or (at your option) any later version.                           *
0009  *                                                                                   *
0010  *  This program is distributed in the hope that it will be useful,                  *
0011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
0012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                    *
0013  *  GNU General Public License for more details.                                     *
0014  *                                                                                   *
0015  *  You should have received a copy of the GNU General Public License                *
0016  *  along with this program; if not, write to the Free Software                      *
0017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
0018 *************************************************************************************/
0019 
0020 #ifndef MATRIX_H
0021 #define MATRIX_H
0022 
0023 #include "object.h"
0024 #include "vector.h"
0025 
0026 namespace Analitza {
0027 
0028 class Cn;
0029 
0030 class Vector;
0031 
0032 class ANALITZA_EXPORT MatrixRow : public Vector
0033 {
0034     public:
0035         explicit MatrixRow(int size=0);
0036         virtual QVariant accept(AbstractExpressionVisitor* e) const override;
0037         
0038         MatrixRow* copy() const override;
0039 };
0040 
0041 class ANALITZA_EXPORT Matrix : public Object
0042 {
0043     public:
0044         typedef QList<MatrixRow*>::iterator iterator;
0045         typedef QList<MatrixRow*>::const_iterator const_iterator;
0046         
0047         Matrix();
0048         /** Fills the matrix with a fixed numeric @p value, the matrix size will be @p m x @p n */
0049         Matrix(int m, int n, const Cn *value);
0050         ~Matrix() override;
0051         void appendBranch(MatrixRow* o);
0052         
0053         virtual Matrix* copy() const override;
0054         virtual bool matches(const Object* exp, QMap< QString, const Object* >* found) const override;
0055         virtual QVariant accept(AbstractExpressionVisitor* exp) const override;
0056         const_iterator constBegin() const { return m_rows.constBegin(); }
0057         const_iterator constEnd() const { return m_rows.constEnd(); }
0058         iterator begin() { return m_rows.begin(); }
0059         iterator end() { return m_rows.end(); }
0060         QList< MatrixRow* > rows() const { return m_rows; }
0061         bool operator==(const Matrix& m) const;
0062         int rowCount() const { return m_rows.size(); }
0063         Analitza::Matrix::iterator erase(const Analitza::Matrix::iterator& it) { return m_rows.erase(it); }
0064         Object* at(int i, int j) const;
0065         int columnCount() const;
0066         bool isSquare() const;
0067         virtual bool isZero() const override;
0068         bool hasOnlyNumbers() const { return m_rows.isEmpty()? false : m_hasOnlyNumbers; }
0069         bool isIdentity() const;
0070         bool isDiagonal() const;
0071         
0072     public:
0073         static Matrix* identity(int n);
0074         
0075     private:
0076         QList<MatrixRow*> m_rows;
0077         bool m_hasOnlyNumbers;
0078 };
0079 
0080 }
0081 
0082 #endif // MATRIX_H