www.pudn.com > Image_segment.rar > SubMatrix.inl
//Copyright (c) 2004-2005, Baris Sumengen //All rights reserved. // // CIMPL Matrix Performance Library // //Redistribution and use in source and binary //forms, with or without modification, are //permitted provided that the following //conditions are met: // // * No commercial use is allowed. // This software can only be used // for non-commercial purposes. This // distribution is mainly intended for // academic research and teaching. // * Redistributions of source code must // retain the above copyright notice, this // list of conditions and the following // disclaimer. // * Redistributions of binary form must // mention the above copyright notice, this // list of conditions and the following // disclaimer in a clearly visible part // in associated product manual, // readme, and web site of the redistributed // software. // * Redistributions in binary form must // reproduce the above copyright notice, // this list of conditions and the // following disclaimer in the // documentation and/or other materials // provided with the distribution. // * The name of Baris Sumengen may not be // used to endorse or promote products // derived from this software without // specific prior written permission. // //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT //HOLDERS AND CONTRIBUTORS "AS IS" AND ANY //EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT //NOT LIMITED TO, THE IMPLIED WARRANTIES OF //MERCHANTABILITY AND FITNESS FOR A PARTICULAR //PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE //CONTRIBUTORS BE LIABLE FOR ANY //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, //EXEMPLARY, OR CONSEQUENTIAL DAMAGES //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT //OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, //DATA, OR PROFITS; OR BUSINESS INTERRUPTION) //HOWEVER CAUSED AND ON ANY THEORY OF //LIABILITY, WHETHER IN CONTRACT, STRICT //LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR //OTHERWISE) ARISING IN ANY WAY OUT OF THE USE //OF THIS SOFTWARE, EVEN IF ADVISED OF THE //POSSIBILITY OF SUCH DAMAGE. template< class T > SubMatrix::SubMatrix(void) { xDim = 0; yDim = 0; columns = 0; clean = 0; } template< class T > SubMatrix ::SubMatrix(SubMatrix &m) { xDim = m.xDim; yDim = m.yDim; columns = m.columns; clean = new (std::nothrow) Cleaner (columns); Utility::CheckPointer(clean); } template< class T > SubMatrix ::~SubMatrix(void) { if(clean != 0) { delete clean; } } template< class T > inline const int SubMatrix ::Columns() const { return xDim; } template< class T > inline const int SubMatrix ::Rows() const { return yDim; } template< class T > inline const int SubMatrix ::XDim() const { return xDim; } template< class T > inline const int SubMatrix ::YDim() const { return yDim; } template< class T > SubMatrix & SubMatrix ::operator= (T init) { for(int i=0;i SubMatrix & SubMatrix ::operator= (SubMatrix & m) { if(&m != this) { if(xDim != m.xDim || yDim != m.yDim) { cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl; Utility::RunTimeError("(Sub)Matrices must be same size for the assignment!"); } for(int i=0;i SubMatrix & SubMatrix ::operator= (Matrix & m) { if(xDim != m.xDim || yDim != m.yDim) { cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl; Utility::RunTimeError("(Sub)Matrices must be same size for the assignment!"); } for(int i=0;i inline T& SubMatrix ::operator() (const int j, const int i) { #ifdef CIMPL_BOUNDS_CHECK if(i<0 || i>=xDim || j<0 || j>=yDim) { cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl; Utility::RunTimeError("Index outside bounds!"); } #endif return columns[i][j]; } template< class T > inline Vector & SubMatrix ::operator[] (const int i) { return columns[i]; }