From 7b769b50357a8ddce3d3afb5c970e415b7dcc3e2 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> Date: Tue, 20 Jan 2009 10:55:39 +0100 Subject: [PATCH] added C++0x-style cbegin(), cend() iterator methods - added STL-compatible resize() method. Should this be the primary entry point? - made [DS]LListBase end iterators private --- .../HashTables/HashTable/HashTable.H | 6 +++ .../HashTables/HashTable/HashTableI.H | 18 +++++++- .../StaticHashTable/StaticHashTable.H | 11 +++-- .../StaticHashTable/StaticHashTableI.H | 18 +++++++- .../linkTypes/DLListBase/DLListBase.C | 6 +-- .../linkTypes/DLListBase/DLListBase.H | 31 ++++++++------ .../linkTypes/DLListBase/DLListBaseI.H | 24 ++++++++--- .../linkTypes/SLListBase/SLListBase.C | 4 +- .../linkTypes/SLListBase/SLListBase.H | 28 +++++++------ .../linkTypes/SLListBase/SLListBaseI.H | 24 ++++++++--- .../Lists/CompactListList/CompactListList.C | 36 +++++++++------- .../Lists/CompactListList/CompactListList.H | 19 +++++++-- .../Lists/CompactListList/CompactListListI.H | 37 +++++++++++++++++ .../Lists/DynamicList/DynamicList.H | 9 ++++ .../Lists/DynamicList/DynamicListI.H | 21 ++++++++++ .../containers/Lists/FixedList/FixedList.H | 34 +++++++++------ .../containers/Lists/FixedList/FixedListI.H | 41 +++++++++++++++++++ src/OpenFOAM/containers/Lists/List/List.H | 6 +++ src/OpenFOAM/containers/Lists/List/ListI.H | 14 +++++++ .../containers/Lists/PackedList/PackedList.H | 3 ++ .../containers/Lists/PackedList/PackedListI.H | 7 ++++ .../containers/Lists/PtrList/PtrList.H | 6 +++ .../containers/Lists/PtrList/PtrListI.H | 7 ++++ src/OpenFOAM/containers/Lists/UList/UList.H | 30 ++++++++------ src/OpenFOAM/containers/Lists/UList/UListI.H | 28 +++++++++++++ .../containers/Lists/UPtrList/UPtrList.H | 8 ++++ .../containers/Lists/UPtrList/UPtrListI.H | 15 ++++++- src/lagrangian/basic/Cloud/Cloud.H | 10 +++++ .../edgeFaceCirculator/edgeFaceCirculator.H | 2 + .../edgeFaceCirculator/edgeFaceCirculatorI.H | 24 +++++++++++ src/meshTools/octree/octree.C | 16 ++++++++ src/meshTools/octree/octree.H | 6 +-- .../UnsortedMeshedSurface.H | 3 ++ 33 files changed, 461 insertions(+), 91 deletions(-) diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index 2fbb548d0e6..457e2f1b7e5 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -384,6 +384,12 @@ public: }; + //- const_iterator set to the beginning of the HashTable + inline const_iterator cbegin() const; + + //- const_iterator set to beyond the end of the HashTable + inline const const_iterator& cend() const; + //- const_iterator set to the beginning of the HashTable inline const_iterator begin() const; diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H index 03359b2fd10..79ff3741453 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H @@ -452,7 +452,7 @@ const Key& Foam::HashTable<T, Key, Hash>::const_iterator::key() template<class T, class Key, class Hash> inline typename Foam::HashTable<T, Key, Hash>::const_iterator -Foam::HashTable<T, Key, Hash>::begin() const +Foam::HashTable<T, Key, Hash>::cbegin() const { label i = 0; @@ -477,6 +477,22 @@ Foam::HashTable<T, Key, Hash>::begin() const } +template<class T, class Key, class Hash> +inline const typename Foam::HashTable<T, Key, Hash>::const_iterator& +Foam::HashTable<T, Key, Hash>::cend() const +{ + return HashTable<T, Key, Hash>::endConstIter_; +} + + +template<class T, class Key, class Hash> +inline typename Foam::HashTable<T, Key, Hash>::const_iterator +Foam::HashTable<T, Key, Hash>::begin() const +{ + return this->cbegin(); +} + + template<class T, class Key, class Hash> inline const typename Foam::HashTable<T, Key, Hash>::const_iterator& Foam::HashTable<T, Key, Hash>::end() const diff --git a/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.H b/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.H index 2816056383e..4513ea02452 100644 --- a/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.H +++ b/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.H @@ -317,19 +317,24 @@ public: }; - //- iterator set to the begining of the StaticHashTable + //- iterator set to the beginning of the StaticHashTable inline iterator begin(); //- iterator set to beyond the end of the StaticHashTable inline const iterator& end(); - //- const_iterator set to the begining of the StaticHashTable + //- const_iterator set to the beginning of the StaticHashTable + inline const_iterator cbegin() const; + + //- const_iterator set to beyond the end of the StaticHashTable + inline const const_iterator& cend() const; + + //- const_iterator set to the beginning of the StaticHashTable inline const_iterator begin() const; //- const_iterator set to beyond the end of the StaticHashTable inline const const_iterator& end() const; - // IOstream Operator friend Istream& operator>> <T, Key, Hash> diff --git a/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTableI.H b/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTableI.H index d9bfaae0b80..329437a07a4 100644 --- a/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTableI.H +++ b/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTableI.H @@ -355,7 +355,7 @@ Foam::StaticHashTable<T, Key, Hash>::end() template<class T, class Key, class Hash> inline typename Foam::StaticHashTable<T, Key, Hash>::const_iterator -Foam::StaticHashTable<T, Key, Hash>::begin() const +Foam::StaticHashTable<T, Key, Hash>::cbegin() const { // Find first non-empty entry forAll(keys_, hashIdx) @@ -377,6 +377,22 @@ Foam::StaticHashTable<T, Key, Hash>::begin() const } +template<class T, class Key, class Hash> +inline const typename Foam::StaticHashTable<T, Key, Hash>::const_iterator& +Foam::StaticHashTable<T, Key, Hash>::cend() const +{ + return StaticHashTable<T, Key, Hash>::endConstIter_; +} + + +template<class T, class Key, class Hash> +inline typename Foam::StaticHashTable<T, Key, Hash>::const_iterator +Foam::StaticHashTable<T, Key, Hash>::begin() const +{ + return this->cbegin(); +} + + template<class T, class Key, class Hash> inline const typename Foam::StaticHashTable<T, Key, Hash>::const_iterator& Foam::StaticHashTable<T, Key, Hash>::end() const diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C index 5c21dfe58e6..78a4313a90a 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C @@ -30,14 +30,14 @@ License #include "IOstreams.H" #include "long.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -Foam::DLListBase::iterator Foam::DLListBase::endIter +Foam::DLListBase::iterator Foam::DLListBase::endIter_ ( const_cast<DLListBase&>(static_cast<const DLListBase&>(DLListBase())) ); -Foam::DLListBase::const_iterator Foam::DLListBase::endConstIter +Foam::DLListBase::const_iterator Foam::DLListBase::endConstIter_ ( static_cast<const DLListBase&>(DLListBase()), reinterpret_cast<const link*>(0) diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H index 475109cc771..ba3423c8e2c 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H @@ -176,7 +176,7 @@ public: // STL iterator - //- An STL iterator + //- An STL-conforming iterator class iterator { friend class DLListBase; @@ -193,16 +193,17 @@ public: //- Copy of the link link curLink_; + // Private Member Functions + + //- Construct for a given SLListBase with NULL element and link. + // Only used to create endIter + inline iterator(DLListBase&); + public: //- Construct for a given DLListBase and link inline iterator(DLListBase&, link*); - //- Construct for a given DLListBase - // setting element and link to NULL. - // Only used to create endIter - inline iterator(DLListBase&); - // Member operators inline void operator=(const iterator&); @@ -217,16 +218,12 @@ public: }; inline iterator begin(); - - //- iterator returned by end() - static iterator endIter; - inline const iterator& end(); // STL const_iterator - //- An STL const_iterator + //- An STL-conforming const_iterator class const_iterator { // Private data @@ -258,12 +255,20 @@ public: inline const_iterator operator++(int); }; + inline const_iterator cbegin() const; + inline const const_iterator& cend() const; + inline const_iterator begin() const; + inline const const_iterator& end() const; + +private: + + //- iterator returned by end() + static iterator endIter_; //- const_iterator returned by end() - static const_iterator endConstIter; + static const_iterator endConstIter_; - inline const const_iterator& end() const; }; diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H index 6692ce5c525..9b80941bf9a 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H @@ -259,14 +259,14 @@ Foam::DLListBase::begin() } else { - return endIter; + return endIter_; } } inline const Foam::DLListBase::iterator& Foam::DLListBase::end() { - return endIter; + return endIter_; } @@ -350,7 +350,7 @@ Foam::DLListBase::const_iterator::operator++(int) inline Foam::DLListBase::const_iterator -Foam::DLListBase::begin() const +Foam::DLListBase::cbegin() const { if (size()) { @@ -358,15 +358,29 @@ Foam::DLListBase::begin() const } else { - return endConstIter; + return endConstIter_; } } +inline const Foam::DLListBase::const_iterator& +Foam::DLListBase::cend() const +{ + return endConstIter_; +} + + +inline Foam::DLListBase::const_iterator +Foam::DLListBase::begin() const +{ + return this->cbegin(); +} + + inline const Foam::DLListBase::const_iterator& Foam::DLListBase::end() const { - return endConstIter; + return endConstIter_; } diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.C b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.C index 75dca644d99..f0fb24baac2 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.C +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.C @@ -29,12 +29,12 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -Foam::SLListBase::iterator Foam::SLListBase::endIter +Foam::SLListBase::iterator Foam::SLListBase::endIter_ ( const_cast<SLListBase&>(static_cast<const SLListBase&>(SLListBase())) ); -Foam::SLListBase::const_iterator Foam::SLListBase::endConstIter +Foam::SLListBase::const_iterator Foam::SLListBase::endConstIter_ ( static_cast<const SLListBase&>(SLListBase()), reinterpret_cast<const link*>(0) diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H index 06f5960faec..4f660a1e4d0 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H @@ -178,16 +178,16 @@ public: //- Copy of the link link curLink_; - public: + // Private Member Functions - //- Construct for a given SLListBase and link - inline iterator(SLListBase&, link*); - - //- Construct for a given SLListBase - // setting element and link to NULL. + //- Construct for a given SLListBase with NULL element and link. // Only used to create endIter inline iterator(SLListBase&); + public: + + //- Construct for a given SLListBase and link + inline iterator(SLListBase&, link*); // Member operators @@ -203,10 +203,6 @@ public: }; inline iterator begin(); - - //- iterator returned by end() - static iterator endIter; - inline const iterator& end(); @@ -245,12 +241,20 @@ public: inline const_iterator operator++(int); }; + inline const_iterator cbegin() const; + inline const const_iterator& cend() const; + inline const_iterator begin() const; + inline const const_iterator& end() const; + +private: + + //- iterator returned by end() + static iterator endIter_; //- const_iterator returned by end() - static const_iterator endConstIter; + static const_iterator endConstIter_; - inline const const_iterator& end() const; }; diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H index ca069a239d7..de34257d342 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H @@ -231,7 +231,7 @@ Foam::SLListBase::begin() } else { - return endIter; + return endIter_; } } @@ -239,7 +239,7 @@ Foam::SLListBase::begin() inline const Foam::SLListBase::iterator& Foam::SLListBase::end() { - return endIter; + return endIter_; } @@ -323,7 +323,7 @@ Foam::SLListBase::const_iterator::operator++(int) inline Foam::SLListBase::const_iterator -Foam::SLListBase::begin() const +Foam::SLListBase::cbegin() const { if (size()) { @@ -331,15 +331,29 @@ Foam::SLListBase::begin() const } else { - return endConstIter; + return endConstIter_; } } +inline const Foam::SLListBase::const_iterator& +Foam::SLListBase::cend() const +{ + return endConstIter_; +} + + +inline Foam::SLListBase::const_iterator +Foam::SLListBase::begin() const +{ + return this->cbegin(); +} + + inline const Foam::SLListBase::const_iterator& Foam::SLListBase::end() const { - return endConstIter; + return endConstIter_; } diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C b/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C index 2602eea95a6..8e802fe48ea 100644 --- a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C +++ b/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C @@ -142,12 +142,17 @@ void Foam::CompactListList<T>::setSize(const label nRows) template<class T> -void Foam::CompactListList<T>::setSize(const label nRows, const label nData) +void Foam::CompactListList<T>::setSize +( + const label nRows, + const label nData +) { offsets_.setSize(nRows); m_.setSize(nData); } + template<class T> void Foam::CompactListList<T>::setSize ( @@ -160,19 +165,6 @@ void Foam::CompactListList<T>::setSize m_.setSize(nData, t); } -template<class T> -Foam::labelList Foam::CompactListList<T>::sizes() const -{ - labelList rowSizes(offsets_.size()); - - label prevOffset = 0; - forAll(offsets_, i) - { - rowSizes[i] = offsets_[i]-prevOffset; - prevOffset = offsets_[i]; - } - return rowSizes; -} template<class T> void Foam::CompactListList<T>::setSize(const UList<label>& rowSizes) @@ -189,6 +181,22 @@ void Foam::CompactListList<T>::setSize(const UList<label>& rowSizes) m_.setSize(sumSize); } + +template<class T> +Foam::labelList Foam::CompactListList<T>::sizes() const +{ + labelList rowSizes(offsets_.size()); + + label prevOffset = 0; + forAll(offsets_, i) + { + rowSizes[i] = offsets_[i]-prevOffset; + prevOffset = offsets_[i]; + } + return rowSizes; +} + + template<class T> void Foam::CompactListList<T>::clear() { diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H b/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H index 18943d268f3..f0a80cc1bd8 100644 --- a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H +++ b/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H @@ -156,15 +156,28 @@ public: //- Reset sizes of CompactListList and value for new elements. void setSize(const label nRows, const label nData, const T&); - //- Return sizes (to be used e.g. for construction) - labelList sizes() const; - //- Reset size of CompactListList. void setSize(const UList<label>& rowSizes); + //- Reset size of CompactListList. + // This form only allows contraction of the CompactListList. + inline void resize(const label nRows); + + //- Reset size of CompactListList. + inline void resize(const label nRows, const label nData); + + //- Reset sizes of CompactListList and value for new elements. + inline void resize(const label nRows, const label nData, const T&); + + //- Reset size of CompactListList. + inline void resize(const UList<label>& rowSizes); + //- Clear the CompactListList, i.e. set sizes to zero. void clear(); + //- Return sizes (to be used e.g. for construction) + labelList sizes() const; + //- Transfer the contents of the argument CompactListList // into this CompactListList and annull the argument list. void transfer(CompactListList<T>&); diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H b/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H index 58e9590199f..dc57627911d 100644 --- a/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H +++ b/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H @@ -176,6 +176,43 @@ inline Foam::Xfer<Foam::CompactListList<T> > Foam::CompactListList<T>::xfer() } +template<class T> +inline void Foam::CompactListList<T>::resize(const label nRows) +{ + this->setSize(nRows); +} + + +template<class T> +inline void Foam::CompactListList<T>::resize +( + const label nRows, + const label nData +) +{ + this->setSize(nRows, nData); +} + + +template<class T> +inline void Foam::CompactListList<T>::resize +( + const label nRows, + const label nData, + const T& t +) +{ + this->setSize(nRows, nData, t); +} + + +template<class T> +inline void Foam::CompactListList<T>::resize(const UList<label>& rowSizes) +{ + this->setSize(rowSizes); +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template<class T> diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H index 1e62ceb96c9..47e7c4b2009 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H @@ -142,6 +142,15 @@ public: //- Alter the addressed list size and fill new space with a constant. inline void setSize(const label, const T&); + //- Alter the addressed list size. + // New space will be allocated if required. + // Use this to resize the list prior to using the operator[] for + // setting values (as per List usage). + inline void resize(const label); + + //- Alter the addressed list size and fill new space with a constant. + inline void resize(const label, const T&); + //- Reserve allocation space for at least this size. // Never shrinks the allocated size, use setCapacity() for that. inline void reserve(const label); diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index 5f65f0e6657..5fe561e0f28 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -207,6 +207,27 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize } +template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> +inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::resize +( + const label nElem +) +{ + this->setSize(nElem); +} + + +template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> +inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::resize +( + const label nElem, + const T& t +) +{ + this->setSize(nElem, t); +} + + template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::clear() { diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index 40f0bb24f09..2e3ddf408bd 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -153,6 +153,10 @@ public: // Edit + //- Dummy resize function + // needed to make FixedList consistent with List + inline void resize(const label); + //- Dummy setSize function // needed to make FixedList consistent with List inline void setSize(const label); @@ -227,12 +231,16 @@ public: //- Random access iterator for traversing FixedList. typedef const T* const_iterator; - //- Return a const_iterator to begin traversing the - // constant FixedList. + //- Return const_iterator to begin traversing the constant FixedList. + inline const_iterator cbegin() const; + + //- Return const_iterator to end traversing the constant FixedList. + inline const_iterator cend() const; + + //- Return const_iterator to begin traversing the constant FixedList. inline const_iterator begin() const; - //- Return a const_iterator to end traversing the - // constant FixedList. + //- Return const_iterator to end traversing the constant FixedList. inline const_iterator end() const; @@ -241,12 +249,10 @@ public: //- Reverse iterator for reverse traversal of FixedList. typedef T* reverse_iterator; - //- Return a reverse_iterator to begin reverse traversing the - // FixedList. + //- Return reverse_iterator to begin reverse traversing the FixedList. inline reverse_iterator rbegin(); - //- Return a reverse_iterator to end reverse traversing the - // FixedList. + //- Return reverse_iterator to end reverse traversing the FixedList. inline reverse_iterator rend(); @@ -255,12 +261,16 @@ public: //- Reverse iterator for reverse traversal of constant FixedList. typedef const T* const_reverse_iterator; - //- Return a const_reverse_iterator to begin reverse traversing the - // FixedList. + //- Return const_reverse_iterator to begin reverse traversing FixedList. + inline const_reverse_iterator crbegin() const; + + //- Return const_reverse_iterator to end reverse traversing FixedList. + inline const_reverse_iterator crend() const; + + //- Return const_reverse_iterator to begin reverse traversing FixedList. inline const_reverse_iterator rbegin() const; - //- Return a const_reverse_iterator to end reverse traversing the - // FixedList. + //- Return const_reverse_iterator to end reverse traversing FixedList. inline const_reverse_iterator rend() const; diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H index e58d500ffde..d618cb6e386 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H @@ -170,6 +170,14 @@ inline void Foam::FixedList<T, Size>::checkIndex(const label i) const } +template<class T, Foam::label Size> +inline void Foam::FixedList<T, Size>::resize(const label s) +{ +# ifdef FULLDEBUG + checkSize(s); +# endif +} + template<class T, Foam::label Size> inline void Foam::FixedList<T, Size>::setSize(const label s) { @@ -276,6 +284,14 @@ Foam::FixedList<T, Size>::begin() const } +template<class T, Foam::label Size> +inline typename Foam::FixedList<T, Size>::const_iterator +Foam::FixedList<T, Size>::cbegin() const +{ + return v_; +} + + template<class T, Foam::label Size> inline typename Foam::FixedList<T, Size>::iterator Foam::FixedList<T, Size>::end() @@ -291,6 +307,15 @@ Foam::FixedList<T, Size>::end() const return &v_[Size]; } + +template<class T, Foam::label Size> +inline typename Foam::FixedList<T, Size>::const_iterator +Foam::FixedList<T, Size>::cend() const +{ + return &v_[Size]; +} + + template<class T, Foam::label Size> inline typename Foam::FixedList<T, Size>::iterator Foam::FixedList<T, Size>::rbegin() @@ -307,6 +332,14 @@ Foam::FixedList<T, Size>::rbegin() const } +template<class T, Foam::label Size> +inline typename Foam::FixedList<T, Size>::const_iterator +Foam::FixedList<T, Size>::crbegin() const +{ + return &v_[Size-1]; +} + + template<class T, Foam::label Size> inline typename Foam::FixedList<T, Size>::iterator Foam::FixedList<T, Size>::rend() @@ -323,6 +356,14 @@ Foam::FixedList<T, Size>::rend() const } +template<class T, Foam::label Size> +inline typename Foam::FixedList<T, Size>::const_iterator +Foam::FixedList<T, Size>::crend() const +{ + return &v_[-1]; +} + + template<class T, Foam::label Size> inline Foam::label Foam::FixedList<T, Size>::size() const { diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index 11431b4daf1..983b2be0081 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -158,6 +158,12 @@ public: // Edit + //- Reset size of List. + inline void resize(const label); + + //- Reset size of List and value for new elements. + inline void resize(const label, const T&); + //- Reset size of List. void setSize(const label); diff --git a/src/OpenFOAM/containers/Lists/List/ListI.H b/src/OpenFOAM/containers/Lists/List/ListI.H index a0b72867081..c3c6ebe4fb6 100644 --- a/src/OpenFOAM/containers/Lists/List/ListI.H +++ b/src/OpenFOAM/containers/Lists/List/ListI.H @@ -47,6 +47,20 @@ inline const Foam::List<T>& Foam::List<T>::null() } +template<class T> +inline void Foam::List<T>::resize(const label newSize) +{ + this->setSize(newSize); +} + + +template<class T> +inline void Foam::List<T>::resize(const label newSize, const T& a) +{ + this->setSize(newSize, a); +} + + template<class T> inline T& Foam::List<T>::newElmt(const label i) { diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H index d2d015ad566..92493d557db 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H @@ -150,6 +150,9 @@ public: //- Reset size of List. void setSize(const label); + //- Reset size of List. + inline void resize(const label); + //- Clear the list, i.e. set size to zero. void clear(); diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H index dc5f18786e8..3ccd2578139 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H @@ -110,6 +110,13 @@ inline Foam::PackedList<nBits>::PackedList(const label size) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template<int nBits> +inline void Foam::PackedList<nBits>::resize(const label size) +{ + this->setSize(size); +} + + template<int nBits> inline Foam::label Foam::PackedList<nBits>::size() const { diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrList.H b/src/OpenFOAM/containers/Lists/PtrList/PtrList.H index 86c7ea8f4d8..5de1345f10d 100644 --- a/src/OpenFOAM/containers/Lists/PtrList/PtrList.H +++ b/src/OpenFOAM/containers/Lists/PtrList/PtrList.H @@ -170,6 +170,12 @@ public: // deleted. void setSize(const label); + //- Reset size of PtrList. This can only be used to set the size + // of an empty PtrList, extend a PtrList, remove entries from + // the end of a PtrList. If the entries are non-empty they are + // deleted. + inline void resize(const label); + //- Clear the PtrList, i.e. set size to zero deleting all the // allocated entries. void clear(); diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrListI.H b/src/OpenFOAM/containers/Lists/PtrList/PtrListI.H index 8dfbe2686ab..d450cdd09fe 100644 --- a/src/OpenFOAM/containers/Lists/PtrList/PtrListI.H +++ b/src/OpenFOAM/containers/Lists/PtrList/PtrListI.H @@ -45,6 +45,13 @@ inline bool Foam::PtrList<T>::empty() const } +template<class T> +inline void Foam::PtrList<T>::resize(const label newSize) +{ + this->setSize(newSize); +} + + template<class T> inline bool Foam::PtrList<T>::set(const label i) const { diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index bf3dc848026..83c0913a5fe 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.H +++ b/src/OpenFOAM/containers/Lists/UList/UList.H @@ -215,12 +215,16 @@ public: //- Random access iterator for traversing UList. typedef const T* const_iterator; - //- Return a const_iterator to begin traversing the - // constant UList. + //- Return const_iterator to begin traversing the constant UList. + inline const_iterator cbegin() const; + + //- Return const_iterator to end traversing the constant UList. + inline const_iterator cend() const; + + //- Return const_iterator to begin traversing the constant UList. inline const_iterator begin() const; - //- Return a const_iterator to end traversing the - // constant UList. + //- Return const_iterator to end traversing the constant UList. inline const_iterator end() const; @@ -229,12 +233,10 @@ public: //- Reverse iterator for reverse traversal of UList. typedef T* reverse_iterator; - //- Return a reverse_iterator to begin reverse traversing the - // UList. + //- Return reverse_iterator to begin reverse traversing the UList. inline reverse_iterator rbegin(); - //- Return a reverse_iterator to end reverse traversing the - // UList. + //- Return reverse_iterator to end reverse traversing the UList. inline reverse_iterator rend(); @@ -243,12 +245,16 @@ public: //- Reverse iterator for reverse traversal of constant UList. typedef const T* const_reverse_iterator; - //- Return a const_reverse_iterator to begin reverse traversing the - // UList. + //- Return const_reverse_iterator to begin reverse traversing the UList. + inline const_reverse_iterator crbegin() const; + + //- Return const_reverse_iterator to end reverse traversing the UList. + inline const_reverse_iterator crend() const; + + //- Return const_reverse_iterator to begin reverse traversing the UList. inline const_reverse_iterator rbegin() const; - //- Return a const_reverse_iterator to end reverse traversing the - // UList. + //- Return const_reverse_iterator to end reverse traversing the UList. inline const_reverse_iterator rend() const; diff --git a/src/OpenFOAM/containers/Lists/UList/UListI.H b/src/OpenFOAM/containers/Lists/UList/UListI.H index e6fbb5230b9..7d8d87006c8 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListI.H +++ b/src/OpenFOAM/containers/Lists/UList/UListI.H @@ -161,6 +161,13 @@ Foam::UList<T>::begin() const return v_; } +template<class T> +inline typename Foam::UList<T>::const_iterator +Foam::UList<T>::cbegin() const +{ + return v_; +} + template<class T> inline typename Foam::UList<T>::iterator Foam::UList<T>::end() @@ -175,6 +182,13 @@ Foam::UList<T>::end() const return &v_[size_]; } +template<class T> +inline typename Foam::UList<T>::const_iterator +Foam::UList<T>::cend() const +{ + return &v_[size_]; +} + template<class T> inline typename Foam::UList<T>::iterator Foam::UList<T>::rbegin() @@ -189,6 +203,13 @@ Foam::UList<T>::rbegin() const return &v_[size_-1]; } +template<class T> +inline typename Foam::UList<T>::const_iterator +Foam::UList<T>::crbegin() const +{ + return &v_[size_-1]; +} + template<class T> inline typename Foam::UList<T>::iterator Foam::UList<T>::rend() @@ -203,6 +224,13 @@ Foam::UList<T>::rend() const return &v_[-1]; } +template<class T> +inline typename Foam::UList<T>::const_iterator +Foam::UList<T>::crend() const +{ + return &v_[-1]; +} + template<class T> inline Foam::label Foam::UList<T>::size() const { diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H index 05e0078701d..cfcae367184 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H @@ -124,6 +124,9 @@ public: //- Return the number of elements in the UPtrList inline label size() const; + //- Return true if the UPtrList is empty (i.e., if size() == 0). + inline bool empty() const; + // Edit @@ -132,6 +135,11 @@ public: // the end of a UPtrList. void setSize(const label); + //- Reset size of UPtrList. This can only be used to set the size + // of an empty UPtrList, extend a UPtrList, remove entries from + // the end of a UPtrList. + inline void resize(const label); + //- Clear the UPtrList, i.e. set size to zero void clear(); diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrListI.H b/src/OpenFOAM/containers/Lists/UPtrList/UPtrListI.H index 73663843d86..859f54fce5f 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrListI.H +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrListI.H @@ -35,13 +35,26 @@ inline Foam::label Foam::UPtrList<T>::size() const } +template<class T> +inline bool Foam::UPtrList<T>::empty() const +{ + return ptrs_.empty(); +} + + +template<class T> +inline void Foam::UPtrList<T>::resize(const label newSize) +{ + this->setSize(newSize); +} + + template<class T> inline bool Foam::UPtrList<T>::set(const label i) const { return ptrs_[i] != NULL; } - template<class T> inline T* Foam::UPtrList<T>::set(const label i, T* ptr) { diff --git a/src/lagrangian/basic/Cloud/Cloud.H b/src/lagrangian/basic/Cloud/Cloud.H index ca74393cabf..684ceb979e3 100644 --- a/src/lagrangian/basic/Cloud/Cloud.H +++ b/src/lagrangian/basic/Cloud/Cloud.H @@ -189,11 +189,21 @@ public: return IDLList<ParticleType>::begin(); }; + const const_iterator cbegin() const + { + return IDLList<ParticleType>::cbegin(); + }; + const const_iterator end() const { return IDLList<ParticleType>::end(); }; + const const_iterator cend() const + { + return IDLList<ParticleType>::cend(); + }; + iterator begin() { return IDLList<ParticleType>::begin(); diff --git a/src/meshTools/edgeFaceCirculator/edgeFaceCirculator.H b/src/meshTools/edgeFaceCirculator/edgeFaceCirculator.H index a2a5ec7abe7..644b0e84a05 100644 --- a/src/meshTools/edgeFaceCirculator/edgeFaceCirculator.H +++ b/src/meshTools/edgeFaceCirculator/edgeFaceCirculator.H @@ -192,9 +192,11 @@ public: // the current face. For boundary edges this is the first boundary face // reached from walking back (i.e. in opposite direction to ++) inline edgeFaceCirculator begin() const; + inline edgeFaceCirculator cbegin() const; //- iterator set to beyond the end of the walk. inline const edgeFaceCirculator& end() const; + inline const edgeFaceCirculator& cend() const; }; diff --git a/src/meshTools/edgeFaceCirculator/edgeFaceCirculatorI.H b/src/meshTools/edgeFaceCirculator/edgeFaceCirculatorI.H index 558d0c75261..d8511c4fb67 100644 --- a/src/meshTools/edgeFaceCirculator/edgeFaceCirculatorI.H +++ b/src/meshTools/edgeFaceCirculator/edgeFaceCirculatorI.H @@ -419,10 +419,34 @@ Foam::edgeFaceCirculator Foam::edgeFaceCirculator::begin() const } +Foam::edgeFaceCirculator Foam::edgeFaceCirculator::cbegin() const +{ + edgeFaceCirculator iter + ( + mesh_, + faceLabel_, + ownerSide_, + index_, + isBoundaryEdge_ + ); + + if (isBoundaryEdge_) + { + iter.setCanonical(); + } + return iter; +} + + const Foam::edgeFaceCirculator& Foam::edgeFaceCirculator::end() const { return endConstIter; } +const Foam::edgeFaceCirculator& Foam::edgeFaceCirculator::cend() const +{ + return endConstIter; +} + // ************************************************************************* // diff --git a/src/meshTools/octree/octree.C b/src/meshTools/octree/octree.C index 554af3ad5ab..fa180fd9c12 100644 --- a/src/meshTools/octree/octree.C +++ b/src/meshTools/octree/octree.C @@ -879,6 +879,14 @@ Foam::octree<Type>::begin() const } +template <class Type> +typename Foam::octree<Type>::const_iterator +Foam::octree<Type>::cbegin() const +{ + return const_iterator(*this, 0); +} + + template <class Type> const typename Foam::octree<Type>::const_iterator& Foam::octree<Type>::end() const @@ -887,6 +895,14 @@ Foam::octree<Type>::end() const } +template <class Type> +const typename Foam::octree<Type>::const_iterator& +Foam::octree<Type>::cend() const +{ + return octree<Type>::endConstIter_; +} + + // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // template <class Type> diff --git a/src/meshTools/octree/octree.H b/src/meshTools/octree/octree.H index 33c62def017..8f797232422 100644 --- a/src/meshTools/octree/octree.H +++ b/src/meshTools/octree/octree.H @@ -445,10 +445,6 @@ public: //- Construct for a given octree and index const_iterator(const octree&, label); - // Member functions - - const_iterator begin() const; - // Member operators void operator=(const const_iterator&); @@ -465,9 +461,11 @@ public: //- const_iterator set to the begining of the octree inline const_iterator begin() const; + inline const_iterator cbegin() const; //- const_iterator set to beyond the end of the octree inline const const_iterator& end() const; + inline const const_iterator& cend() const; // IOstream Operators diff --git a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H index a2fb0c7d1f2..bd692647abe 100644 --- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H +++ b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H @@ -102,6 +102,9 @@ private: // Private member functions + //- Disable resize with value + void resize(const label, const Face&); + //- Disable setSize with value void setSize(const label, const Face&); -- GitLab