MatrixList.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 
00059 namespace CIMPL
00060 {
00061 
00062 
00063 
00064 template< class T >
00065 MatrixList<T>::MatrixList(void)
00066 {
00067         planes = 0;
00068         xDim = 0;
00069         yDim = 0;
00070         list = 0;
00071 }
00072 
00073 
00074 template< class T >
00075 MatrixList<T>::MatrixList(MatrixList<T>& ml)
00076 {
00077         planes = ml.planes;
00078         xDim = ml.xDim;
00079         yDim = ml.yDim;
00080         list = new (std::nothrow) Matrix<T>[ml.planes];
00081         Utility::CheckPointer(list);
00082         for(int i=0; i<planes; i++)
00083         {
00084                 list[i] = ml.list[i];
00085         }
00086 }
00087 
00088 template< class T >
00089 MatrixList<T>::MatrixList(Matrix<T>& m)
00090 {
00091         planes = 1;
00092         list = new (std::nothrow) Matrix<T>[1];
00093         Utility::CheckPointer(list);
00094         xDim = m.Columns();
00095         yDim = m.Rows();
00096         list[0] = m;
00097 }
00098 
00099 
00100 template< class T >
00101 MatrixList<T>::MatrixList(Matrix<T>& m1, Matrix<T>& m2, Matrix<T>& m3)
00102 {
00103         if(m1.Rows() != m2.Rows() || m1.Rows() != m3.Rows() || m2.Rows() != m3.Rows() || m1.Columns() != m2.Columns() || m1.Columns() != m3.Columns() || m2.Columns() != m3.Columns())
00104         {
00105                 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00106                 Utility::RunTimeError("Matrix dimensions does not match to each other!");
00107         }
00108         planes = 3;
00109         list = new (std::nothrow) Matrix<T>[3];
00110         Utility::CheckPointer(list);
00111         xDim = m1.Columns();
00112         yDim = m1.Rows();
00113         list[0] = m1;
00114         list[1] = m2;
00115         list[2] = m3;
00116 }
00117 
00118 
00119 template< class T >
00120 MatrixList<T>::MatrixList(int l, int rows, int cols)
00121 {
00122         planes = l;
00123         xDim = cols;
00124         yDim = rows;
00125         
00126         list = new (std::nothrow) Matrix<T>[l];
00127         Utility::CheckPointer(list);
00128         
00129         for(int i=0; i<l; i++)
00130         {
00131                 list[i] = Matrix<T>(rows, cols);
00132         }
00133 }
00134 
00135 
00136 template< class T >
00137 MatrixList<T>::~MatrixList(void)
00138 {
00139         delete [] list;
00140 }
00141 
00142 
00143 template< class T >
00144 void MatrixList<T>::PushBack(Matrix<T>& m)
00145 {
00146         if(list ==0)
00147         {
00148                 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00149                 Utility::RunTimeError("MatrixList needs to be initialized first before appending new matrices!");
00150         }
00151         if(m.Rows() != yDim || m.Columns() != xDim)
00152         {
00153                 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00154                 Utility::RunTimeError("Matrix dimensions does not match to MatrixList!");
00155         }
00156         
00157         Matrix<T> *temp = new (std::nothrow) Matrix<T>[planes+1];
00158         Utility::CheckPointer(temp);
00159         for(int i=0;i<planes;i++)
00160         {
00161                 temp[i] = list[i];
00162         }
00163         temp[planes] = m;
00164         planes++;
00165         delete [] list;
00166         list = temp;
00167 }
00168 
00169 
00170 template< class T >
00171 void MatrixList<T>::PushFront(Matrix<T>& m)
00172 {
00173         if(list ==0)
00174         {
00175                 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00176                 Utility::RunTimeError("MatrixList needs to be initialized first before appending new matrices!");
00177         }
00178         if(m.Rows() != yDim || m.Columns() != xDim)
00179         {
00180                 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00181                 Utility::RunTimeError("Matrix dimensions does not match to MatrixList!");
00182         }
00183         
00184         Matrix<T> *temp = new (std::nothrow) Matrix<T>[planes+1];
00185         Utility::CheckPointer(temp);
00186         for(int i=0;i<planes;i++)
00187         {
00188                 temp[i+1] = list[i];
00189         }
00190         temp[0] = m;
00191         planes++;
00192         delete [] list;
00193         list = temp;
00194 }
00195 
00196 
00197 
00198 template< class T >
00199 int MatrixList<T>::Planes() const
00200 {
00201         return planes;
00202 }
00203 
00204 template< class T >
00205 int MatrixList<T>::Rows() const
00206 {
00207         return yDim;
00208 }
00209 
00210 template< class T >
00211 int MatrixList<T>::Columns() const
00212 {
00213         return xDim;
00214 }
00215 
00216 
00217 template< class T >
00218 int MatrixList<T>::XDim() const
00219 {
00220         return xDim;
00221 }
00222 
00223 template< class T >
00224 int MatrixList<T>::YDim() const
00225 {
00226         return yDim;
00227 }
00228 
00229 
00230 template< class T >
00231 MatrixList<T>& MatrixList<T>::operator= (MatrixList<T>& ml)
00232 {
00233         planes = ml.planes;
00234         xDim = ml.xDim;
00235         yDim = ml.yDim;
00236         
00237         delete [] list;
00238         list = new (std::nothrow) Matrix<T>[ml.planes];
00239         Utility::CheckPointer(list);
00240         for(int i=0; i<planes; i++)
00241         {
00242                 list[i] = ml.list[i];
00243         }
00244         
00245         return *this;
00246 }
00247 
00248 
00249 
00250 template< class T >
00251 Matrix<T>& MatrixList<T>::operator[] (const int i)
00252 {
00253         return list[i];
00254 }
00255 
00256 
00257 
00258 template< class T >
00259 Matrix<T>& MatrixList<T>::operator() (const int i)
00260 {
00261         if(i<0 || i>=planes)
00262         {
00263                 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00264                 Utility::RunTimeError("Index outside bounds!");
00265         }
00266         return list[i];
00267 }
00268 
00269 
00270 
00271 
00272 
00273 
00274 };
00275 
00276 

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