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 \*---------------------------------------------------------------------------*/
31 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
34 Foam::UPtrList<T>::UPtrList()
41 Foam::UPtrList<T>::UPtrList(const label s)
43 ptrs_(s, reinterpret_cast<T*>(0))
48 Foam::UPtrList<T>::UPtrList(const Xfer<UPtrList<T> >& lst)
55 Foam::UPtrList<T>::UPtrList(UPtrList<T>& a, bool reUse)
61 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
64 void Foam::UPtrList<T>::setSize(const label newSize)
66 label oldSize = size();
72 else if (newSize < oldSize)
74 ptrs_.setSize(newSize);
76 else if (newSize > oldSize)
78 ptrs_.setSize(newSize);
80 // set new elements to NULL
81 for (register label i=oldSize; i<newSize; i++)
90 void Foam::UPtrList<T>::clear()
96 // Transfer the contents of the argument List into this List
97 // and anull the argument list
99 void Foam::UPtrList<T>::transfer(UPtrList<T>& a)
101 ptrs_.transfer(a.ptrs_);
106 void Foam::UPtrList<T>::reorder(const UList<label>& oldToNew)
108 if (oldToNew.size() != size())
110 FatalErrorIn("UPtrList<T>::reorder(const UList<label>&)")
111 << "Size of map (" << oldToNew.size()
112 << ") not equal to list size (" << size()
113 << ")." << abort(FatalError);
116 List<T*> newPtrs_(ptrs_.size(), reinterpret_cast<T*>(0));
120 label newI = oldToNew[i];
122 if (newI < 0 || newI >= size())
124 FatalErrorIn("UPtrList<T>::reorder(const UList<label>&)")
125 << "Illegal index " << newI << nl
126 << "Valid indices are 0.." << size()-1
127 << abort(FatalError);
132 FatalErrorIn("UPtrList<T>::reorder(const UList<label>&)")
133 << "reorder map is not unique; element " << newI
134 << " already set." << abort(FatalError);
136 newPtrs_[newI] = ptrs_[i];
143 FatalErrorIn("UPtrList<T>::reorder(const UList<label>&)")
144 << "Element " << i << " not set after reordering." << nl
145 << abort(FatalError);
149 ptrs_.transfer(newPtrs_);
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 #include "UPtrListIO.C"
157 // ************************************************************************* //