initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / containers / Lists / CompactListList / CompactListListI.H
blob2dad35b6fc0d670f5d11cab5b16e8f5ce5980651
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 \*---------------------------------------------------------------------------*/
27 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 namespace Foam
32 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
34 template<class T>
35 inline CompactListList<T>::CompactListList()
39 template<class T>
40 inline CompactListList<T>::CompactListList(const label nRows, const label nData)
42     offsets_(nRows, 0),
43     m_(nData)
47 template<class T>
48 inline 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 autoPtr<CompactListList<T> > CompactListList<T>::clone() const
63     return autoPtr<CompactListList<T> >(new CompactListList<T>(*this));
67 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
69 template<class T>
70 inline label CompactListList<T>::size() const
72     return offsets_.size();
75 template<class T>
76 inline const List<label>& CompactListList<T>::offsets() const
78     return offsets_;
81 template<class T>
82 inline List<label>& CompactListList<T>::offsets()
84     return offsets_;
87 template<class T>
88 inline const List<T>& CompactListList<T>::m() const
90     return m_;
93 template<class T>
94 inline List<T>& CompactListList<T>::m()
96     return m_;
100 template<class T>
101 inline label CompactListList<T>::index(const label i, const label j) const
103     if (i == 0)
104     {
105         return j;
106     }
107     else
108     {
109         return offsets_[i-1] + j;
110     }
113 template<class T>
114 inline label CompactListList<T>::whichRow(const label i) const
116     if (i < 0 || i >= m_.size())
117     {
118         FatalErrorIn
119         (
120             "CompactListList<T>::whichRow(const label i) const"
121         )   << "Index " << i << " outside 0.." << m_.size()
122             << abort(FatalError);
123     }
125     forAll(offsets_, rowI)
126     {
127         if (i < offsets_[rowI])
128         {
129             return rowI;
130         }
131     }
133     return -1;
136 template<class T>
137 inline label CompactListList<T>::whichColumn(const label row, const label i)
138  const
140     return i - index(row, 0);
143 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
145 template<class T>
146 inline UList<T> CompactListList<T>::operator[](const label i)
148     if (i == 0)
149     {
150         return UList<T>(m_.begin(), offsets_[i]);
151     }
152     else
153     {
154         return UList<T>(&m_[offsets_[i-1]], offsets_[i] - offsets_[i-1]);
155     }
158 template<class T>
159 inline const UList<T> CompactListList<T>::operator[](const label i) const
161     if (i == 0)
162     {
163         return UList<T>(m_.begin(), offsets_[i]);
164     }
165     else
166     {
167         return UList<T>(&m_[offsets_[i-1]], offsets_[i] - offsets_[i-1]);
168     }
172 template<class T>
173 inline T& CompactListList<T>::operator()(const label i, const label j)
175     return m_[index(i, j)];
178 template<class T>
179 inline const T& CompactListList<T>::operator()
181     const label i,
182     const label j
183 ) const
185     return m_[index(i, j)];
189 template<class T>
190 inline void CompactListList<T>::operator=(const T& t)
192     m_ = t;
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 } // End namespace Foam
200 // ************************************************************************* //