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 \*---------------------------------------------------------------------------*/
30 #include "PtrListLoopM.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
40 UPtrList<T>::UPtrList()
47 UPtrList<T>::UPtrList(const label s)
49 ptrs_(s, reinterpret_cast<T*>(NULL))
54 UPtrList<T>::UPtrList(UPtrList<T>& a, bool reUse)
60 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
63 void UPtrList<T>::setSize(const label newSize)
65 label oldSize = size();
71 else if (newSize < oldSize)
73 ptrs_.setSize(newSize);
75 else if (newSize > oldSize)
77 ptrs_.setSize(newSize);
80 for (i=oldSize; i<newSize; i++)
89 void UPtrList<T>::clear()
95 // Transfer the contents of the argument List into this List
96 // and anull the argument list
98 void UPtrList<T>::transfer(UPtrList<T>& a)
100 ptrs_.transfer(a.ptrs_);
105 void UPtrList<T>::reorder(const UList<label>& oldToNew)
107 if (oldToNew.size() != size())
109 FatalErrorIn("UPtrList<T>::reorder(const UList<label>&)")
110 << "Size of map (" << oldToNew.size()
111 << ") not equal to list size (" << size()
112 << ")." << abort(FatalError);
115 List<T*> newPtrs_(ptrs_.size(), reinterpret_cast<T*>(NULL));
119 label newI = oldToNew[i];
121 if (newI < 0 || newI >= size())
123 FatalErrorIn("UPtrList<T>::reorder(const UList<label>&)")
124 << "Illegal index " << newI << nl
125 << "Valid indices are 0.." << size()-1
126 << abort(FatalError);
131 FatalErrorIn("UPtrList<T>::reorder(const UList<label>&)")
132 << "reorder map is not unique; element " << newI
133 << " already set." << abort(FatalError);
135 newPtrs_[newI] = ptrs_[i];
142 FatalErrorIn("UPtrList<T>::reorder(const UList<label>&)")
143 << "Element " << i << " not set after reordering." << nl
144 << abort(FatalError);
148 ptrs_.transfer(newPtrs_);
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 } // End namespace Foam
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 #include "UPtrListIO.C"
160 // ************************************************************************* //