fixed_square_matrix.h
00001 /* Copyright (C) 2003-2005  Martin Förg
00002 
00003  * This library is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU Lesser General Public
00005  * License as published by the Free Software Foundation; either
00006  * version 2.1 of the License, or (at your option) any later version.
00007  * 
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * Lesser General Public License for more details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public
00014  * License along with this library; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00016  *
00017  * Contact:
00018  *   martin.o.foerg@googlemail.com
00019  *
00020  */
00021 
00022 #ifndef fixed_square_matrix_h
00023 #define fixed_square_matrix_h
00024 
00025 #include "fixed_general_matrix.h"
00026 
00027 namespace fmatvec {
00028 
00038   template <int M, class AT> class SquareMatrix<Fixed<M>,AT> : public Matrix<General,Fixed<M>,Fixed<M>,AT> {
00039 
00040     public:
00041 
00042 //      template<class Ini=All<AT> >
00043 //      SquareMatrix(Ini ini=All<AT>()) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini) { }
00044 //      template<class Ini=All<AT> >
00045 //      SquareMatrix(int m, Ini ini=All<AT>()) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini) { } 
00046 
00047       SquareMatrix(Noinit ini) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini) { }
00048       SquareMatrix(Init ini=INIT, const AT &a=0) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini,a) { }
00049       SquareMatrix(Eye ini, const AT &a=1) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini,a) { }
00050       SquareMatrix(int m, Noinit ini) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini) { }
00051       SquareMatrix(int m, Init ini=INIT, const AT &a=0) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini,a) { }
00052       SquareMatrix(int m, Eye ini, const AT &a=1) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini,a) { }
00053 
00054       SquareMatrix(const char *str) : Matrix<General,Fixed<M>,Fixed<M>,AT>(str) { }
00055 
00060       template<class Type, class Row, class Col>
00061       explicit SquareMatrix(const Matrix<Type,Row,Col,AT>&  A) : Matrix<General,Fixed<M>,Fixed<M>,AT>(A) {
00062       }
00063 
00064       template<class Row>
00065       SquareMatrix(const SquareMatrix<Row,AT> &A) : Matrix<General,Fixed<M>,Fixed<M>,AT>(A) {
00066       }
00067 
00074       template <class Type, class Row, class Col> SquareMatrix<Fixed<M>,AT>& operator=(const Matrix<Type,Row,Col,AT> &A) {
00075         Matrix<General,Fixed<M>,Fixed<M>,AT>::operator=(A);
00076         return *this;
00077       }
00078 
00083       int size() const {return M;};
00084 
00085       using Matrix<General,Fixed<M>,Fixed<M>,AT>::operator();
00086       using Matrix<General,Fixed<M>,Fixed<M>,AT>::e;
00087 
00092       inline operator std::vector<std::vector<AT> >();
00093 
00094       inline const SquareMatrix<Fixed<M>,AT> T() const;
00095 
00096   };
00097 
00098   template <int M, class AT>
00099     inline const SquareMatrix<Fixed<M>,AT> SquareMatrix<Fixed<M>,AT>::T() const {
00100       SquareMatrix<Fixed<M>,AT> A(NONINIT);
00101       for(int i=0; i<M; i++)
00102         for(int j=0; j<M; j++)
00103           A.e(i,j) = e(j,i);
00104       return A;
00105     }
00106 
00107   template <int M, class AT>
00108     inline SquareMatrix<Fixed<M>,AT>::operator std::vector<std::vector<AT> >() {
00109       std::vector<std::vector<AT> > ret(size());
00110       for(int r=0; r<size(); r++) {
00111         ret[r].resize(size());
00112         for(int c=0; c<size(); c++)
00113           ret[r][c]= e(r,c);
00114       }
00115       return ret;
00116     }
00117 
00118 }
00119 
00120 #endif