|
STK++ 1.0
|
00001 /*--------------------------------------------------------------------*/ 00002 /* Copyright (C) 2004-2007 Serge Iovleff 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU Lesser General Public License as 00006 published by the Free Software Foundation; either version 2 of the 00007 License, or (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public 00015 License along with this program; if not, write to the 00016 Free Software Foundation, Inc., 00017 59 Temple Place, 00018 Suite 330, 00019 Boston, MA 02111-1307 00020 USA 00021 00022 Contact : Serge.Iovleff@stkpp.org 00023 */ 00024 00025 /* 00026 * Project: stkpp::Arrays 00027 * Purpose: Define the MatrixSquare class. 00028 * Author: Serge Iovleff, serge.iovleff@stkpp.org 00029 * 00030 **/ 00031 00036 #ifndef STK_MATRIXSQUARE_H 00037 #define STK_MATRIXSQUARE_H 00038 00039 #include "STK_Matrix.h" 00040 00041 namespace STK 00042 { 00043 00044 class MatrixSquare; 00045 00050 template<> 00051 struct ContainerTraits<Real, MatrixSquare > 00052 { 00053 typedef Point TContainerHo; 00054 typedef Vector TContainerVe; 00055 }; 00056 00057 00067 class MatrixSquare : public Matrix 00068 { 00069 public: 00073 MatrixSquare( Range const& I = Range()); 00074 00080 MatrixSquare( Range const& I, Real const& v); 00081 00086 MatrixSquare( MatrixSquare const&T, bool ref=false); 00087 00092 MatrixSquare( Matrix const& T, Range const& I); 00093 00095 virtual ~MatrixSquare(); 00096 00100 inline Range const& range() const 00101 { return rangeVe();} 00102 00106 inline Integer const& first() const 00107 { return firstCol();} 00108 00112 inline Integer const& last() const 00113 { return lastCol();} 00114 00118 inline MatrixSquare sub(Range const& I) const 00119 { return MatrixSquare(*this, I);} 00120 00124 inline void shift(Integer beg) 00125 { Matrix::shift(beg, beg);} 00126 00130 inline void resize( Range const& I =Range()) 00131 { Matrix::resize(I, I);} 00132 00137 inline void insert( Integer const& pos, Integer const& n =1) 00138 { 00139 Matrix::insertRows(pos, n); 00140 Matrix::insertCols(pos, n); 00141 } 00142 00148 inline void erase( Integer const& pos, Integer const& n=1) 00149 { 00150 Matrix::eraseCols(pos, n); 00151 Matrix::eraseRows(pos, n); 00152 } 00153 00157 inline void pushBack(Integer n=1) 00158 { 00159 Matrix::pushBackRows(n); 00160 Matrix::pushBackCols(n); 00161 } 00162 00166 inline void popBack(Integer const& n=1) 00167 { 00168 Matrix::popBackCols(n); 00169 Matrix::popBackRows(n); 00170 } 00171 00178 inline MatrixSquare& operator=( MatrixSquare const& T) 00179 { 00180 Matrix *p1(this); // convert this to Array2D 00181 const Matrix *p2(&T); // convert T to Array2D 00182 (*p1) = (*p2); // use = of Array2D class 00183 00184 return *this; 00185 } 00186 00190 inline MatrixSquare& operator=(Real const& v) 00191 { 00192 Matrix *p1(this); // convert this to Array2D 00193 (*p1) = v; // use = of Array2D class 00194 00195 return *this; 00196 } 00197 00204 template < class TContainer2D> 00205 inline MatrixSquare& operator=( ITArray2D< Real, TContainer2D> const& T) 00206 { 00207 if (T.rangeVe() != T.rangeHo()) 00208 { throw runtime_error("MatrixSquare::operator=(T) " 00209 "dimensions of T are not square."); 00210 } 00211 // use Matrix = operator 00212 Matrix *p1(this); // convert this to Matrix 00213 (*p1) = T; // use = of Matrix class 00214 return *this; 00215 } 00216 00217 private: 00223 inline void resize( Range const& I, Range const& J) 00224 { 00225 if (I != J) 00226 { throw runtime_error("MatrixSquare::resize(I, J) " 00227 "I != J"); 00228 } 00229 Matrix::resize(I, J); 00230 } 00231 00237 inline void shift(Integer rbeg, Integer cbeg) 00238 { 00239 if (rbeg != cbeg) 00240 { throw runtime_error("MatrixSquare::shift(rbeg, cbeg) " 00241 "rbeg != cbeg"); 00242 } 00243 Matrix::shift(rbeg, cbeg); 00244 } 00245 00246 00247 00248 }; 00249 00250 } // namespace STK 00251 00252 00253 #endif 00254 // STK_MATRIXSQUARE_H