diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedList.C b/src/OpenFOAM/containers/Bits/PackedList/PackedList.C index 2a28e4f064..0a76e3c93c 100644 --- a/src/OpenFOAM/containers/Bits/PackedList/PackedList.C +++ b/src/OpenFOAM/containers/Bits/PackedList/PackedList.C @@ -123,10 +123,10 @@ bool Foam::PackedList::uniform() const } else if (nblocks > 1) { - // Check all blocks that are completely occupied: (nblocks-1) - const unsigned int blockval = - BitOps::repeat_value(val); + // Fill value for complete blocks + const unsigned int blockval = repeated_value(val); + // Check each complete block (nblocks-1) for (label blocki = 0; identical && blocki < (nblocks-1); ++blocki) { identical = (blocks_[blocki] == blockval); diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedList.H b/src/OpenFOAM/containers/Bits/PackedList/PackedList.H index f4d01f94dd..709f0f90d4 100644 --- a/src/OpenFOAM/containers/Bits/PackedList/PackedList.H +++ b/src/OpenFOAM/containers/Bits/PackedList/PackedList.H @@ -109,9 +109,6 @@ namespace Foam template class PackedList; class labelRange; -class Istream; -class Ostream; - template Istream& operator>>(Istream& is, PackedList& list); @@ -136,9 +133,11 @@ public: // Types and dimension information //- The storage block type for bit elements + // \note Type name compatibility with boost::dynamic_bitset typedef unsigned int block_type; //- The number of bits in a single block + // \note Type name compatibility with boost::dynamic_bitset static constexpr unsigned bits_per_block = (std::numeric_limits::digits); @@ -219,6 +218,9 @@ protected: // This \a rubbish may have arisen from block-wise operations etc. inline void clear_trailing_bits(); + //- Copy assignment + inline void copyAssign(const PackedList& rhs); + public: @@ -335,11 +337,8 @@ public: // Edit - //- Assign all entries to the given value. Takes linear time. - inline void assign(const unsigned int val); - - //- Copy assignment. - inline void assign(const PackedList& rhs); + //- Assign all entries to the given value. + inline void fill(const unsigned int val); //- Trim any trailing zero elements, optionally specifying a //- a minimum position, below which trimming will not occur. @@ -348,6 +347,7 @@ public: inline bool trim(label minpos=-1); //- Clear all bits but do not adjust the addressable size. + // \note Method name compatibility with boost::dynamic_bitset inline void reset(); //- Alter the size of the underlying storage. @@ -359,9 +359,6 @@ public: // Optionally specify a value for new elements. inline void resize(const label nElem, const unsigned int val = 0u); - //- Alias for resize() - inline void setSize(const label nElem, const unsigned int val = 0u); - //- Reserve allocation space for at least this size. // Never shrinks the allocated size. // The list size is adjusted as per DynamicList with @@ -382,7 +379,7 @@ public: inline void swap(PackedList& rhs); //- Transfer the contents of the argument list into this list - // and annul the argument list. + //- and annul the argument list. inline void transfer(PackedList& rhs); @@ -435,15 +432,15 @@ public: // Fatal for out-of-range indices inline reference operator[](const label i); - //- Assignment of all entries to the given value. Takes linear time. - inline void operator=(const unsigned int val); - //- Copy assignment. inline void operator=(const PackedList& lst); //- Move assignment. inline void operator=(PackedList&& lst); + //- Assign all entries to the given value. fill() + inline void operator=(const unsigned int val); + // Access helpers @@ -509,6 +506,23 @@ public: Istream& is, PackedList& list ); + + + // Housekeeping + + //- Deprecated(2020-11) use fill() + // \deprecated(2020-11) use fill() + void assign(const unsigned int val) { this->fill(val); } + + //- Deprecated(2020-11) use operator= + // \deprecated(2020-11) use operator= + void assign(const PackedList& rhs) { (*this) = rhs; } + + //- Alias for resize() + void setSize(const label len, unsigned int val = 0u) + { + resize(len, val); + } }; diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H b/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H index 4fe51d14e8..92529fdb0e 100644 --- a/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H +++ b/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -138,24 +138,35 @@ inline bool Foam::PackedList::trim(label minpos) } +template +inline void Foam::PackedList::copyAssign(const PackedList& rhs) +{ + // Self-assignment silently ignored + blocks_ = rhs.blocks_; + size_ = rhs.size_; +} + + // * * * * * * * * * * * * * * * Specializations * * * * * * * * * * * * * * // namespace Foam { - template<> inline unsigned int PackedList<1>::repeated_value(unsigned val) - { - return (val ? ~0u : 0u); - } - template<> inline unsigned int PackedList<1>::readValue(Istream& is) - { - return readBool(is); - } +// constexpr noexcept +template<> inline unsigned int PackedList<1>::repeated_value(unsigned val) +{ + return (val ? ~0u : 0u); +} - template<> inline void PackedList<1>::setPair(Istream& is) - { - set(readLabel(is), true); - } +template<> inline unsigned int PackedList<1>::readValue(Istream& is) +{ + return readBool(is); +} + +template<> inline void PackedList<1>::setPair(Istream& is) +{ + set(readLabel(is), true); +} } // End namespace Foam @@ -446,17 +457,6 @@ inline void Foam::PackedList::resize } -template -inline void Foam::PackedList::setSize -( - const label newSize, - const unsigned int val -) -{ - resize(newSize, val); -} - - template inline void Foam::PackedList::setCapacity(const label numElem) { @@ -680,41 +680,27 @@ inline unsigned int Foam::PackedList::remove() template -inline void Foam::PackedList::assign(const unsigned int val) +inline void Foam::PackedList::fill(const unsigned int val) { + if (empty()) + { + return; // Trivial case + } + const label nblocks = num_blocks(size()); - // Trivial cases first - if (!nblocks) - { - return; - } - else if (!val) - { - for (label blocki=0; blocki < nblocks; ++blocki) - { - blocks_[blocki] = 0u; - } - return; - } - // Fill value for complete blocks - const unsigned int blockval = repeated_value(val); + const unsigned int blockval = (val ? repeated_value(val) : 0u); for (label blocki=0; blocki < nblocks; ++blocki) { blocks_[blocki] = blockval; } - clear_trailing_bits(); -} - - -template -inline void Foam::PackedList::assign(const PackedList& list) -{ - blocks_ = list.blocks_; - size_ = list.size_; + if (val) + { + clear_trailing_bits(); + } } @@ -738,17 +724,10 @@ Foam::PackedList::operator[](const label i) } -template -inline void Foam::PackedList::operator=(const unsigned int val) -{ - assign(val); -} - - template inline void Foam::PackedList::operator=(const PackedList& rhs) { - assign(rhs); + copyAssign(rhs); } @@ -759,6 +738,13 @@ inline void Foam::PackedList::operator=(PackedList&& rhs) } +template +inline void Foam::PackedList::operator=(const unsigned int val) +{ + fill(val); +} + + // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // template diff --git a/src/OpenFOAM/containers/Bits/bitSet/bitSet.C b/src/OpenFOAM/containers/Bits/bitSet/bitSet.C index b8300bcca8..ac1a8017b3 100644 --- a/src/OpenFOAM/containers/Bits/bitSet/bitSet.C +++ b/src/OpenFOAM/containers/Bits/bitSet/bitSet.C @@ -329,8 +329,8 @@ void Foam::bitSet::assign(const UList& bools) { const label len = bools.size(); + clear(); resize(len); - assign(false); // Could also handle block-wise (in the future?) diff --git a/src/OpenFOAM/containers/Bits/bitSet/bitSet.H b/src/OpenFOAM/containers/Bits/bitSet/bitSet.H index 2921a02e23..119d211298 100644 --- a/src/OpenFOAM/containers/Bits/bitSet/bitSet.H +++ b/src/OpenFOAM/containers/Bits/bitSet/bitSet.H @@ -56,7 +56,6 @@ namespace Foam // Forward Declarations class bitSet; -class labelRange; /*---------------------------------------------------------------------------*\ Class bitSet Declaration @@ -66,8 +65,6 @@ class bitSet : public PackedList<1> { -private: - // Private Member Functions //- Find the first block with a '0' bit @@ -218,12 +215,15 @@ public: // Query //- True if all bits in this bitset are set or if the set is empty. + // \note Method name compatibility with boost::dynamic_bitset inline bool all() const; //- True if any bits in this bitset are set. + // \note Method name compatibility with boost::dynamic_bitset inline bool any() const; //- True if no bits in this bitset are set. + // \note Method name compatibility with boost::dynamic_bitset inline bool none() const; //- True if all entries have identical values, and the set is non-empty @@ -232,6 +232,7 @@ public: //- Count number of bits set. // \param on can be set to false to count the number of unset bits // instead. + // \note Method name compatibility with boost::dynamic_bitset inline unsigned int count(const bool on=true) const; //- True if any bits in the other bitset intersect (are the same). @@ -292,7 +293,7 @@ public: // Assignment //- Assign all entries to the given value. - inline void assign(const bool val); + inline void fill(const bool val); //- Copy assign all entries from a list of bools. void assign(const UList& bools); @@ -544,15 +545,15 @@ public: // Fatal for out-of-range indices inline reference operator[](const label i); - //- Assignment of all entries to the given value. - inline bitSet& operator=(const bool val); - //- Copy assignment inline bitSet& operator=(const bitSet& bitset); //- Move assignment inline bitSet& operator=(bitSet&& bitset); + //- Assign all entries to the given value. fill() + inline bitSet& operator=(const bool val); + //- Bitwise-AND all the bits in other with the bits in this bitset. // The operands may have dissimilar sizes without affecting the size // of the set. @@ -591,6 +592,13 @@ public: { return *this; } + + + // Housekeeping + + //- Deprecated(2020-11) use fill() + // \deprecated(2020-11) use fill() + void assign(const unsigned int val) { this->fill(val); } }; diff --git a/src/OpenFOAM/containers/Bits/bitSet/bitSetI.H b/src/OpenFOAM/containers/Bits/bitSet/bitSetI.H index b52f52d55a..acad8c5ec9 100644 --- a/src/OpenFOAM/containers/Bits/bitSet/bitSetI.H +++ b/src/OpenFOAM/containers/Bits/bitSet/bitSetI.H @@ -90,7 +90,7 @@ inline Foam::bitSet::bitSet(const label n, const bool val) : bitSet(n) { - if (val) assign(val); + if (val) fill(val); } @@ -539,7 +539,7 @@ inline void Foam::bitSet::transfer(bitSet& bitset) } -inline void Foam::bitSet::assign(const bool val) +inline void Foam::bitSet::fill(const bool val) { if (empty()) { @@ -548,21 +548,18 @@ inline void Foam::bitSet::assign(const bool val) const label nblocks = num_blocks(size()); + // Fill value for complete blocks + const unsigned int blockval = (val ? ~0u : 0u); + + for (label blocki=0; blocki < nblocks; ++blocki) + { + blocks_[blocki] = blockval; + } + if (val) { - for (label blocki=0; blocki < nblocks; ++blocki) - { - blocks_[blocki] = (~0u); - } clear_trailing_bits(); } - else - { - for (label blocki=0; blocki < nblocks; ++blocki) - { - blocks_[blocki] = (0u); - } - } } @@ -691,13 +688,6 @@ inline Foam::bitSet::reference Foam::bitSet::operator[](const label i) } -inline Foam::bitSet& Foam::bitSet::operator=(const bool val) -{ - PackedList<1>::operator=(val); - return *this; -} - - inline Foam::bitSet& Foam::bitSet::operator=(const bitSet& bitset) { PackedList<1>::operator=(bitset); @@ -712,6 +702,13 @@ inline Foam::bitSet& Foam::bitSet::operator=(bitSet&& bitset) } +inline Foam::bitSet& Foam::bitSet::operator=(const bool val) +{ + fill(val); + return *this; +} + + inline Foam::bitSet& Foam::bitSet::operator&=(const bitSet& other) { return andEq(other); diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index c3518d70d9..3944c2c990 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -90,7 +90,7 @@ template inline Foam::DynamicList::DynamicList ( const label nElem, - const zero + const Foam::zero ) : List(nElem, Zero), @@ -762,7 +762,7 @@ inline void Foam::DynamicList::operator= template inline void Foam::DynamicList::operator= ( - const zero + const Foam::zero ) { UList::operator=(Zero); diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index ac652d033d..ad6fb893a0 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -275,12 +275,18 @@ public: // Edit - //- Dummy resize function, to make FixedList consistent with List + //- Dummy function, to make FixedList consistent with List inline void resize(const label n); - //- Dummy setSize function, to make FixedList consistent with List + //- Dummy function, to make FixedList consistent with List inline void setSize(const label n); + //- Assign all entries to the given value + inline void fill(const T& val); + + //- Assign all entries to zero + inline void fill(const Foam::zero); + //- Move element to the first position. void moveFirst(const label i); @@ -318,9 +324,12 @@ public: //- Assignment to an initializer list. Takes linear time inline void operator=(std::initializer_list list); - //- Assignment of all entries to the given value + //- Assign all entries to the given value. fill() inline void operator=(const T& val); + //- Assign all entries to zero. fill() + inline void operator=(const Foam::zero); + //- Copy assignment inline void operator=(const FixedList& list); diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H index e93be1b5fa..47e629af90 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H @@ -45,20 +45,14 @@ inline const Foam::FixedList& Foam::FixedList::null() template inline Foam::FixedList::FixedList(const T& val) { - for (unsigned i=0; ifill(val); } template inline Foam::FixedList::FixedList(const Foam::zero) { - for (unsigned i=0; ifill(Zero); } @@ -342,6 +336,26 @@ inline void Foam::FixedList::setSize(const label n) } +template +inline void Foam::FixedList::fill(const T& val) +{ + for (unsigned i=0; i +inline void Foam::FixedList::fill(const Foam::zero) +{ + for (unsigned i=0; i inline void Foam::FixedList::swap(FixedList& list) { @@ -443,12 +457,17 @@ inline void Foam::FixedList::operator=(std::initializer_list list) template inline void Foam::FixedList::operator=(const T& val) { - for (unsigned i=0; ifill(val); } + +template +inline void Foam::FixedList::operator=(const Foam::zero) +{ + this->fill(Zero); +} + + template inline void Foam::FixedList::operator=(const FixedList& list) { diff --git a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H index 9739690e62..a868fcf3a4 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H +++ b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H @@ -93,7 +93,7 @@ public: //- Move construct inline PtrDynList(PtrDynList&& list); - //- Take ownerskip of pointers in the list, set old pointers to null. + //- Take ownership of pointers in the list, set old pointers to null. inline explicit PtrDynList(UList& list); diff --git a/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H b/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H index cc5cb25af0..e9bf294a90 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H +++ b/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H @@ -99,7 +99,7 @@ public: //- Move construct inline PtrList(PtrList&& list); - //- Take ownerskip of pointers in the list, set old pointers to null. + //- Take ownership of pointers in the list, set old pointers to null. inline explicit PtrList(UList& list); //- Copy construct using 'clone()' method on each element diff --git a/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H b/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H index bcf4470e9f..d726d5de9c 100644 --- a/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H +++ b/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H @@ -90,7 +90,7 @@ template inline Foam::DynamicField::DynamicField ( const label len, - const zero + const Foam::zero ) : Field(len, Zero),