OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

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-2007 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 
00054 //- Return the number of rows
00055 template<class T>
00056 inline label Matrix<T>::n() const
00057 {
00058     return n_;
00059 }
00060 
00061 
00062 //- Return the number of columns
00063 template<class T>
00064 inline label Matrix<T>::m() const
00065 {
00066     return m_;
00067 }
00068 
00069 
00070 //- Return the number of columns
00071 template<class T>
00072 inline label Matrix<T>::size() const
00073 {
00074     return n_*m_;
00075 }
00076 
00077 
00078 // Check index i is within valid range (0 ... n-1).
00079 template<class T>
00080 inline void Matrix<T>::checki(const label i) const
00081 {
00082     if (!n_)
00083     {
00084         FatalErrorIn("Matrix<T>::checki(const label)")
00085             << "attempt to access element from zero sized row"
00086             << abort(FatalError);
00087     }
00088     else if (i<0 || i>=n_)
00089     {
00090         FatalErrorIn("Matrix<T>::checki(const label)")
00091             << "index " << i << " out of range 0 ... " << n_-1
00092             << abort(FatalError);
00093     }
00094 }
00095 
00096 
00097 // Check index j is within valid range (0 ... n-1).
00098 template<class T>
00099 inline void Matrix<T>::checkj(const label j) const
00100 {
00101     if (!m_)
00102     {
00103         FatalErrorIn("Matrix<T>::checkj(const label)")
00104             << "attempt to access element from zero sized column"
00105             << abort(FatalError);
00106     }
00107     else if (j<0 || j>=m_)
00108     {
00109         FatalErrorIn("Matrix<T>::checkj(const label)")
00110             << "index " << j << " out of range 0 ... " << m_-1
00111             << abort(FatalError);
00112     }
00113 }
00114 
00115 
00116 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00117 
00118 // Return subscript-checked element access
00119 template<class T>
00120 inline T* Matrix<T>::operator[](const label i)
00121 {
00122 #   ifdef FULLDEBUG
00123     checki(i);
00124 #   endif
00125     return v_[i];
00126 }
00127 
00128 
00129 // Return subscript-checked const element access
00130 template<class T>
00131 inline const T* Matrix<T>::operator[](const label i) const
00132 {
00133 #   ifdef FULLDEBUG
00134     checki(i);
00135 #   endif
00136     return v_[i];
00137 }
00138 
00139 
00140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00141 
00142 } // End namespace Foam
00143 
00144 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd