SubMatrix.inl

Go to the documentation of this file.
00001 //Copyright (c) 2004-2005, Baris Sumengen
00002 //All rights reserved.
00003 //
00004 // CIMPL Matrix Performance Library
00005 //
00006 //Redistribution and use in source and binary
00007 //forms, with or without modification, are
00008 //permitted provided that the following
00009 //conditions are met:
00010 //
00011 //    * No commercial use is allowed. 
00012 //    This software can only be used
00013 //    for non-commercial purposes. This 
00014 //    distribution is mainly intended for
00015 //    academic research and teaching.
00016 //    * Redistributions of source code must
00017 //    retain the above copyright notice, this
00018 //    list of conditions and the following
00019 //    disclaimer.
00020 //    * Redistributions of binary form must
00021 //    mention the above copyright notice, this
00022 //    list of conditions and the following
00023 //    disclaimer in a clearly visible part 
00024 //    in associated product manual, 
00025 //    readme, and web site of the redistributed 
00026 //    software.
00027 //    * Redistributions in binary form must
00028 //    reproduce the above copyright notice,
00029 //    this list of conditions and the
00030 //    following disclaimer in the
00031 //    documentation and/or other materials
00032 //    provided with the distribution.
00033 //    * The name of Baris Sumengen may not be
00034 //    used to endorse or promote products
00035 //    derived from this software without
00036 //    specific prior written permission.
00037 //
00038 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
00039 //HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
00040 //EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
00041 //NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00042 //MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00043 //PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00044 //CONTRIBUTORS BE LIABLE FOR ANY
00045 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00046 //EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00047 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00048 //OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00049 //DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00050 //HOWEVER CAUSED AND ON ANY THEORY OF
00051 //LIABILITY, WHETHER IN CONTRACT, STRICT
00052 //LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00053 //OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00054 //OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00055 //POSSIBILITY OF SUCH DAMAGE.
00056 
00057 
00058 namespace CIMPL
00059 {
00060 
00061 
00062 template< class T >
00063 SubMatrix<T>::SubMatrix(void)
00064 {
00065         xDim = 0;
00066         yDim = 0;
00067         columns = 0;
00068         clean = 0;
00069 }
00070 
00071 
00072 template< class T >
00073 SubMatrix<T>::SubMatrix(SubMatrix<T> &m) 
00074 {
00075         xDim = m.xDim;
00076         yDim = m.yDim;
00077         columns = m.columns;
00078         clean = new (std::nothrow) Cleaner<T>(columns);
00079         Utility::CheckPointer(clean);
00080 
00081 }
00082 
00083 
00084 
00085 
00086 template< class T >
00087 SubMatrix<T>::~SubMatrix(void)
00088 {
00089         
00090         if(clean != 0)
00091         {
00092                 delete clean;
00093         }
00094 
00095 }
00096 
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 template< class T >
00106 inline const int SubMatrix<T>::Columns() const
00107 {
00108         return xDim;
00109 }
00110 
00111 template< class T >
00112 inline const int SubMatrix<T>::Rows() const
00113 {
00114         return yDim;
00115 }
00116 
00117 
00118 template< class T >
00119 inline const int SubMatrix<T>::XDim() const
00120 {
00121         return xDim;
00122 }
00123 
00124 template< class T >
00125 inline const int SubMatrix<T>::YDim() const
00126 {
00127         return yDim;
00128 }
00129 
00130 
00131 
00132 template< class T >
00133 SubMatrix<T>& SubMatrix<T>::operator= (SubMatrix<T>& m)
00134 {
00135         if(xDim != m.xDim || yDim != m.yDim)
00136         {
00137                 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00138                 Utility::RunTimeError("(Sub)Matrices must be same size for the assignment!");
00139         }
00140         for(int i=0;i<m.xDim;i++)
00141         {
00142                 for(int j=0;j<m.yDim;j++)
00143                 {
00144                         columns[i][j] = m.columns[i][j];
00145                 }
00146         }
00147 
00148         return *this;
00149 }
00150 
00151 template< class T >
00152 SubMatrix<T>& SubMatrix<T>::operator= (Matrix<T>& m)
00153 {
00154         if(xDim != m.xDim || yDim != m.yDim)
00155         {
00156                 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00157                 Utility::RunTimeError("(Sub)Matrices must be same size for the assignment!");
00158         }
00159         for(int i=0;i<m.xDim;i++)
00160         {
00161                 for(int j=0;j<m.yDim;j++)
00162                 {
00163                         columns[i][j] = m.ElemNC(j,i);
00164                 }
00165         }
00166         
00167         
00168         return *this;
00169 }
00170 
00171 
00172 
00173 template< class T >
00174 inline T& SubMatrix<T>::operator() (const int j, const int i)
00175 {
00176         if(i<0 || i>=xDim || j<0 || j>=yDim)
00177         {
00178                 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00179                 Utility::RunTimeError("Index outside bounds!");
00180         }
00181 
00182         return columns[i][j];
00183 
00184 }
00185 
00186 template< class T >
00187 inline Vector<T>& SubMatrix<T>::operator[] (const int i)
00188 {
00189         return columns[i];
00190 }
00191 
00192 // more complete treatment of submatrix.
00193 
00194 
00195 
00196 
00197 }; //namespace
00198 
00199 
00200 
00201 
00202 

Generated on Thu Jan 20 08:43:45 2005 for CIMPL by  doxygen 1.3.9.1