OpenFOAM logo
Open Source CFD Toolkit

MatrixI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "error.H"
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00035 
00036 template<class T>
00037 inline Matrix<T>::Matrix()
00038 :
00039     n_(0),
00040     m_(0),
00041     v_(NULL)
00042 {}
00043 
00044 
00045 template<class T>
00046 inline autoPtr<Matrix<T> > Matrix<T>::clone() const
00047 {
00048     return autoPtr<Matrix<T> >(new Matrix<T>(*this));
00049 }
00050 
00051 
00052 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00053             //- Return the number of rows
00054 template<class T>
00055 inline label Matrix<T>::n() const
00056 {
00057     return n_;
00058 }
00059 
00060 
00061 //- Return the number of columns
00062 template<class T>
00063 inline label Matrix<T>::m() const
00064 {
00065     return m_;
00066 }
00067 
00068 
00069 //- Return the number of columns
00070 template<class T>
00071 inline label Matrix<T>::size() const
00072 {
00073     return n_*m_;
00074 }
00075 
00076 
00077 // Check index i is within valid range (0 ... n-1).
00078 template<class T>
00079 inline void Matrix<T>::checki(const label i) const
00080 {
00081     if (!n_)
00082     {
00083         FatalErrorIn("Matrix<T>::checki(const label)")
00084             << "attempt to access element from zero sized row"
00085             << abort(FatalError);
00086     }
00087     else if (i<0 || i>=n_)
00088     {
00089         FatalErrorIn("Matrix<T>::checki(const label)")
00090             << "index " << i << " out of range 0 ... " << n_-1
00091             << abort(FatalError);
00092     }
00093 }
00094 
00095 
00096 // Check index j is within valid range (0 ... n-1).
00097 template<class T>
00098 inline void Matrix<T>::checkj(const label j) const
00099 {
00100     if (!m_)
00101     {
00102         FatalErrorIn("Matrix<T>::checkj(const label)")
00103             << "attempt to access element from zero sized column"
00104             << abort(FatalError);
00105     }
00106     else if (j<0 || j>=m_)
00107     {
00108         FatalErrorIn("Matrix<T>::checkj(const label)")
00109             << "index " << j << " out of range 0 ... " << m_-1
00110             << abort(FatalError);
00111     }
00112 }
00113 
00114 
00115 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00116 
00117 // Return subscript-checked element access
00118 template<class T>
00119 inline T* Matrix<T>::operator[](const label i)
00120 {
00121 #   ifdef FULLDEBUG
00122     checki(i);
00123 #   endif
00124     return v_[i];
00125 }
00126 
00127 
00128 // Return subscript-checked const element access
00129 template<class T>
00130 inline const T* Matrix<T>::operator[](const label i) const
00131 {
00132 #   ifdef FULLDEBUG
00133     checki(i);
00134 #   endif
00135     return v_[i];
00136 }
00137 
00138 
00139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00140 
00141 } // End namespace Foam
00142 
00143 // ************************************************************************* //
For further information go to www.openfoam.org