1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 \*---------------------------------------------------------------------------*/
30 #include "SLPtrList.H"
32 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
35 Foam::PtrList<T>::PtrList()
42 Foam::PtrList<T>::PtrList(const label s)
44 ptrs_(s, reinterpret_cast<T*>(0))
49 Foam::PtrList<T>::PtrList(const PtrList<T>& a)
55 ptrs_[i] = (a[i]).clone().ptr();
61 template<class CloneArg>
62 Foam::PtrList<T>::PtrList(const PtrList<T>& a, const CloneArg& cloneArg)
68 ptrs_[i] = (a[i]).clone(cloneArg).ptr();
74 Foam::PtrList<T>::PtrList(const Xfer<PtrList<T> >& lst)
81 Foam::PtrList<T>::PtrList(PtrList<T>& a, bool reUse)
89 ptrs_[i] = a.ptrs_[i];
98 ptrs_[i] = (a[i]).clone().ptr();
105 Foam::PtrList<T>::PtrList(const SLPtrList<T>& sll)
114 typename SLPtrList<T>::const_iterator iter = sll.begin();
119 ptrs_[i++] = (iter()).clone().ptr();
125 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
128 Foam::PtrList<T>::~PtrList()
140 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143 void Foam::PtrList<T>::setSize(const label newSize)
147 FatalErrorIn("PtrList<T>::setSize(const label)")
148 << "bad set size " << newSize
149 << abort(FatalError);
152 label oldSize = size();
158 else if (newSize < oldSize)
161 for (i=newSize; i<oldSize; i++)
169 ptrs_.setSize(newSize);
171 else // newSize > oldSize
173 ptrs_.setSize(newSize);
176 for (i=oldSize; i<newSize; i++)
185 void Foam::PtrList<T>::clear()
200 void Foam::PtrList<T>::transfer(PtrList<T>& a)
203 ptrs_.transfer(a.ptrs_);
208 void Foam::PtrList<T>::reorder(const UList<label>& oldToNew)
210 if (oldToNew.size() != size())
212 FatalErrorIn("PtrList<T>::reorder(const UList<label>&)")
213 << "Size of map (" << oldToNew.size()
214 << ") not equal to list size (" << size()
215 << ")." << abort(FatalError);
218 List<T*> newPtrs_(ptrs_.size(), reinterpret_cast<T*>(0));
222 label newI = oldToNew[i];
224 if (newI < 0 || newI >= size())
226 FatalErrorIn("PtrList<T>::reorder(const UList<label>&)")
227 << "Illegal index " << newI << nl
228 << "Valid indices are 0.." << size()-1
229 << abort(FatalError);
234 FatalErrorIn("PtrList<T>::reorder(const UList<label>&)")
235 << "reorder map is not unique; element " << newI
236 << " already set." << abort(FatalError);
238 newPtrs_[newI] = ptrs_[i];
245 FatalErrorIn("PtrList<T>::reorder(const UList<label>&)")
246 << "Element " << i << " not set after reordering." << nl
247 << abort(FatalError);
251 ptrs_.transfer(newPtrs_);
255 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
258 Foam::PtrList<T>& Foam::PtrList<T>::operator=(const PtrList<T>& a)
262 FatalErrorIn("PtrList<T>::operator=(const PtrList<T>&)")
263 << "attempted assignment to self"
264 << abort(FatalError);
273 ptrs_[i] = (a[i]).clone().ptr();
276 else if (a.size() == size())
285 FatalErrorIn("PtrList::operator=(const PtrList<T>&)")
286 << "bad size: " << a.size()
287 << abort(FatalError);
295 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
297 #include "PtrListIO.C"
299 // ************************************************************************* //