initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / containers / Lists / CompactListList / CompactListList.C
blob9be79966c6e83132631ac1b556a1dd9836fed510
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 #include "CompactListList.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * * //
36 template<class T>
37 CompactListList<T>::CompactListList(const List<List<T> >& ll)
39     offsets_(ll.size())
41     label sumSize = 0;
42     forAll(ll, i)
43     {
44         sumSize += ll[i].size();
45         offsets_[i] = sumSize;
46     }
48     m_.setSize(sumSize);
50     label k = 0;
51     forAll(ll, i)
52     {
53         const List<T>& lli = ll[i];
55         forAll(lli, j)
56         {
57             m_[k++] = lli[j];
58         }
59     }
63 template<class T>
64 CompactListList<T>::CompactListList(const UList<label>& rowSizes)
66     offsets_(rowSizes.size())
68     label sumSize = 0;
69     forAll(rowSizes, i)
70     {
71         sumSize += rowSizes[i];
72         offsets_[i] = sumSize;
73     }
75     m_.setSize(sumSize);
79 template<class T>
80 CompactListList<T>::CompactListList(const UList<label>& rowSizes, const T& t)
82     offsets_(rowSizes.size())
84     label sumSize = 0;
85     forAll(rowSizes, i)
86     {
87         sumSize += rowSizes[i];
88         offsets_[i] = sumSize;
89     }
91     m_.setSize(sumSize, t);
95 template<class T>
96 CompactListList<T>::CompactListList(CompactListList<T>& cll, bool reUse)
98     offsets_(cll.offsets_, reUse),
99     m_(cll.m_, reUse)
103 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
105 template<class T>
106 const CompactListList<T>& CompactListList<T>::null()
108     CompactListList<T>* nullPtr = reinterpret_cast<CompactListList<T>*>(NULL);
109     return *nullPtr;
113 template<class T>
114 void CompactListList<T>::setSize(const label nRows)
116     if (nRows == 0)
117     {
118         clear();
119     }
120     if (nRows < offsets_.size())
121     {
122         offsets_.setSize(nRows);
123         m_.setSize(offsets_[nRows - 1]);
124     }
125     else if (nRows > offsets_.size())
126     {
127         FatalErrorIn("CompactListList<T>::setSize(const label nRows)")
128             << "Cannot be used to extend the list from " << offsets_.size()
129             << " to " << nRows << nl
130             << "    Please use one of the other setSize member functions"
131             << abort(FatalError);
132     }
136 template<class T>
137 void CompactListList<T>::setSize(const label nRows, const label nData)
139     offsets_.setSize(nRows);
140     m_.setSize(nData);
143 template<class T>
144 void CompactListList<T>::setSize
146     const label nRows,
147     const label nData,
148     const T& t
151     offsets_.setSize(nRows);
152     m_.setSize(nData, t);
155 template<class T>
156 labelList CompactListList<T>::sizes() const
158     labelList rowSizes(offsets_.size());
160     label prevOffset = 0;
161     forAll(offsets_, i)
162     {
163         rowSizes[i] = offsets_[i]-prevOffset;
164         prevOffset = offsets_[i];
165     }
166     return rowSizes;
169 template<class T>
170 void CompactListList<T>::setSize(const UList<label>& rowSizes)
172     offsets_.setSize(rowSizes.size());
174     label sumSize = 0;
175     forAll(rowSizes, i)
176     {
177         sumSize += rowSizes[i];
178         offsets_[i] = sumSize;
179     }
181     m_.setSize(sumSize);
184 template<class T>
185 void CompactListList<T>::clear()
187     offsets_.clear();
188     m_.clear();
192 template<class T>
193 void CompactListList<T>::transfer(CompactListList<T>& a)
195     offsets_.transfer(a.offsets_);
196     m_.transfer(a.m_);
200 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
202 template<class T>
203 List<List<T> > CompactListList<T>::operator()() const
205     List<List<T> > llt(offsets_.size());
207     label offsetPrev = 0;
208     forAll(offsets_, i)
209     {
210         List<T>& llti = llt[i];
212         llti.setSize(offsets_[i] - offsetPrev);
214         forAll(llti, j)
215         {
216             llti[j] = m_[offsetPrev + j];
217         }
219         offsetPrev = offsets_[i];
220     }
222     return llt;
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229 } // End namespace Foam
231 // * * * * * * * * * * * * * * * *  IOStream operators * * * * * * * * * * * //
233 #include "CompactListListIO.C"
235 // ************************************************************************* //