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

CompactListListI.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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00028 
00029 namespace Foam
00030 {
00031 
00032 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00033 
00034 template<class T>
00035 inline CompactListList<T>::CompactListList()
00036 {}
00037 
00038 
00039 template<class T>
00040 inline CompactListList<T>::CompactListList(const label nRows, const label nData)
00041 :
00042     offsets_(nRows, 0),
00043     m_(nData)
00044 {}
00045 
00046 
00047 template<class T>
00048 inline CompactListList<T>::CompactListList
00049 (
00050     const label nRows,
00051     const label nData,
00052     const T& t
00053 )
00054 :
00055     offsets_(nRows, 0),
00056     m_(nData, t)
00057 {}
00058 
00059 
00060 template<class T>
00061 inline autoPtr<CompactListList<T> > CompactListList<T>::clone() const
00062 {
00063     return autoPtr<CompactListList<T> >(new CompactListList<T>(*this));
00064 }
00065 
00066 
00067 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00068 
00069 template<class T>
00070 inline label CompactListList<T>::size() const
00071 {
00072     return offsets_.size();
00073 }
00074 
00075 template<class T>
00076 inline const List<label>& CompactListList<T>::offsets() const
00077 {
00078     return offsets_;
00079 }
00080 
00081 template<class T>
00082 inline List<label>& CompactListList<T>::offsets()
00083 {
00084     return offsets_;
00085 }
00086 
00087 template<class T>
00088 inline const List<T>& CompactListList<T>::m() const
00089 {
00090     return m_;
00091 }
00092 
00093 template<class T>
00094 inline List<T>& CompactListList<T>::m()
00095 {
00096     return m_;
00097 }
00098 
00099 
00100 template<class T>
00101 inline label CompactListList<T>::index(const label i, const label j) const
00102 {
00103     if (i == 0)
00104     {
00105         return j;
00106     }
00107     else
00108     {
00109         return offsets_[i-1] + j;
00110     }
00111 }
00112 
00113 template<class T>
00114 inline label CompactListList<T>::whichRow(const label i) const
00115 {
00116     if (i < 0 || i >= m_.size())
00117     {
00118         FatalErrorIn
00119         (
00120             "CompactListList<T>::whichRow(const label i) const"
00121         )   << "Index " << i << " outside 0.." << m_.size()
00122             << abort(FatalError);
00123     }
00124 
00125     forAll(offsets_, rowI)
00126     {
00127         if (i < offsets_[rowI])
00128         {
00129             return rowI;
00130         }
00131     }
00132 
00133     return -1;
00134 }
00135 
00136 template<class T>
00137 inline label CompactListList<T>::whichColumn(const label row, const label i)
00138  const
00139 {
00140     return i - index(row, 0);
00141 }
00142 
00143 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00144 
00145 template<class T>
00146 inline UList<T> CompactListList<T>::operator[](const label i)
00147 {
00148     if (i == 0)
00149     {
00150         return UList<T>(m_.begin(), offsets_[i]);
00151     }
00152     else
00153     {
00154         return UList<T>(&m_[offsets_[i-1]], offsets_[i] - offsets_[i-1]);
00155     }
00156 }
00157 
00158 template<class T>
00159 inline const UList<T> CompactListList<T>::operator[](const label i) const
00160 {
00161     if (i == 0)
00162     {
00163         return UList<T>(m_.begin(), offsets_[i]);
00164     }
00165     else
00166     {
00167         return UList<T>(&m_[offsets_[i-1]], offsets_[i] - offsets_[i-1]);
00168     }
00169 }
00170 
00171 
00172 template<class T>
00173 inline T& CompactListList<T>::operator()(const label i, const label j)
00174 {
00175     return m_[index(i, j)];
00176 }
00177 
00178 template<class T>
00179 inline const T& CompactListList<T>::operator()
00180 (
00181     const label i,
00182     const label j
00183 ) const
00184 {
00185     return m_[index(i, j)];
00186 }
00187 
00188 
00189 template<class T>
00190 inline void CompactListList<T>::operator=(const T& t)
00191 {
00192     m_ = t;
00193 }
00194 
00195 
00196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00197 
00198 } // End namespace Foam
00199 
00200 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd