initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / containers / Lists / CompactListList / CompactListListI.H
blobdc57627911d5c63e8175b059731bf6d1ded3f27e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
28 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
30 template<class T>
31 inline Foam::CompactListList<T>::CompactListList()
35 template<class T>
36 inline Foam::CompactListList<T>::CompactListList
38     const label nRows,
39     const label nData
42     offsets_(nRows, 0),
43     m_(nData)
47 template<class T>
48 inline Foam::CompactListList<T>::CompactListList
50     const label nRows,
51     const label nData,
52     const T& t
55     offsets_(nRows, 0),
56     m_(nData, t)
60 template<class T>
61 inline Foam::autoPtr<Foam::CompactListList<T> >
62 Foam::CompactListList<T>::clone() const
64     return autoPtr<CompactListList<T> >(new CompactListList<T>(*this));
68 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
70 template<class T>
71 inline const Foam::CompactListList<T>& Foam::CompactListList<T>::null()
73     return *reinterpret_cast< CompactListList<T>* >(0);
77 template<class T>
78 inline Foam::label Foam::CompactListList<T>::size() const
80     return offsets_.size();
84 template<class T>
85 inline bool Foam::CompactListList<T>::empty() const
87     return offsets_.empty();
91 template<class T>
92 inline const Foam::List<Foam::label>& Foam::CompactListList<T>::offsets() const
94     return offsets_;
98 template<class T>
99 inline Foam::List<Foam::label>& Foam::CompactListList<T>::offsets()
101     return offsets_;
105 template<class T>
106 inline const Foam::List<T>& Foam::CompactListList<T>::m() const
108     return m_;
112 template<class T>
113 inline Foam::List<T>& Foam::CompactListList<T>::m()
115     return m_;
119 template<class T>
120 inline Foam::label Foam::CompactListList<T>::index
122     const label i,
123     const label j
124 ) const
126     if (i == 0)
127     {
128         return j;
129     }
130     else
131     {
132         return offsets_[i-1] + j;
133     }
137 template<class T>
138 inline Foam::label Foam::CompactListList<T>::whichRow(const label i) const
140     if (i < 0 || i >= m_.size())
141     {
142         FatalErrorIn
143         (
144             "CompactListList<T>::whichRow(const label) const"
145         )   << "Index " << i << " outside 0.." << m_.size()
146             << abort(FatalError);
147     }
149     forAll(offsets_, rowI)
150     {
151         if (i < offsets_[rowI])
152         {
153             return rowI;
154         }
155     }
157     return -1;
161 template<class T>
162 inline Foam::label Foam::CompactListList<T>::whichColumn
164     const label row,
165     const label i
166 ) const
168     return i - index(row, 0);
172 template<class T>
173 inline Foam::Xfer<Foam::CompactListList<T> > Foam::CompactListList<T>::xfer()
175     return xferMove(*this);
179 template<class T>
180 inline void Foam::CompactListList<T>::resize(const label nRows)
182     this->setSize(nRows);
186 template<class T>
187 inline void Foam::CompactListList<T>::resize
189     const label nRows,
190     const label nData
193     this->setSize(nRows, nData);
197 template<class T>
198 inline void Foam::CompactListList<T>::resize
200     const label nRows,
201     const label nData,
202     const T& t
205     this->setSize(nRows, nData, t);
209 template<class T>
210 inline void Foam::CompactListList<T>::resize(const UList<label>& rowSizes)
212     this->setSize(rowSizes);
216 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
218 template<class T>
219 inline Foam::UList<T> Foam::CompactListList<T>::operator[]
221     const label i
224     if (i == 0)
225     {
226         return UList<T>(m_.begin(), offsets_[i]);
227     }
228     else
229     {
230         return UList<T>(&m_[offsets_[i-1]], offsets_[i] - offsets_[i-1]);
231     }
235 template<class T>
236 inline const Foam::UList<T> Foam::CompactListList<T>::operator[]
238     const label i
239 ) const
241     if (i == 0)
242     {
243         return UList<T>(m_.begin(), offsets_[i]);
244     }
245     else
246     {
247         return UList<T>(&m_[offsets_[i-1]], offsets_[i] - offsets_[i-1]);
248     }
252 template<class T>
253 inline T& Foam::CompactListList<T>::operator()
255     const label i,
256     const label j
259     return m_[index(i, j)];
263 template<class T>
264 inline const T& Foam::CompactListList<T>::operator()
266     const label i,
267     const label j
268 ) const
270     return m_[index(i, j)];
274 template<class T>
275 inline void Foam::CompactListList<T>::operator=(const T& t)
277     m_ = t;
281 // ************************************************************************* //