1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "CompactListList.H"
28 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
31 Foam::CompactListList<T>::CompactListList(const List<List<T> >& ll)
38 sumSize += ll[i].size();
39 offsets_[i] = sumSize;
47 const List<T>& lli = ll[i];
58 Foam::CompactListList<T>::CompactListList
60 const UList<label>& rowSizes
63 offsets_(rowSizes.size())
68 sumSize += rowSizes[i];
69 offsets_[i] = sumSize;
77 Foam::CompactListList<T>::CompactListList
79 const UList<label>& rowSizes,
83 offsets_(rowSizes.size())
88 sumSize += rowSizes[i];
89 offsets_[i] = sumSize;
92 m_.setSize(sumSize, t);
97 Foam::CompactListList<T>::CompactListList
99 const Xfer<CompactListList<T> >& lst
107 Foam::CompactListList<T>::CompactListList
109 CompactListList<T>& lst,
113 offsets_(lst.offsets_, reUse),
118 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 void Foam::CompactListList<T>::setSize(const label nRows)
127 if (nRows < offsets_.size())
129 offsets_.setSize(nRows);
130 m_.setSize(offsets_[nRows - 1]);
132 else if (nRows > offsets_.size())
134 FatalErrorIn("CompactListList<T>::setSize(const label nRows)")
135 << "Cannot be used to extend the list from " << offsets_.size()
136 << " to " << nRows << nl
137 << " Please use one of the other setSize member functions"
138 << abort(FatalError);
144 void Foam::CompactListList<T>::setSize
150 offsets_.setSize(nRows);
156 void Foam::CompactListList<T>::setSize
163 offsets_.setSize(nRows);
164 m_.setSize(nData, t);
169 void Foam::CompactListList<T>::setSize(const UList<label>& rowSizes)
171 offsets_.setSize(rowSizes.size());
176 sumSize += rowSizes[i];
177 offsets_[i] = sumSize;
185 Foam::labelList Foam::CompactListList<T>::sizes() const
187 labelList rowSizes(offsets_.size());
189 label prevOffset = 0;
192 rowSizes[i] = offsets_[i]-prevOffset;
193 prevOffset = offsets_[i];
200 void Foam::CompactListList<T>::clear()
208 void Foam::CompactListList<T>::transfer(CompactListList<T>& a)
210 offsets_.transfer(a.offsets_);
215 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
218 Foam::List<Foam::List<T> > Foam::CompactListList<T>::operator()() const
220 List<List<T> > ll(offsets_.size());
222 label offsetPrev = 0;
225 List<T>& lst = ll[i];
227 lst.setSize(offsets_[i] - offsetPrev);
231 lst[j] = m_[offsetPrev + j];
234 offsetPrev = offsets_[i];
241 // * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
243 #include "CompactListListIO.C"
245 // ************************************************************************* //