Commit a8550cd0 authored by Mark Olesen's avatar Mark Olesen
Browse files

List - adjusted transfer(DynamicList) and added transfer(SortableList)

parent 8b72dbed
......@@ -100,6 +100,15 @@ int main(int argc, char *argv[])
Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
<< " " << dlB.size() << "/" << dlB.allocSize() << endl;
// try with a normal list:
List<label> lstA;
lstA.transfer(dlB);
Info<< "Transferred to normal list" << endl;
Info<< "<lstA>" << lstA << "</lstA>" << nl << "sizes: "
<< " " << lstA.size() << endl;
Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
<< " " << dlB.size() << "/" << dlB.allocSize() << endl;
return 0;
}
......
......@@ -70,6 +70,13 @@ int main(int argc, char *argv[])
Info << "sorted: " << b << endl;
Info << "indices: " << b.indices() << endl;
labelList flatten;
flatten.transfer(b);
Info << "flatten: " << flatten << endl;
Info << "sorted: " << b << endl;
Info << "indices: " << b.indices() << endl;
Info << "End\n" << endl;
return 0;
......
......@@ -432,14 +432,20 @@ void Foam::List<T>::transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>& a)
{
// shrink the allocated space to the number of elements used
a.shrink();
a.allocSize_ = 0;
if (this->v_) delete[] this->v_;
this->size_ = a.size_;
this->v_ = a.v_;
transfer(static_cast<List<T>&>(a));
}
a.size_ = 0;
a.v_ = 0;
a.allocSize_ = 0;
// Transfer the contents of the argument SortableList into this List
// and anull the argument list
template<class T>
void Foam::List<T>::transfer(SortableList<T>& a)
{
// shrink away the sort indices
a.shrink();
transfer(static_cast<List<T>&>(a));
}
......
......@@ -63,7 +63,8 @@ template<class T, label Size> class FixedList;
template<class T> class PtrList;
template<class T> class SLList;
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
class DynamicList;
class DynamicList;
template<class T> class SortableList;
template<class T> class IndirectList;
template<class T> class BiIndirectList;
......@@ -173,6 +174,10 @@ public:
template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&);
//- Transfer the contents of the argument List into this List
// and annull the argument list.
void transfer(SortableList<T>&);
//- Return subscript-checked element of UList.
inline T& newElmt(const label);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment