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
This commit is contained in:
Mark Olesen
2009-01-20 10:55:39 +01:00
parent 19fc795489
commit 7b769b5035
33 changed files with 461 additions and 91 deletions

View File

@ -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 //- const_iterator set to the beginning of the HashTable
inline const_iterator begin() const; inline const_iterator begin() const;

View File

@ -452,7 +452,7 @@ const Key& Foam::HashTable<T, Key, Hash>::const_iterator::key()
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
inline typename Foam::HashTable<T, Key, Hash>::const_iterator 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; 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> template<class T, class Key, class Hash>
inline const typename Foam::HashTable<T, Key, Hash>::const_iterator& inline const typename Foam::HashTable<T, Key, Hash>::const_iterator&
Foam::HashTable<T, Key, Hash>::end() const Foam::HashTable<T, Key, Hash>::end() const

View File

@ -317,19 +317,24 @@ public:
}; };
//- iterator set to the begining of the StaticHashTable //- iterator set to the beginning of the StaticHashTable
inline iterator begin(); inline iterator begin();
//- iterator set to beyond the end of the StaticHashTable //- iterator set to beyond the end of the StaticHashTable
inline const iterator& end(); 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; inline const_iterator begin() const;
//- const_iterator set to beyond the end of the StaticHashTable //- const_iterator set to beyond the end of the StaticHashTable
inline const const_iterator& end() const; inline const const_iterator& end() const;
// IOstream Operator // IOstream Operator
friend Istream& operator>> <T, Key, Hash> friend Istream& operator>> <T, Key, Hash>

View File

@ -355,7 +355,7 @@ Foam::StaticHashTable<T, Key, Hash>::end()
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
inline typename Foam::StaticHashTable<T, Key, Hash>::const_iterator 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 // Find first non-empty entry
forAll(keys_, hashIdx) 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> template<class T, class Key, class Hash>
inline const typename Foam::StaticHashTable<T, Key, Hash>::const_iterator& inline const typename Foam::StaticHashTable<T, Key, Hash>::const_iterator&
Foam::StaticHashTable<T, Key, Hash>::end() const Foam::StaticHashTable<T, Key, Hash>::end() const

View File

@ -30,14 +30,14 @@ License
#include "IOstreams.H" #include "IOstreams.H"
#include "long.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())) 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()), static_cast<const DLListBase&>(DLListBase()),
reinterpret_cast<const link*>(0) reinterpret_cast<const link*>(0)

View File

@ -176,7 +176,7 @@ public:
// STL iterator // STL iterator
//- An STL iterator //- An STL-conforming iterator
class iterator class iterator
{ {
friend class DLListBase; friend class DLListBase;
@ -193,16 +193,17 @@ public:
//- Copy of the link //- Copy of the link
link curLink_; link curLink_;
// Private Member Functions
//- Construct for a given SLListBase with NULL element and link.
// Only used to create endIter
inline iterator(DLListBase&);
public: public:
//- Construct for a given DLListBase and link //- Construct for a given DLListBase and link
inline iterator(DLListBase&, 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 // Member operators
inline void operator=(const iterator&); inline void operator=(const iterator&);
@ -217,16 +218,12 @@ public:
}; };
inline iterator begin(); inline iterator begin();
//- iterator returned by end()
static iterator endIter;
inline const iterator& end(); inline const iterator& end();
// STL const_iterator // STL const_iterator
//- An STL const_iterator //- An STL-conforming const_iterator
class const_iterator class const_iterator
{ {
// Private data // Private data
@ -258,12 +255,20 @@ public:
inline const_iterator operator++(int); inline const_iterator operator++(int);
}; };
inline const_iterator cbegin() const;
inline const const_iterator& cend() const;
inline const_iterator begin() 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() //- const_iterator returned by end()
static const_iterator endConstIter; static const_iterator endConstIter_;
inline const const_iterator& end() const;
}; };

View File

@ -259,14 +259,14 @@ Foam::DLListBase::begin()
} }
else else
{ {
return endIter; return endIter_;
} }
} }
inline const Foam::DLListBase::iterator& Foam::DLListBase::end() 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 inline Foam::DLListBase::const_iterator
Foam::DLListBase::begin() const Foam::DLListBase::cbegin() const
{ {
if (size()) if (size())
{ {
@ -358,15 +358,29 @@ Foam::DLListBase::begin() const
} }
else 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& inline const Foam::DLListBase::const_iterator&
Foam::DLListBase::end() const Foam::DLListBase::end() const
{ {
return endConstIter; return endConstIter_;
} }

View File

@ -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())) 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()), static_cast<const SLListBase&>(SLListBase()),
reinterpret_cast<const link*>(0) reinterpret_cast<const link*>(0)

View File

@ -178,17 +178,17 @@ public:
//- Copy of the link //- Copy of the link
link curLink_; link curLink_;
// Private Member Functions
//- Construct for a given SLListBase with NULL element and link.
// Only used to create endIter
inline iterator(SLListBase&);
public: public:
//- Construct for a given SLListBase and link //- Construct for a given SLListBase and link
inline iterator(SLListBase&, link*); inline iterator(SLListBase&, link*);
//- Construct for a given SLListBase
// setting element and link to NULL.
// Only used to create endIter
inline iterator(SLListBase&);
// Member operators // Member operators
inline void operator=(const iterator&); inline void operator=(const iterator&);
@ -203,10 +203,6 @@ public:
}; };
inline iterator begin(); inline iterator begin();
//- iterator returned by end()
static iterator endIter;
inline const iterator& end(); inline const iterator& end();
@ -245,12 +241,20 @@ public:
inline const_iterator operator++(int); inline const_iterator operator++(int);
}; };
inline const_iterator cbegin() const;
inline const const_iterator& cend() const;
inline const_iterator begin() 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() //- const_iterator returned by end()
static const_iterator endConstIter; static const_iterator endConstIter_;
inline const const_iterator& end() const;
}; };

View File

@ -231,7 +231,7 @@ Foam::SLListBase::begin()
} }
else else
{ {
return endIter; return endIter_;
} }
} }
@ -239,7 +239,7 @@ Foam::SLListBase::begin()
inline const Foam::SLListBase::iterator& inline const Foam::SLListBase::iterator&
Foam::SLListBase::end() Foam::SLListBase::end()
{ {
return endIter; return endIter_;
} }
@ -323,7 +323,7 @@ Foam::SLListBase::const_iterator::operator++(int)
inline Foam::SLListBase::const_iterator inline Foam::SLListBase::const_iterator
Foam::SLListBase::begin() const Foam::SLListBase::cbegin() const
{ {
if (size()) if (size())
{ {
@ -331,15 +331,29 @@ Foam::SLListBase::begin() const
} }
else 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& inline const Foam::SLListBase::const_iterator&
Foam::SLListBase::end() const Foam::SLListBase::end() const
{ {
return endConstIter; return endConstIter_;
} }

View File

@ -142,12 +142,17 @@ void Foam::CompactListList<T>::setSize(const label nRows)
template<class T> 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); offsets_.setSize(nRows);
m_.setSize(nData); m_.setSize(nData);
} }
template<class T> template<class T>
void Foam::CompactListList<T>::setSize void Foam::CompactListList<T>::setSize
( (
@ -160,19 +165,6 @@ void Foam::CompactListList<T>::setSize
m_.setSize(nData, t); 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> template<class T>
void Foam::CompactListList<T>::setSize(const UList<label>& rowSizes) 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); 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> template<class T>
void Foam::CompactListList<T>::clear() void Foam::CompactListList<T>::clear()
{ {

View File

@ -156,15 +156,28 @@ public:
//- Reset sizes of CompactListList and value for new elements. //- Reset sizes of CompactListList and value for new elements.
void setSize(const label nRows, const label nData, const T&); 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. //- Reset size of CompactListList.
void setSize(const UList<label>& rowSizes); 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. //- Clear the CompactListList, i.e. set sizes to zero.
void clear(); void clear();
//- Return sizes (to be used e.g. for construction)
labelList sizes() const;
//- Transfer the contents of the argument CompactListList //- Transfer the contents of the argument CompactListList
// into this CompactListList and annull the argument list. // into this CompactListList and annull the argument list.
void transfer(CompactListList<T>&); void transfer(CompactListList<T>&);

View File

@ -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 * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T> template<class T>

View File

@ -142,6 +142,15 @@ public:
//- Alter the addressed list size and fill new space with a constant. //- Alter the addressed list size and fill new space with a constant.
inline void setSize(const label, const T&); 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. //- Reserve allocation space for at least this size.
// Never shrinks the allocated size, use setCapacity() for that. // Never shrinks the allocated size, use setCapacity() for that.
inline void reserve(const label); inline void reserve(const label);

View File

@ -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> template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::clear() inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::clear()
{ {

View File

@ -153,6 +153,10 @@ public:
// Edit // Edit
//- Dummy resize function
// needed to make FixedList consistent with List
inline void resize(const label);
//- Dummy setSize function //- Dummy setSize function
// needed to make FixedList consistent with List // needed to make FixedList consistent with List
inline void setSize(const label); inline void setSize(const label);
@ -227,12 +231,16 @@ public:
//- Random access iterator for traversing FixedList. //- Random access iterator for traversing FixedList.
typedef const T* const_iterator; typedef const T* const_iterator;
//- Return a const_iterator to begin traversing the //- Return const_iterator to begin traversing the constant FixedList.
// 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; inline const_iterator begin() const;
//- Return a const_iterator to end traversing the //- Return const_iterator to end traversing the constant FixedList.
// constant FixedList.
inline const_iterator end() const; inline const_iterator end() const;
@ -241,12 +249,10 @@ public:
//- Reverse iterator for reverse traversal of FixedList. //- Reverse iterator for reverse traversal of FixedList.
typedef T* reverse_iterator; typedef T* reverse_iterator;
//- Return a reverse_iterator to begin reverse traversing the //- Return reverse_iterator to begin reverse traversing the FixedList.
// FixedList.
inline reverse_iterator rbegin(); inline reverse_iterator rbegin();
//- Return a reverse_iterator to end reverse traversing the //- Return reverse_iterator to end reverse traversing the FixedList.
// FixedList.
inline reverse_iterator rend(); inline reverse_iterator rend();
@ -255,12 +261,16 @@ public:
//- Reverse iterator for reverse traversal of constant FixedList. //- Reverse iterator for reverse traversal of constant FixedList.
typedef const T* const_reverse_iterator; typedef const T* const_reverse_iterator;
//- Return a const_reverse_iterator to begin reverse traversing the //- Return const_reverse_iterator to begin reverse traversing FixedList.
// 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; inline const_reverse_iterator rbegin() const;
//- Return a const_reverse_iterator to end reverse traversing the //- Return const_reverse_iterator to end reverse traversing FixedList.
// FixedList.
inline const_reverse_iterator rend() const; inline const_reverse_iterator rend() const;

View File

@ -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> template<class T, Foam::label Size>
inline void Foam::FixedList<T, Size>::setSize(const label s) 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> template<class T, Foam::label Size>
inline typename Foam::FixedList<T, Size>::iterator inline typename Foam::FixedList<T, Size>::iterator
Foam::FixedList<T, Size>::end() Foam::FixedList<T, Size>::end()
@ -291,6 +307,15 @@ Foam::FixedList<T, Size>::end() const
return &v_[Size]; 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> template<class T, Foam::label Size>
inline typename Foam::FixedList<T, Size>::iterator inline typename Foam::FixedList<T, Size>::iterator
Foam::FixedList<T, Size>::rbegin() 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> template<class T, Foam::label Size>
inline typename Foam::FixedList<T, Size>::iterator inline typename Foam::FixedList<T, Size>::iterator
Foam::FixedList<T, Size>::rend() 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> template<class T, Foam::label Size>
inline Foam::label Foam::FixedList<T, Size>::size() const inline Foam::label Foam::FixedList<T, Size>::size() const
{ {

View File

@ -158,6 +158,12 @@ public:
// Edit // 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. //- Reset size of List.
void setSize(const label); void setSize(const label);

View File

@ -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> template<class T>
inline T& Foam::List<T>::newElmt(const label i) inline T& Foam::List<T>::newElmt(const label i)
{ {

View File

@ -150,6 +150,9 @@ public:
//- Reset size of List. //- Reset size of List.
void setSize(const label); void setSize(const label);
//- Reset size of List.
inline void resize(const label);
//- Clear the list, i.e. set size to zero. //- Clear the list, i.e. set size to zero.
void clear(); void clear();

View File

@ -110,6 +110,13 @@ inline Foam::PackedList<nBits>::PackedList(const label size)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<int nBits>
inline void Foam::PackedList<nBits>::resize(const label size)
{
this->setSize(size);
}
template<int nBits> template<int nBits>
inline Foam::label Foam::PackedList<nBits>::size() const inline Foam::label Foam::PackedList<nBits>::size() const
{ {

View File

@ -170,6 +170,12 @@ public:
// deleted. // deleted.
void setSize(const label); 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 //- Clear the PtrList, i.e. set size to zero deleting all the
// allocated entries. // allocated entries.
void clear(); void clear();

View File

@ -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> template<class T>
inline bool Foam::PtrList<T>::set(const label i) const inline bool Foam::PtrList<T>::set(const label i) const
{ {

View File

@ -215,12 +215,16 @@ public:
//- Random access iterator for traversing UList. //- Random access iterator for traversing UList.
typedef const T* const_iterator; typedef const T* const_iterator;
//- Return a const_iterator to begin traversing the //- Return const_iterator to begin traversing the constant UList.
// 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; inline const_iterator begin() const;
//- Return a const_iterator to end traversing the //- Return const_iterator to end traversing the constant UList.
// constant UList.
inline const_iterator end() const; inline const_iterator end() const;
@ -229,12 +233,10 @@ public:
//- Reverse iterator for reverse traversal of UList. //- Reverse iterator for reverse traversal of UList.
typedef T* reverse_iterator; typedef T* reverse_iterator;
//- Return a reverse_iterator to begin reverse traversing the //- Return reverse_iterator to begin reverse traversing the UList.
// UList.
inline reverse_iterator rbegin(); inline reverse_iterator rbegin();
//- Return a reverse_iterator to end reverse traversing the //- Return reverse_iterator to end reverse traversing the UList.
// UList.
inline reverse_iterator rend(); inline reverse_iterator rend();
@ -243,12 +245,16 @@ public:
//- Reverse iterator for reverse traversal of constant UList. //- Reverse iterator for reverse traversal of constant UList.
typedef const T* const_reverse_iterator; typedef const T* const_reverse_iterator;
//- Return a const_reverse_iterator to begin reverse traversing the //- Return const_reverse_iterator to begin reverse traversing the UList.
// 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; inline const_reverse_iterator rbegin() const;
//- Return a const_reverse_iterator to end reverse traversing the //- Return const_reverse_iterator to end reverse traversing the UList.
// UList.
inline const_reverse_iterator rend() const; inline const_reverse_iterator rend() const;

View File

@ -161,6 +161,13 @@ Foam::UList<T>::begin() const
return v_; return v_;
} }
template<class T>
inline typename Foam::UList<T>::const_iterator
Foam::UList<T>::cbegin() const
{
return v_;
}
template<class T> template<class T>
inline typename Foam::UList<T>::iterator inline typename Foam::UList<T>::iterator
Foam::UList<T>::end() Foam::UList<T>::end()
@ -175,6 +182,13 @@ Foam::UList<T>::end() const
return &v_[size_]; return &v_[size_];
} }
template<class T>
inline typename Foam::UList<T>::const_iterator
Foam::UList<T>::cend() const
{
return &v_[size_];
}
template<class T> template<class T>
inline typename Foam::UList<T>::iterator inline typename Foam::UList<T>::iterator
Foam::UList<T>::rbegin() Foam::UList<T>::rbegin()
@ -189,6 +203,13 @@ Foam::UList<T>::rbegin() const
return &v_[size_-1]; 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> template<class T>
inline typename Foam::UList<T>::iterator inline typename Foam::UList<T>::iterator
Foam::UList<T>::rend() Foam::UList<T>::rend()
@ -203,6 +224,13 @@ Foam::UList<T>::rend() const
return &v_[-1]; return &v_[-1];
} }
template<class T>
inline typename Foam::UList<T>::const_iterator
Foam::UList<T>::crend() const
{
return &v_[-1];
}
template<class T> template<class T>
inline Foam::label Foam::UList<T>::size() const inline Foam::label Foam::UList<T>::size() const
{ {

View File

@ -124,6 +124,9 @@ public:
//- Return the number of elements in the UPtrList //- Return the number of elements in the UPtrList
inline label size() const; inline label size() const;
//- Return true if the UPtrList is empty (i.e., if size() == 0).
inline bool empty() const;
// Edit // Edit
@ -132,6 +135,11 @@ public:
// the end of a UPtrList. // the end of a UPtrList.
void setSize(const label); 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 //- Clear the UPtrList, i.e. set size to zero
void clear(); void clear();

View File

@ -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> template<class T>
inline bool Foam::UPtrList<T>::set(const label i) const inline bool Foam::UPtrList<T>::set(const label i) const
{ {
return ptrs_[i] != NULL; return ptrs_[i] != NULL;
} }
template<class T> template<class T>
inline T* Foam::UPtrList<T>::set(const label i, T* ptr) inline T* Foam::UPtrList<T>::set(const label i, T* ptr)
{ {

View File

@ -189,11 +189,21 @@ public:
return IDLList<ParticleType>::begin(); return IDLList<ParticleType>::begin();
}; };
const const_iterator cbegin() const
{
return IDLList<ParticleType>::cbegin();
};
const const_iterator end() const const const_iterator end() const
{ {
return IDLList<ParticleType>::end(); return IDLList<ParticleType>::end();
}; };
const const_iterator cend() const
{
return IDLList<ParticleType>::cend();
};
iterator begin() iterator begin()
{ {
return IDLList<ParticleType>::begin(); return IDLList<ParticleType>::begin();

View File

@ -192,9 +192,11 @@ public:
// the current face. For boundary edges this is the first boundary face // the current face. For boundary edges this is the first boundary face
// reached from walking back (i.e. in opposite direction to ++) // reached from walking back (i.e. in opposite direction to ++)
inline edgeFaceCirculator begin() const; inline edgeFaceCirculator begin() const;
inline edgeFaceCirculator cbegin() const;
//- iterator set to beyond the end of the walk. //- iterator set to beyond the end of the walk.
inline const edgeFaceCirculator& end() const; inline const edgeFaceCirculator& end() const;
inline const edgeFaceCirculator& cend() const;
}; };

View File

@ -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 const Foam::edgeFaceCirculator& Foam::edgeFaceCirculator::end() const
{ {
return endConstIter; return endConstIter;
} }
const Foam::edgeFaceCirculator& Foam::edgeFaceCirculator::cend() const
{
return endConstIter;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -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> template <class Type>
const typename Foam::octree<Type>::const_iterator& const typename Foam::octree<Type>::const_iterator&
Foam::octree<Type>::end() const 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 * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
template <class Type> template <class Type>

View File

@ -445,10 +445,6 @@ public:
//- Construct for a given octree and index //- Construct for a given octree and index
const_iterator(const octree&, label); const_iterator(const octree&, label);
// Member functions
const_iterator begin() const;
// Member operators // Member operators
void operator=(const const_iterator&); void operator=(const const_iterator&);
@ -465,9 +461,11 @@ public:
//- const_iterator set to the begining of the octree //- const_iterator set to the begining of the octree
inline const_iterator begin() const; inline const_iterator begin() const;
inline const_iterator cbegin() const;
//- const_iterator set to beyond the end of the octree //- const_iterator set to beyond the end of the octree
inline const const_iterator& end() const; inline const const_iterator& end() const;
inline const const_iterator& cend() const;
// IOstream Operators // IOstream Operators

View File

@ -102,6 +102,9 @@ private:
// Private member functions // Private member functions
//- Disable resize with value
void resize(const label, const Face&);
//- Disable setSize with value //- Disable setSize with value
void setSize(const label, const Face&); void setSize(const label, const Face&);