diff --git a/applications/test/List/ListTest.C b/applications/test/List/ListTest.C index bc8901b03beacc65c399053ab5c5d49532009edf..d4834cb1db2b02bc79f4d6e8508e9f3b3361c695 100644 --- a/applications/test/List/ListTest.C +++ b/applications/test/List/ListTest.C @@ -43,31 +43,33 @@ using namespace Foam; int main(int argc, char *argv[]) { - List<vector> list(IStringStream("1 ((0 1 2))")()); - Info<< list << endl; + List<vector> list1(IStringStream("1 ((0 1 2))")()); + Info<< "list1: " << list1 << endl; List<vector> list2(IStringStream("((0 1 2) (3 4 5) (6 7 8))")()); - Info<< list2 << endl; + Info<< "list2: " << list2 << endl; + + list1.append(list2); + Info<< "list1.append(list2): " << list1 << endl; Info<< findIndex(list2, vector(3, 4, 5)) << endl; list2.setSize(10, vector(1, 2, 3)); - Info<< list2 << endl; + Info<< "list2: " << list2 << endl; List<vector> list3(list2.xfer()); Info<< "Transferred via the xfer() method" << endl; - Info<< list2 << nl - << list3 << endl; + Info<< "list2: " << list2 << nl + << "list3: " << list3 << endl; // Subset const labelList map(IStringStream("2 (0 2)")()); List<vector> subList3(list3, map); Info<< "Elements " << map << " out of " << list3 - << " : " << subList3 << endl; + << " => " << subList3 << endl; return 0; } - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index 6d20e2b3b72af3b5ec441d8c88668f2c9158b83c..429c91f820675d4ead0d17b1827dcca15fd9fbae 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -404,6 +404,61 @@ void Foam::List<T>::clear() } +template<class T> +void Foam::List<T>::append(const UList<T>& lst) +{ + if (this == &lst) + { + FatalErrorIn + ( + "List<T>::append(const UList<T>&)" + ) << "attempted appending to self" << abort(FatalError); + } + + label nextFree = this->size_; + setSize(nextFree + lst.size()); + + forAll(lst, elemI) + { + this->operator[](nextFree++) = lst[elemI]; + } +} + + +template<class T> +void Foam::List<T>::append(const UIndirectList<T>& lst) +{ + label nextFree = this->size_; + setSize(nextFree + lst.size()); + + forAll(lst, elemI) + { + this->operator[](nextFree++) = lst[elemI]; + } +} + + +template<class T> +void Foam::List<T>::append(const SLList<T>& lst) +{ + if (lst.size()) + { + label nextFree = this->size_; + setSize(nextFree + lst.size()); + + for + ( + typename SLList<T>::const_iterator iter = lst.begin(); + iter != lst.end(); + ++iter + ) + { + this->operator[](nextFree++) = iter(); + } + } +} + + // Transfer the contents of the argument List into this List // and anull the argument list template<class T> @@ -559,12 +614,9 @@ void Foam::List<T>::operator=(const IndirectList<T>& lst) if (this->size_) this->v_ = new T[this->size_]; } - if (this->size_) + forAll(*this, i) { - forAll(*this, i) - { - this->operator[](i) = lst[i]; - } + this->operator[](i) = lst[i]; } } @@ -581,12 +633,9 @@ void Foam::List<T>::operator=(const UIndirectList<T>& lst) if (this->size_) this->v_ = new T[this->size_]; } - if (this->size_) + forAll(*this, i) { - forAll(*this, i) - { - this->operator[](i) = lst[i]; - } + this->operator[](i) = lst[i]; } } @@ -603,12 +652,9 @@ void Foam::List<T>::operator=(const BiIndirectList<T>& lst) if (this->size_) this->v_ = new T[this->size_]; } - if (this->size_) + forAll(*this, i) { - forAll(*this, i) - { - this->operator[](i) = lst[i]; - } + this->operator[](i) = lst[i]; } } diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index 86876cff713e4bbba54302df8a51bb127370a9d0..5961ff174793741a484f7955872108c471791d7b 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -109,7 +109,7 @@ public: List(const List<T>&); //- Construct by transferring the parameter contents - List(const Xfer<List<T> >&); + List(const Xfer< List<T> >&); //- Construct as copy or re-use as specified. List(List<T>&, bool reUse); @@ -181,6 +181,15 @@ public: //- Clear the list, i.e. set size to zero. void clear(); + //- Append a List at the end of this list + void append(const UList<T>&); + + //- Append a UIndirectList at the end of this list + void append(const UIndirectList<T>&); + + //- Append a SLList at the end of this list + void append(const SLList<T>&); + //- Transfer the contents of the argument List into this List // and annull the argument list. void transfer(List<T>&); @@ -195,7 +204,7 @@ public: void transfer(SortableList<T>&); //- Transfer contents to the Xfer container - inline Xfer<List<T> > xfer(); + inline Xfer< List<T> > xfer(); //- Return subscript-checked element of UList. inline T& newElmt(const label);