UPtrList.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "error.H"
00028
00029 #include "UPtrList.H"
00030
00031
00032
00033 template<class T>
00034 Foam::UPtrList<T>::UPtrList()
00035 :
00036 ptrs_()
00037 {}
00038
00039
00040 template<class T>
00041 Foam::UPtrList<T>::UPtrList(const label s)
00042 :
00043 ptrs_(s, reinterpret_cast<T*>(0))
00044 {}
00045
00046
00047 template<class T>
00048 Foam::UPtrList<T>::UPtrList(const Xfer<UPtrList<T> >& lst)
00049 {
00050 transfer(lst());
00051 }
00052
00053
00054 template<class T>
00055 Foam::UPtrList<T>::UPtrList(UPtrList<T>& a, bool reUse)
00056 :
00057 ptrs_(a.ptrs_, reUse)
00058 {}
00059
00060
00061
00062
00063 template<class T>
00064 void Foam::UPtrList<T>::setSize(const label newSize)
00065 {
00066 label oldSize = size();
00067
00068 if (newSize <= 0)
00069 {
00070 clear();
00071 }
00072 else if (newSize < oldSize)
00073 {
00074 ptrs_.setSize(newSize);
00075 }
00076 else if (newSize > oldSize)
00077 {
00078 ptrs_.setSize(newSize);
00079
00080
00081 for (register label i=oldSize; i<newSize; i++)
00082 {
00083 ptrs_[i] = NULL;
00084 }
00085 }
00086 }
00087
00088
00089 template<class T>
00090 void Foam::UPtrList<T>::clear()
00091 {
00092 ptrs_.clear();
00093 }
00094
00095
00096
00097
00098 template<class T>
00099 void Foam::UPtrList<T>::transfer(UPtrList<T>& a)
00100 {
00101 ptrs_.transfer(a.ptrs_);
00102 }
00103
00104
00105 template<class T>
00106 void Foam::UPtrList<T>::reorder(const UList<label>& oldToNew)
00107 {
00108 if (oldToNew.size() != size())
00109 {
00110 FatalErrorIn("UPtrList<T>::reorder(const UList<label>&)")
00111 << "Size of map (" << oldToNew.size()
00112 << ") not equal to list size (" << size()
00113 << ")." << abort(FatalError);
00114 }
00115
00116 List<T*> newPtrs_(ptrs_.size(), reinterpret_cast<T*>(0));
00117
00118 forAll(*this, i)
00119 {
00120 label newI = oldToNew[i];
00121
00122 if (newI < 0 || newI >= size())
00123 {
00124 FatalErrorIn("UPtrList<T>::reorder(const UList<label>&)")
00125 << "Illegal index " << newI << nl
00126 << "Valid indices are 0.." << size()-1
00127 << abort(FatalError);
00128 }
00129
00130 if (newPtrs_[newI])
00131 {
00132 FatalErrorIn("UPtrList<T>::reorder(const UList<label>&)")
00133 << "reorder map is not unique; element " << newI
00134 << " already set." << abort(FatalError);
00135 }
00136 newPtrs_[newI] = ptrs_[i];
00137 }
00138
00139 forAll(newPtrs_, i)
00140 {
00141 if (!newPtrs_[i])
00142 {
00143 FatalErrorIn("UPtrList<T>::reorder(const UList<label>&)")
00144 << "Element " << i << " not set after reordering." << nl
00145 << abort(FatalError);
00146 }
00147 }
00148
00149 ptrs_.transfer(newPtrs_);
00150 }
00151
00152
00153
00154
00155 #include "UPtrListIO.C"
00156
00157
Copyright © 2000-2009 OpenCFD Ltd