diff --git a/applications/test/PackedList4/Test-PackedList4.C b/applications/test/PackedList4/Test-PackedList4.C index e50eee04f4d6dae8bcf77141a36cdc7280f4be71..cb94feb1b9f22fb548036769324ada10a59dc2f3 100644 --- a/applications/test/PackedList4/Test-PackedList4.C +++ b/applications/test/PackedList4/Test-PackedList4.C @@ -144,18 +144,18 @@ int main(int argc, char *argv[]) Info<< "\ntest Istream constructor\n"; list4.printInfo(Info, true); - Info<< list4 << " indices: " << list4.used()() << nl; + Info<< list4 << " indices: " << list4.used() << nl; Info<< "\nassign from labelList\n"; list4 = labelList{0, 1, 2, 3, 12, 13, 14, 19, 20, 21}; list4.printInfo(Info, true); - Info<< list4 << " indices: " << list4.used()() << nl; + Info<< list4 << " indices: " << list4.used() << nl; // Not yet: // PackedBoolList list5{0, 1, 2, 3, 12, 13, 14, 19, 20, 21}; // list5.printInfo(Info, true); - // Info<< list5 << " indices: " << list5.used()() << nl; + // Info<< list5 << " indices: " << list5.used() << nl; Info<< "\nassign from indices\n"; list4.read @@ -168,7 +168,7 @@ int main(int argc, char *argv[]) list4.printInfo(Info, true); - Info<< list4 << " indices: " << list4.used()() << nl; + Info<< list4 << " indices: " << list4.used() << nl; boolList bools(list4.size()); forAll(list4, i) diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.C b/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.C index db6036d715194a70ebbbb89898c83e1cb15cedac..7179796b7e82a1da0925705454e14ee816c9db02 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.C +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.C @@ -265,26 +265,28 @@ Foam::label Foam::PackedBoolList::subset(const labelUIndList& indices) } -Foam::Xfer<Foam::labelList> Foam::PackedBoolList::used() const +Foam::labelList Foam::PackedBoolList::used() const { - labelList lst(this->count()); + // Number of used (set) entries + const label cnt = this->count(); - if (lst.size()) + labelList lst(cnt); + + if (cnt) { - label nElem = 0; + // The length of the input list + const label len = this->size(); - forAll(*this, elemI) + for (label i=0, usedi=0; (i < len && usedi < cnt); ++i) { - if (get(elemI)) + if (get(i)) { - lst[nElem++] = elemI; + lst[usedi++] = i; } } - - lst.setSize(nElem); } - return lst.xfer(); + return lst; } diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.H b/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.H index 28209b6ea53d3f3e665d0d39dd22800d98f2de5f..717be74288efeb411da48c90716c7245da9ffaba 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -91,7 +91,7 @@ public: // Constructors //- Construct null - inline PackedBoolList(); + PackedBoolList() = default; //- Construct from Istream PackedBoolList(Istream& is); @@ -102,17 +102,17 @@ public: //- Construct with given size and value for all elements inline PackedBoolList(const label size, const bool val); - //- Copy constructor + //- Copy construct inline PackedBoolList(const PackedBoolList& lst); - //- Copy constructor + //- Copy construct explicit inline PackedBoolList(const PackedList<1>& lst); - //- Construct by transferring the parameter contents - inline PackedBoolList(const Xfer<PackedBoolList>& lst); + //- Move construct + inline PackedBoolList(PackedBoolList&& lst); - //- Construct by transferring the parameter contents - inline PackedBoolList(const Xfer<PackedList<1>>& lst); + //- Move construct + inline PackedBoolList(PackedList<1>&& lst); //- Construct with given size and list of labels to set as true. inline PackedBoolList(const label size, const labelUList& indices); @@ -137,7 +137,7 @@ public: // Member Functions - // Access + // Access using PackedList<1>::set; using PackedList<1>::unset; @@ -175,12 +175,11 @@ public: // Return number of elements subsetted. label subset(const labelUIndList& indices); - //- Return indices of the used (true) elements as a list of labels - Xfer<labelList> used() const; + labelList used() const; - // Edit + // Edit //- Transfer the contents of the argument list into this list //- and annul the argument list. @@ -190,21 +189,24 @@ public: //- and annul the argument list. inline void transfer(PackedList<1>& lst); - //- Transfer contents to the Xfer container - inline Xfer<PackedBoolList> xfer(); - // Member Operators //- Assignment of all entries to the given value. inline void operator=(const bool val); - //- Assignment operator. + //- Copy assignment inline void operator=(const PackedBoolList& lst); - //- Assignment operator. + //- Copy assignment inline void operator=(const PackedList<1>& lst); + //- Move assignment + inline void operator=(PackedBoolList&& lst); + + //- Move assignment + inline void operator=(PackedList<1>&& lst); + //- Assignment operator. void operator=(const UList<bool>& lst); diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedBoolListI.H b/src/OpenFOAM/containers/Lists/PackedList/PackedBoolListI.H index db40fab00b272cbf6501984bd39fb3e6dcf6b8a7..c89acf0bc38b2f14af92d41224c2b6f600e8175c 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedBoolListI.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedBoolListI.H @@ -25,12 +25,6 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -inline Foam::PackedBoolList::PackedBoolList() -: - PackedList<1>() -{} - - inline Foam::PackedBoolList::PackedBoolList(const label size) : PackedList<1>(size) @@ -59,18 +53,20 @@ inline Foam::PackedBoolList::PackedBoolList(const PackedList<1>& lst) {} -inline Foam::PackedBoolList::PackedBoolList(const Xfer<PackedBoolList>& lst) +inline Foam::PackedBoolList::PackedBoolList(PackedBoolList&& lst) : PackedList<1>() { - transfer(lst()); + transfer(lst); } -inline Foam::PackedBoolList::PackedBoolList(const Xfer<PackedList<1>>& lst) +inline Foam::PackedBoolList::PackedBoolList(PackedList<1>&& lst) : - PackedList<1>(lst) -{} + PackedList<1>() +{ + transfer(lst); +} inline Foam::PackedBoolList::PackedBoolList(const UList<bool>& lst) @@ -147,12 +143,6 @@ inline void Foam::PackedBoolList::transfer(PackedList<1>& lst) } -inline Foam::Xfer<Foam::PackedBoolList> Foam::PackedBoolList::xfer() -{ - return xferMove(*this); -} - - // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // inline void Foam::PackedBoolList::operator=(const bool val) @@ -173,6 +163,18 @@ inline void Foam::PackedBoolList::operator=(const PackedList<1>& lst) } +inline void Foam::PackedBoolList::operator=(PackedBoolList&& lst) +{ + transfer(lst); +} + + +inline void Foam::PackedBoolList::operator=(PackedList<1>&& lst) +{ + transfer(lst); +} + + inline void Foam::PackedBoolList::operator=(const labelUList& indices) { clear(); diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.C b/src/OpenFOAM/containers/Lists/PackedList/PackedList.C index f9f87b8c00dd54c6950f75e7fc3538124ffa5b18..63c0908961f3c69ebf77e445e851b17e9f56e6cf 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.C +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.C @@ -141,16 +141,16 @@ void Foam::PackedList<nBits>::flip() template<unsigned nBits> -Foam::Xfer<Foam::labelList> Foam::PackedList<nBits>::values() const +Foam::labelList Foam::PackedList<nBits>::values() const { labelList elems(size_); - forAll(*this, i) + for (label i=0; i < size_; ++i) { elems[i] = get(i); } - return elems.xfer(); + return elems; } @@ -522,6 +522,13 @@ void Foam::PackedList<nBits>::operator=(const PackedList<nBits>& lst) } +template<unsigned nBits> +void Foam::PackedList<nBits>::operator=(PackedList<nBits>&& lst) +{ + transfer(lst); +} + + template<unsigned nBits> void Foam::PackedList<nBits>::operator=(const labelUList& lst) { diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H index 2ae542aeaaeac7f00678a11c1a254e10bd8cf0a2..8ffd02e70434dbfaebc90e05d5c80c070b4b8686 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H @@ -235,11 +235,11 @@ public: //- Construct from Istream inline PackedList(Istream& is); - //- Copy constructor + //- Copy construct inline PackedList(const PackedList<nBits>& lst); - //- Construct by transferring the parameter contents - inline PackedList(const Xfer<PackedList<nBits>>& lst); + //- Move construct + inline PackedList(PackedList<nBits>&& lst); //- Construct from a list of labels explicit inline PackedList(const labelUList& lst); @@ -297,7 +297,7 @@ public: unsigned int count() const; //- Return the values as a list of labels - Xfer<labelList> values() const; + labelList values() const; //- Print bit patterns, optionally output unused elements // @@ -356,9 +356,6 @@ public: // and annul the argument list. inline void transfer(PackedList<nBits>& lst); - //- Transfer contents to the Xfer container - inline Xfer<PackedList<nBits>> xfer(); - // IO @@ -407,9 +404,12 @@ public: //- Assignment of all entries to the given value. Takes linear time. inline void operator=(const unsigned int val); - //- Assignment operator. + //- Copy assignment. void operator=(const PackedList<nBits>& lst); + //- Move assignment. + void operator=(PackedList<nBits>&& lst); + //- Assignment operator. void operator=(const labelUList& lst); diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H index 94f91cee4ba1e324bae8f5640d2a33c57bdeeb5d..b4efd00711667359774ddd6403e97601687bd030 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H @@ -223,9 +223,13 @@ inline Foam::PackedList<nBits>::PackedList(const PackedList<nBits>& lst) template<unsigned nBits> -inline Foam::PackedList<nBits>::PackedList(const Xfer<PackedList<nBits>>& lst) +inline Foam::PackedList<nBits>::PackedList(PackedList<nBits>&& lst) +: + PackedListCore(), + StorageList(), + size_(0) { - transfer(lst()); + transfer(lst); } @@ -956,13 +960,6 @@ inline void Foam::PackedList<nBits>::transfer(PackedList<nBits>& lst) } -template<unsigned nBits> -inline Foam::Xfer<Foam::PackedList<nBits>> Foam::PackedList<nBits>::xfer() -{ - return xferMove(*this); -} - - template<unsigned nBits> inline unsigned int Foam::PackedList<nBits>::get(const label i) const {