From fa3acc9955b29cd5d5408330899a024c2954530c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 26 Jan 2018 12:19:48 +0100 Subject: [PATCH] ENH: make CompactListList swapable and move construct/assignable --- .../CompactListList/Test-CompactListList.C | 8 +-- .../faceAgglomerate/faceAgglomerate.C | 1 - .../Lists/CompactListList/CompactListList.C | 39 +++++------ .../Lists/CompactListList/CompactListList.H | 22 +++++- .../Lists/CompactListList/CompactListListI.H | 69 +++++++++++++++++-- 5 files changed, 105 insertions(+), 34 deletions(-) diff --git a/applications/test/CompactListList/Test-CompactListList.C b/applications/test/CompactListList/Test-CompactListList.C index 265bb7646f..587fa9df82 100644 --- a/applications/test/CompactListList/Test-CompactListList.C +++ b/applications/test/CompactListList/Test-CompactListList.C @@ -47,8 +47,8 @@ int main(int argc, char *argv[]) Info<< "cll1:" << cll1 << endl; // Resize and assign row by row - labelList row0(2, 0); - labelList row1(3, 1); + labelList row0(2, label(0)); + labelList row1(3, label(1)); labelList rowSizes(2); rowSizes[0] = row0.size(); @@ -140,8 +140,8 @@ int main(int argc, char *argv[]) { faceList fcs(2); - fcs[0] = face(labelList(1, 111)); - fcs[1] = face(labelList(2, 222)); + fcs[0] = face(labelList(1, label(111))); + fcs[1] = face(labelList(2, label(222))); CompactListList compactFcs(fcs); Info<< "comactFcs:" << compactFcs << endl; diff --git a/applications/utilities/preProcessing/faceAgglomerate/faceAgglomerate.C b/applications/utilities/preProcessing/faceAgglomerate/faceAgglomerate.C index 99caaf375b..eff776563f 100644 --- a/applications/utilities/preProcessing/faceAgglomerate/faceAgglomerate.C +++ b/applications/utilities/preProcessing/faceAgglomerate/faceAgglomerate.C @@ -41,7 +41,6 @@ SeeAlso #include "fvMesh.H" #include "Time.H" #include "volFields.H" -#include "CompactListList.H" #include "unitConversion.H" #include "pairPatchAgglomeration.H" #include "labelListIOList.H" diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C b/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C index f2ad0802b0..2532ac7e4a 100644 --- a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C +++ b/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C @@ -81,7 +81,7 @@ template Foam::CompactListList::CompactListList ( const labelUList& rowSizes, - const T& t + const T& val ) : size_(rowSizes.size()), @@ -95,7 +95,7 @@ Foam::CompactListList::CompactListList offsets_[i+1] = sumSize; } - m_.setSize(sumSize, t); + m_.setSize(sumSize, val); } @@ -109,19 +109,6 @@ Foam::CompactListList::CompactListList } -template -Foam::CompactListList::CompactListList -( - CompactListList& lst, - bool reuse -) -: - size_(lst.size()), - offsets_(lst.offsets_, reuse), - m_(lst.m_, reuse) -{} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template @@ -219,14 +206,26 @@ void Foam::CompactListList::clear() template -void Foam::CompactListList::transfer +void Foam::CompactListList::swap ( - CompactListList& a + CompactListList& lst ) { - size_ = a.size_; - offsets_.transfer(a.offsets_); - m_.transfer(a.m_); + Foam::Swap(size_, lst.size_); + offsets_.swap(lst.offsets_); + m_.swap(lst.m_); +} + + +template +void Foam::CompactListList::transfer +( + CompactListList& lst +) +{ + size_ = lst.size_; + offsets_.transfer(lst.offsets_); + m_.transfer(lst.m_); } diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H b/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H index fcb7ea2ba5..5c1115e5af 100644 --- a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H +++ b/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H @@ -119,11 +119,17 @@ public: //- Construct given list of row-sizes CompactListList(const labelUList& rowSizes, const T&); + //- Copy construct + inline CompactListList(const CompactListList& lst); + + //- Move construct + inline CompactListList(CompactListList&& lst); + //- Construct by transferring the parameter contents explicit CompactListList(const Xfer>&); //- Construct as copy or re-use as specified. - CompactListList(CompactListList&, bool reuse); + inline CompactListList(CompactListList& lst, bool reuse); //- Construct from Istream. CompactListList(Istream&); @@ -189,13 +195,17 @@ public: //- Return sizes (to be used e.g. for construction) labelList sizes() const; + //- Swap contents + void swap(CompactListList& lst); + //- Transfer the contents of the argument CompactListList // into this CompactListList and annul the argument list. - void transfer(CompactListList&); + void transfer(CompactListList& lst); //- Transfer the contents to the Xfer container inline Xfer> xfer(); + // Other //- Return index into m @@ -226,7 +236,13 @@ public: List operator()() const; //- Assignment of all entries to the given value - inline void operator=(const T&); + inline void operator=(const T& val); + + //- Copy assignment + inline void operator=(const CompactListList& lst); + + //- Move assignment + inline void operator=(CompactListList&& lst); // Istream operator diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H b/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H index 2072887cc5..65ae222f6e 100644 --- a/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H +++ b/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H @@ -53,12 +53,47 @@ inline Foam::CompactListList::CompactListList ( const label mRows, const label nData, - const T& t + const T& val ) : size_(mRows), offsets_(mRows+1, 0), - m_(nData, t) + m_(nData, val) +{} + + +template +inline Foam::CompactListList::CompactListList +( + const CompactListList& lst +) +: + size_(lst.size()), + offsets_(lst.offsets_), + m_(lst.m_) +{} + + +template +inline Foam::CompactListList::CompactListList +( + CompactListList&& lst +) +{ + transfer(lst); +} + + +template +inline Foam::CompactListList::CompactListList +( + CompactListList& lst, + bool reuse +) +: + size_(lst.size()), + offsets_(lst.offsets_, reuse), + m_(lst.m_, reuse) {} @@ -220,7 +255,7 @@ inline Foam::UList Foam::CompactListList::operator[] const label i ) { - label start = offsets_[i]; + const label start = offsets_[i]; return UList(m_.begin() + start, offsets_[i+1] - start); } @@ -232,7 +267,7 @@ Foam::CompactListList::operator[] const label i ) const { - label start = offsets_[i]; + const label start = offsets_[i]; return UList ( const_cast(m_.begin() + start), @@ -264,9 +299,31 @@ inline const T& Foam::CompactListList::operator() template -inline void Foam::CompactListList::operator=(const T& t) +inline void Foam::CompactListList::operator=(const T& val) { - m_ = t; + m_ = val; +} + + +template +inline void Foam::CompactListList::operator= +( + const CompactListList& lst +) +{ + size_ = lst.size_; + offsets_ = lst.offsets_, + m_ = lst.m_; +} + + +template +inline void Foam::CompactListList::operator= +( + CompactListList&& lst +) +{ + transfer(lst); }