diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index da6bd13067..8ab5f7cef4 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -33,7 +33,7 @@ inline Foam::DynamicList::DynamicList() List(SizeInc), allocSize_(SizeInc) { - List::size() = 0; + List::size(0); } @@ -47,7 +47,7 @@ inline Foam::DynamicList::DynamicList List(s), allocSize_(s) { - List::size() = 0; + List::size(0); } @@ -81,14 +81,14 @@ inline void Foam::DynamicList::setSize { if (s < List::size()) { - List::size() = s; + List::size(s); } else { label nextFree = List::size(); allocSize_ = s; List::setSize(allocSize_); - List::size() = nextFree; + List::size(nextFree); } } @@ -102,14 +102,14 @@ inline void Foam::DynamicList::setSize { if (s < List::size()) { - List::size() = s; + List::size(s); } else { label nextFree = List::size(); allocSize_ = s; List::setSize(allocSize_, t); - List::size() = nextFree; + List::size(nextFree); } } @@ -117,7 +117,7 @@ inline void Foam::DynamicList::setSize template inline void Foam::DynamicList::clear() { - List::size() = 0; + List::size(0); } @@ -191,7 +191,7 @@ inline void Foam::DynamicList::append(const T& e) List::setSize(allocSize_); } - List::size() = nextFree; + List::size(nextFree); this->operator[](nextFree - 1) = e; } @@ -212,7 +212,7 @@ inline T Foam::DynamicList::remove() const T& val = List::operator[](nextFree); - List::size() = nextFree; + List::size(nextFree); return val; } @@ -240,7 +240,7 @@ inline T& Foam::DynamicList::operator() List::setSize(allocSize_); } - List::size() = nextFree; + List::size(nextFree); return this->operator[](i); } diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index f669c08780..2b5520b344 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -78,6 +78,12 @@ class List public UList { +protected: + + //- Override size to be inconsistent with allocated storage. + // Use with care. + inline void size(const label); + public: // Constructors diff --git a/src/OpenFOAM/containers/Lists/List/ListI.H b/src/OpenFOAM/containers/Lists/List/ListI.H index d39b19f884..dff3c177d7 100644 --- a/src/OpenFOAM/containers/Lists/List/ListI.H +++ b/src/OpenFOAM/containers/Lists/List/ListI.H @@ -52,6 +52,13 @@ inline T& Foam::List::newElmt(const label i) } +template +inline void Foam::List::size(const label n) +{ + UList::size_ = n; +} + + template inline Foam::label Foam::List::size() const { diff --git a/src/OpenFOAM/containers/Lists/SortableList/SortableList.C b/src/OpenFOAM/containers/Lists/SortableList/SortableList.C index a4264578d1..1f3f53a165 100644 --- a/src/OpenFOAM/containers/Lists/SortableList/SortableList.C +++ b/src/OpenFOAM/containers/Lists/SortableList/SortableList.C @@ -40,6 +40,17 @@ Foam::SortableList::SortableList(const List& values) sort(); } +// Construct from List by transferring +template +Foam::SortableList::SortableList(const xfer >& values) +: + List(), + indices_((*values).size()) +{ + List::transfer(*values); + sort(); +} + // Construct given size. Sort later on. template @@ -86,7 +97,7 @@ void Foam::SortableList::sort() indices_[i] = i; } - //Foam::sort(indices_, less(*this)); + // Foam::sort(indices_, less(*this)); Foam::stableSort(indices_, less(*this)); List tmpValues(this->size()); diff --git a/src/OpenFOAM/containers/Lists/SortableList/SortableList.H b/src/OpenFOAM/containers/Lists/SortableList/SortableList.H index dd0f0af0d4..1a5272e5b7 100644 --- a/src/OpenFOAM/containers/Lists/SortableList/SortableList.H +++ b/src/OpenFOAM/containers/Lists/SortableList/SortableList.H @@ -29,6 +29,8 @@ Description A list that is sorted upon construction or when explicitly requested with the sort() method. + Uses the Foam::stableSort() algorithm. + SourceFiles SortableList.C @@ -84,10 +86,14 @@ public: // Constructors - //- Construct from List, sorting the elements. Starts with indices set - // to index in argument + //- Construct from List, sorting the elements. + // Starts with indices set to index in argument explicit SortableList(const List&); + //- Construct from tranferred List, sorting the elements. + // Starts with indices set to index in argument + explicit SortableList(const xfer >&); + //- Construct given size. Sort later on. explicit SortableList(const label size);