1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
37 CompactListList<T>::CompactListList(const List<List<T> >& ll)
44 sumSize += ll[i].size();
45 offsets_[i] = sumSize;
53 const List<T>& lli = ll[i];
64 CompactListList<T>::CompactListList(const UList<label>& rowSizes)
66 offsets_(rowSizes.size())
71 sumSize += rowSizes[i];
72 offsets_[i] = sumSize;
80 CompactListList<T>::CompactListList(const UList<label>& rowSizes, const T& t)
82 offsets_(rowSizes.size())
87 sumSize += rowSizes[i];
88 offsets_[i] = sumSize;
91 m_.setSize(sumSize, t);
96 CompactListList<T>::CompactListList(CompactListList<T>& cll, bool reUse)
98 offsets_(cll.offsets_, reUse),
103 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
106 const CompactListList<T>& CompactListList<T>::null()
108 CompactListList<T>* nullPtr = reinterpret_cast<CompactListList<T>*>(NULL);
114 void CompactListList<T>::setSize(const label nRows)
120 if (nRows < offsets_.size())
122 offsets_.setSize(nRows);
123 m_.setSize(offsets_[nRows - 1]);
125 else if (nRows > offsets_.size())
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);
137 void CompactListList<T>::setSize(const label nRows, const label nData)
139 offsets_.setSize(nRows);
144 void CompactListList<T>::setSize
151 offsets_.setSize(nRows);
152 m_.setSize(nData, t);
156 labelList CompactListList<T>::sizes() const
158 labelList rowSizes(offsets_.size());
160 label prevOffset = 0;
163 rowSizes[i] = offsets_[i]-prevOffset;
164 prevOffset = offsets_[i];
170 void CompactListList<T>::setSize(const UList<label>& rowSizes)
172 offsets_.setSize(rowSizes.size());
177 sumSize += rowSizes[i];
178 offsets_[i] = sumSize;
185 void CompactListList<T>::clear()
193 void CompactListList<T>::transfer(CompactListList<T>& a)
195 offsets_.transfer(a.offsets_);
200 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
203 List<List<T> > CompactListList<T>::operator()() const
205 List<List<T> > llt(offsets_.size());
207 label offsetPrev = 0;
210 List<T>& llti = llt[i];
212 llti.setSize(offsets_[i] - offsetPrev);
216 llti[j] = m_[offsetPrev + j];
219 offsetPrev = offsets_[i];
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229 } // End namespace Foam
231 // * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
233 #include "CompactListListIO.C"
235 // ************************************************************************* //