mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: adjust const access for linked-list iterators 'operator*'
- provides const/non-const access to the underlying list, but the iterator access itself is const. - provide linked-list iterator 'found()' method for symmetry with hash-table iterators. Use nullptr for more clarity.
This commit is contained in:
@ -56,7 +56,6 @@ int main(int argc, char *argv[])
|
|||||||
Info<< "element:" << *iter << endl;
|
Info<< "element:" << *iter << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Info<< nl << "And again using the same STL iterator: " << nl << endl;
|
Info<< nl << "And again using the same STL iterator: " << nl << endl;
|
||||||
|
|
||||||
forAllIters(myList, iter)
|
forAllIters(myList, iter)
|
||||||
|
|||||||
@ -254,14 +254,14 @@ public:
|
|||||||
|
|
||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
T& operator*()
|
T& operator*() const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
static_cast<link&>
|
static_cast<link&>
|
||||||
(LListBase_iterator::operator*()).obj_;
|
(LListBase_iterator::operator*()).obj_;
|
||||||
}
|
}
|
||||||
|
|
||||||
T& operator()()
|
T& operator()() const
|
||||||
{
|
{
|
||||||
return operator*();
|
return operator*();
|
||||||
}
|
}
|
||||||
@ -312,14 +312,14 @@ public:
|
|||||||
|
|
||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
const T& operator*()
|
const T& operator*() const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
static_cast<const link&>
|
static_cast<const link&>
|
||||||
(LListBase_const_iterator::operator*()).obj_;
|
(LListBase_const_iterator::operator*()).obj_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const T& operator()()
|
const T& operator()() const
|
||||||
{
|
{
|
||||||
return operator*();
|
return operator*();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -196,12 +196,12 @@ public:
|
|||||||
|
|
||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
T& operator*()
|
T& operator*() const
|
||||||
{
|
{
|
||||||
return *(LList<LListBase, T*>::iterator::operator*());
|
return *(LList<LListBase, T*>::iterator::operator*());
|
||||||
}
|
}
|
||||||
|
|
||||||
T& operator()()
|
T& operator()() const
|
||||||
{
|
{
|
||||||
return operator*();
|
return operator*();
|
||||||
}
|
}
|
||||||
@ -235,12 +235,12 @@ public:
|
|||||||
|
|
||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
const T& operator*()
|
const T& operator*() const
|
||||||
{
|
{
|
||||||
return *(LList<LListBase, T*>::const_iterator::operator*());
|
return *(LList<LListBase, T*>::const_iterator::operator*());
|
||||||
}
|
}
|
||||||
|
|
||||||
const T& operator()()
|
const T& operator()() const
|
||||||
{
|
{
|
||||||
return operator*();
|
return operator*();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -192,12 +192,12 @@ public:
|
|||||||
|
|
||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
T& operator*()
|
T& operator*() const
|
||||||
{
|
{
|
||||||
return static_cast<T&>(LListBase_iterator::operator*());
|
return static_cast<T&>(LListBase_iterator::operator*());
|
||||||
}
|
}
|
||||||
|
|
||||||
T& operator()()
|
T& operator()() const
|
||||||
{
|
{
|
||||||
return operator*();
|
return operator*();
|
||||||
}
|
}
|
||||||
@ -247,14 +247,14 @@ public:
|
|||||||
|
|
||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
const T& operator*()
|
const T& operator*() const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
static_cast<const T&>
|
static_cast<const T&>
|
||||||
(LListBase_const_iterator::operator*());
|
(LListBase_const_iterator::operator*());
|
||||||
}
|
}
|
||||||
|
|
||||||
const T& operator()()
|
const T& operator()() const
|
||||||
{
|
{
|
||||||
return operator*();
|
return operator*();
|
||||||
}
|
}
|
||||||
@ -309,14 +309,14 @@ public:
|
|||||||
|
|
||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
const T& operator*()
|
const T& operator*() const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
static_cast<const T&>
|
static_cast<const T&>
|
||||||
(LListBase::const_reverse_iterator::operator*());
|
(LListBase::const_reverse_iterator::operator*());
|
||||||
}
|
}
|
||||||
|
|
||||||
const T& operator()()
|
const T& operator()() const
|
||||||
{
|
{
|
||||||
return operator*();
|
return operator*();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -188,7 +188,7 @@ Foam::DLListBase::link* Foam::DLListBase::removeHead()
|
|||||||
|
|
||||||
if (!first_)
|
if (!first_)
|
||||||
{
|
{
|
||||||
last_ = 0;
|
last_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
f->deregister();
|
f->deregister();
|
||||||
@ -204,8 +204,8 @@ Foam::DLListBase::link* Foam::DLListBase::remove(DLListBase::link* l)
|
|||||||
|
|
||||||
if (l == first_ && first_ == last_)
|
if (l == first_ && first_ == last_)
|
||||||
{
|
{
|
||||||
first_ = 0;
|
first_ = nullptr;
|
||||||
last_ = 0;
|
last_ = nullptr;
|
||||||
}
|
}
|
||||||
else if (l == first_)
|
else if (l == first_)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -25,9 +25,10 @@ Class
|
|||||||
Foam::DLListBase
|
Foam::DLListBase
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Base doubly-linked list.
|
Base for doubly-linked lists.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
|
DLListBaseI.H
|
||||||
DLListBase.C
|
DLListBase.C
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -84,10 +85,10 @@ private:
|
|||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
DLListBase(const DLListBase&);
|
DLListBase(const DLListBase&) = delete;
|
||||||
|
|
||||||
//- Disallow default bitwise assignment
|
//- Disallow default bitwise assignment
|
||||||
void operator=(const DLListBase&);
|
void operator=(const DLListBase&) = delete;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -184,18 +185,14 @@ public:
|
|||||||
friend class DLListBase;
|
friend class DLListBase;
|
||||||
friend class const_iterator;
|
friend class const_iterator;
|
||||||
|
|
||||||
// Private data
|
//- Reference to the list this is an iterator for
|
||||||
|
DLListBase& curList_;
|
||||||
|
|
||||||
//- Reference to the list this is an iterator for
|
//- Current element
|
||||||
DLListBase& curList_;
|
link* curElmt_;
|
||||||
|
|
||||||
//- Current element
|
//- Copy of the link
|
||||||
link* curElmt_;
|
link curLink_;
|
||||||
|
|
||||||
//- Copy of the link
|
|
||||||
link curLink_;
|
|
||||||
|
|
||||||
// Private Member Functions
|
|
||||||
|
|
||||||
//- Construct for a given SLListBase with nullptr element and link.
|
//- Construct for a given SLListBase with nullptr element and link.
|
||||||
// Only used to create endIter
|
// Only used to create endIter
|
||||||
@ -206,17 +203,18 @@ public:
|
|||||||
//- Construct for a given DLListBase and link
|
//- Construct for a given DLListBase and link
|
||||||
inline iterator(DLListBase&, link*);
|
inline iterator(DLListBase&, link*);
|
||||||
|
|
||||||
// Member operators
|
//- Currently pointing at a valid entry
|
||||||
|
inline bool found() const;
|
||||||
|
|
||||||
inline void operator=(const iterator&);
|
inline void operator=(const iterator& iter);
|
||||||
|
|
||||||
inline bool operator==(const iterator&) const;
|
inline bool operator==(const iterator& iter) const;
|
||||||
inline bool operator!=(const iterator&) const;
|
inline bool operator!=(const iterator& iter) const;
|
||||||
|
|
||||||
inline link& operator*();
|
inline link& operator*() const;
|
||||||
|
|
||||||
inline iterator& operator++();
|
inline iterator& operator++();
|
||||||
inline iterator operator++(int);
|
inline iterator operator++(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline iterator begin();
|
inline iterator begin();
|
||||||
@ -228,13 +226,11 @@ public:
|
|||||||
//- An STL-conforming const_iterator
|
//- An STL-conforming const_iterator
|
||||||
class const_iterator
|
class const_iterator
|
||||||
{
|
{
|
||||||
// Private data
|
//- Reference to the list this is an iterator for
|
||||||
|
const DLListBase& curList_;
|
||||||
|
|
||||||
//- Reference to the list this is an iterator for
|
//- Current element
|
||||||
const DLListBase& curList_;
|
const link* curElmt_;
|
||||||
|
|
||||||
//- Current element
|
|
||||||
const link* curElmt_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -242,19 +238,20 @@ public:
|
|||||||
inline const_iterator(const DLListBase&, const link*);
|
inline const_iterator(const DLListBase&, const link*);
|
||||||
|
|
||||||
//- Construct from a non-const iterator
|
//- Construct from a non-const iterator
|
||||||
inline const_iterator(const iterator&);
|
inline const_iterator(const DLListBase::iterator& iter);
|
||||||
|
|
||||||
// Member operators
|
//- Currently pointing at a valid entry
|
||||||
|
inline bool found() const;
|
||||||
|
|
||||||
inline void operator=(const const_iterator&);
|
inline void operator=(const const_iterator& iter);
|
||||||
|
|
||||||
inline bool operator==(const const_iterator&) const;
|
inline bool operator==(const const_iterator& iter) const;
|
||||||
inline bool operator!=(const const_iterator&) const;
|
inline bool operator!=(const const_iterator& iter) const;
|
||||||
|
|
||||||
inline const link& operator*();
|
inline const link& operator*() const;
|
||||||
|
|
||||||
inline const_iterator& operator++();
|
inline const_iterator& operator++();
|
||||||
inline const_iterator operator++(int);
|
inline const_iterator operator++(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const_iterator cbegin() const;
|
inline const_iterator cbegin() const;
|
||||||
@ -269,30 +266,29 @@ public:
|
|||||||
//- An STL-conforming const_reverse_iterator
|
//- An STL-conforming const_reverse_iterator
|
||||||
class const_reverse_iterator
|
class const_reverse_iterator
|
||||||
{
|
{
|
||||||
// Private data
|
//- Reference to the list this is an reverse_iterator for
|
||||||
|
const DLListBase& curList_;
|
||||||
|
|
||||||
//- Reference to the list this is an reverse_iterator for
|
//- Current element
|
||||||
const DLListBase& curList_;
|
const link* curElmt_;
|
||||||
|
|
||||||
//- Current element
|
|
||||||
const link* curElmt_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//- Construct for a given DLListBase and link
|
//- Construct for a given DLListBase and link
|
||||||
inline const_reverse_iterator(const DLListBase&, const link*);
|
inline const_reverse_iterator(const DLListBase& lst, const link*);
|
||||||
|
|
||||||
// Member operators
|
//- Currently pointing at a valid entry
|
||||||
|
inline bool found() const;
|
||||||
|
|
||||||
inline void operator=(const const_reverse_iterator&);
|
inline void operator=(const const_reverse_iterator& iter);
|
||||||
|
|
||||||
inline bool operator==(const const_reverse_iterator&) const;
|
inline bool operator==(const const_reverse_iterator& iter) const;
|
||||||
inline bool operator!=(const const_reverse_iterator&) const;
|
inline bool operator!=(const const_reverse_iterator& iter) const;
|
||||||
|
|
||||||
inline const link& operator*();
|
inline const link& operator*() const;
|
||||||
|
|
||||||
inline const_reverse_iterator& operator++();
|
inline const_reverse_iterator& operator++();
|
||||||
inline const_reverse_iterator operator++(int);
|
inline const_reverse_iterator operator++(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const_reverse_iterator crbegin() const;
|
inline const_reverse_iterator crbegin() const;
|
||||||
|
|||||||
@ -29,15 +29,15 @@ License
|
|||||||
|
|
||||||
inline Foam::DLListBase::link::link()
|
inline Foam::DLListBase::link::link()
|
||||||
:
|
:
|
||||||
prev_(0),
|
prev_(nullptr),
|
||||||
next_(0)
|
next_(nullptr)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::DLListBase::DLListBase()
|
inline Foam::DLListBase::DLListBase()
|
||||||
:
|
:
|
||||||
first_(0),
|
first_(nullptr),
|
||||||
last_(0),
|
last_(nullptr),
|
||||||
nElmts_(0)
|
nElmts_(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -63,14 +63,14 @@ inline Foam::DLListBase::~DLListBase()
|
|||||||
|
|
||||||
inline bool Foam::DLListBase::link::registered() const
|
inline bool Foam::DLListBase::link::registered() const
|
||||||
{
|
{
|
||||||
return prev_ != 0 && next_ != 0;
|
return prev_ != nullptr && next_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::DLListBase::link::deregister()
|
inline void Foam::DLListBase::link::deregister()
|
||||||
{
|
{
|
||||||
prev_ = 0;
|
prev_ = nullptr;
|
||||||
next_ = 0;
|
next_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -140,8 +140,8 @@ Foam::DLListBase::last() const
|
|||||||
|
|
||||||
inline void Foam::DLListBase::clear()
|
inline void Foam::DLListBase::clear()
|
||||||
{
|
{
|
||||||
first_ = 0;
|
first_ = nullptr;
|
||||||
last_ = 0;
|
last_ = nullptr;
|
||||||
nElmts_ = 0;
|
nElmts_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,6 +195,12 @@ inline Foam::DLListBase::iterator::iterator(DLListBase& s)
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::DLListBase::iterator::found() const
|
||||||
|
{
|
||||||
|
return (curElmt_ != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::DLListBase::iterator::operator=(const iterator& iter)
|
inline void Foam::DLListBase::iterator::operator=(const iterator& iter)
|
||||||
{
|
{
|
||||||
curElmt_ = iter.curElmt_;
|
curElmt_ = iter.curElmt_;
|
||||||
@ -215,7 +221,7 @@ inline bool Foam::DLListBase::iterator::operator!=(const iterator& iter) const
|
|||||||
|
|
||||||
|
|
||||||
inline Foam::DLListBase::link&
|
inline Foam::DLListBase::link&
|
||||||
Foam::DLListBase::iterator::operator*()
|
Foam::DLListBase::iterator::operator*() const
|
||||||
{
|
{
|
||||||
return *curElmt_;
|
return *curElmt_;
|
||||||
}
|
}
|
||||||
@ -226,9 +232,9 @@ Foam::DLListBase::iterator::operator++()
|
|||||||
{
|
{
|
||||||
// Check if the curElmt_ is the last element (if it points to itself)
|
// Check if the curElmt_ is the last element (if it points to itself)
|
||||||
// or if the list is empty because the last element may have been removed
|
// or if the list is empty because the last element may have been removed
|
||||||
if (curLink_.next_ == curElmt_ || curList_.last_ == 0)
|
if (curLink_.next_ == curElmt_ || curList_.last_ == nullptr)
|
||||||
{
|
{
|
||||||
curElmt_ = 0;
|
curElmt_ = nullptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -282,13 +288,22 @@ inline Foam::DLListBase::const_iterator::const_iterator
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::DLListBase::const_iterator::const_iterator(const iterator& iter)
|
inline Foam::DLListBase::const_iterator::const_iterator
|
||||||
|
(
|
||||||
|
const DLListBase::iterator& iter
|
||||||
|
)
|
||||||
:
|
:
|
||||||
curList_(iter.curList_),
|
curList_(iter.curList_),
|
||||||
curElmt_(iter.curElmt_)
|
curElmt_(iter.curElmt_)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::DLListBase::const_iterator::found() const
|
||||||
|
{
|
||||||
|
return (curElmt_ != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::DLListBase::const_iterator::operator=
|
inline void Foam::DLListBase::const_iterator::operator=
|
||||||
(
|
(
|
||||||
const const_iterator& iter
|
const const_iterator& iter
|
||||||
@ -317,7 +332,7 @@ inline bool Foam::DLListBase::const_iterator::operator!=
|
|||||||
|
|
||||||
|
|
||||||
inline const Foam::DLListBase::link&
|
inline const Foam::DLListBase::link&
|
||||||
Foam::DLListBase::const_iterator::operator*()
|
Foam::DLListBase::const_iterator::operator*() const
|
||||||
{
|
{
|
||||||
return *curElmt_;
|
return *curElmt_;
|
||||||
}
|
}
|
||||||
@ -328,7 +343,7 @@ Foam::DLListBase::const_iterator::operator++()
|
|||||||
{
|
{
|
||||||
if (curElmt_ == curList_.last_)
|
if (curElmt_ == curList_.last_)
|
||||||
{
|
{
|
||||||
curElmt_ = 0;
|
curElmt_ = nullptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -387,15 +402,21 @@ Foam::DLListBase::end() const
|
|||||||
|
|
||||||
inline Foam::DLListBase::const_reverse_iterator::const_reverse_iterator
|
inline Foam::DLListBase::const_reverse_iterator::const_reverse_iterator
|
||||||
(
|
(
|
||||||
const DLListBase& s,
|
const DLListBase& lst,
|
||||||
const link* elmt
|
const link* elmt
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
curList_(s),
|
curList_(lst),
|
||||||
curElmt_(elmt)
|
curElmt_(elmt)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::DLListBase::const_reverse_iterator::found() const
|
||||||
|
{
|
||||||
|
return (curElmt_ != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::DLListBase::const_reverse_iterator::operator=
|
inline void Foam::DLListBase::const_reverse_iterator::operator=
|
||||||
(
|
(
|
||||||
const const_reverse_iterator& iter
|
const const_reverse_iterator& iter
|
||||||
@ -424,7 +445,7 @@ inline bool Foam::DLListBase::const_reverse_iterator::operator!=
|
|||||||
|
|
||||||
|
|
||||||
inline const Foam::DLListBase::link&
|
inline const Foam::DLListBase::link&
|
||||||
Foam::DLListBase::const_reverse_iterator::operator*()
|
Foam::DLListBase::const_reverse_iterator::operator*() const
|
||||||
{
|
{
|
||||||
return *curElmt_;
|
return *curElmt_;
|
||||||
}
|
}
|
||||||
@ -435,7 +456,7 @@ Foam::DLListBase::const_reverse_iterator::operator++()
|
|||||||
{
|
{
|
||||||
if (curElmt_ == curList_.first_)
|
if (curElmt_ == curList_.first_)
|
||||||
{
|
{
|
||||||
curElmt_ = 0;
|
curElmt_ = nullptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -460,7 +481,7 @@ Foam::DLListBase::crbegin() const
|
|||||||
{
|
{
|
||||||
if (size())
|
if (size())
|
||||||
{
|
{
|
||||||
return const_reverse_iterator(*this, last());
|
return const_reverse_iterator(*this, this->last());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -79,7 +79,7 @@ Foam::SLListBase::link* Foam::SLListBase::removeHead()
|
|||||||
{
|
{
|
||||||
nElmts_--;
|
nElmts_--;
|
||||||
|
|
||||||
if (last_ == 0)
|
if (last_ == nullptr)
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "remove from empty list"
|
<< "remove from empty list"
|
||||||
@ -90,7 +90,7 @@ Foam::SLListBase::link* Foam::SLListBase::removeHead()
|
|||||||
|
|
||||||
if (f == last_)
|
if (f == last_)
|
||||||
{
|
{
|
||||||
last_ = 0;
|
last_ = nullptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -132,7 +132,7 @@ Foam::SLListBase::link* Foam::SLListBase::remove(SLListBase::link* it)
|
|||||||
prev = p;
|
prev = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -25,9 +25,10 @@ Class
|
|||||||
Foam::SLListBase
|
Foam::SLListBase
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Base singly-linked list.
|
Base for singly-linked lists.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
|
SLListBaseI.H
|
||||||
SLListBase.C
|
SLListBase.C
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -81,10 +82,10 @@ private:
|
|||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
SLListBase(const SLListBase&);
|
SLListBase(const SLListBase&) = delete;
|
||||||
|
|
||||||
//- Disallow default bitwise assignment
|
//- Disallow default bitwise assignment
|
||||||
void operator=(const SLListBase&);
|
void operator=(const SLListBase&) = delete;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -166,18 +167,14 @@ public:
|
|||||||
friend class SLListBase;
|
friend class SLListBase;
|
||||||
friend class const_iterator;
|
friend class const_iterator;
|
||||||
|
|
||||||
// Private data
|
//- Reference to the list this is an iterator for
|
||||||
|
SLListBase& curList_;
|
||||||
|
|
||||||
//- Reference to the list this is an iterator for
|
//- Current element
|
||||||
SLListBase& curList_;
|
link* curElmt_;
|
||||||
|
|
||||||
//- Current element
|
//- Copy of the link
|
||||||
link* curElmt_;
|
link curLink_;
|
||||||
|
|
||||||
//- Copy of the link
|
|
||||||
link curLink_;
|
|
||||||
|
|
||||||
// Private Member Functions
|
|
||||||
|
|
||||||
//- Construct for a given SLListBase with nullptr element and link.
|
//- Construct for a given SLListBase with nullptr element and link.
|
||||||
// Only used to create endIter
|
// Only used to create endIter
|
||||||
@ -188,17 +185,18 @@ public:
|
|||||||
//- Construct for a given SLListBase and link
|
//- Construct for a given SLListBase and link
|
||||||
inline iterator(SLListBase&, link*);
|
inline iterator(SLListBase&, link*);
|
||||||
|
|
||||||
// Member operators
|
//- Currently pointing at a valid entry
|
||||||
|
inline bool found() const;
|
||||||
|
|
||||||
inline void operator=(const iterator&);
|
inline void operator=(const iterator& iter);
|
||||||
|
|
||||||
inline bool operator==(const iterator&) const;
|
inline bool operator==(const iterator& iter) const;
|
||||||
inline bool operator!=(const iterator&) const;
|
inline bool operator!=(const iterator& iter) const;
|
||||||
|
|
||||||
inline link& operator*();
|
inline link& operator*() const;
|
||||||
|
|
||||||
inline iterator& operator++();
|
inline iterator& operator++();
|
||||||
inline iterator operator++(int);
|
inline iterator operator++(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline iterator begin();
|
inline iterator begin();
|
||||||
@ -210,13 +208,11 @@ public:
|
|||||||
//- An STL-conforming const_iterator
|
//- An STL-conforming const_iterator
|
||||||
class const_iterator
|
class const_iterator
|
||||||
{
|
{
|
||||||
// Private data
|
//- Reference to the list this is an iterator for
|
||||||
|
const SLListBase& curList_;
|
||||||
|
|
||||||
//- Reference to the list this is an iterator for
|
//- Current element
|
||||||
const SLListBase& curList_;
|
const link* curElmt_;
|
||||||
|
|
||||||
//- Current element
|
|
||||||
const link* curElmt_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -224,20 +220,20 @@ public:
|
|||||||
inline const_iterator(const SLListBase&, const link*);
|
inline const_iterator(const SLListBase&, const link*);
|
||||||
|
|
||||||
//- Construct from a non-const iterator
|
//- Construct from a non-const iterator
|
||||||
inline const_iterator(const iterator&);
|
inline const_iterator(const SLListBase::iterator& iter);
|
||||||
|
|
||||||
|
//- Currently pointing at a valid entry
|
||||||
|
inline bool found() const;
|
||||||
|
|
||||||
// Member operators
|
inline void operator=(const const_iterator& iter);
|
||||||
|
|
||||||
inline void operator=(const const_iterator&);
|
inline bool operator==(const const_iterator& iter) const;
|
||||||
|
inline bool operator!=(const const_iterator& iter) const;
|
||||||
|
|
||||||
inline bool operator==(const const_iterator&) const;
|
inline const link& operator*() const;
|
||||||
inline bool operator!=(const const_iterator&) const;
|
|
||||||
|
|
||||||
inline const link& operator*();
|
inline const_iterator& operator++();
|
||||||
|
inline const_iterator operator++(int);
|
||||||
inline const_iterator& operator++();
|
|
||||||
inline const_iterator operator++(int);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const_iterator cbegin() const;
|
inline const_iterator cbegin() const;
|
||||||
|
|||||||
@ -21,9 +21,6 @@ License
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Description
|
|
||||||
Base singly-linked list.
|
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "error.H"
|
#include "error.H"
|
||||||
@ -32,7 +29,7 @@ Description
|
|||||||
|
|
||||||
inline Foam::SLListBase::link::link()
|
inline Foam::SLListBase::link::link()
|
||||||
:
|
:
|
||||||
next_(0)
|
next_(nullptr)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -44,16 +41,22 @@ inline Foam::SLListBase::link::link(link* p)
|
|||||||
|
|
||||||
inline Foam::SLListBase::SLListBase()
|
inline Foam::SLListBase::SLListBase()
|
||||||
:
|
:
|
||||||
last_(0),
|
last_(nullptr),
|
||||||
nElmts_(0)
|
nElmts_(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::SLListBase::SLListBase(link* a)
|
inline Foam::SLListBase::SLListBase(link* a)
|
||||||
:
|
:
|
||||||
last_(a->next_ = a),
|
last_(a),
|
||||||
nElmts_(1)
|
nElmts_(0)
|
||||||
{}
|
{
|
||||||
|
if (a) // protect against nullptr
|
||||||
|
{
|
||||||
|
a->next_ = a;
|
||||||
|
nElmts_ = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
@ -130,7 +133,7 @@ Foam::SLListBase::last() const
|
|||||||
|
|
||||||
inline void Foam::SLListBase::clear()
|
inline void Foam::SLListBase::clear()
|
||||||
{
|
{
|
||||||
last_ = 0;
|
last_ = nullptr;
|
||||||
nElmts_ = 0;
|
nElmts_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,6 +174,12 @@ inline Foam::SLListBase::iterator::iterator(SLListBase& s)
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::SLListBase::iterator::found() const
|
||||||
|
{
|
||||||
|
return (curElmt_ != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::SLListBase::iterator::operator=(const iterator& iter)
|
inline void Foam::SLListBase::iterator::operator=(const iterator& iter)
|
||||||
{
|
{
|
||||||
curElmt_ = iter.curElmt_;
|
curElmt_ = iter.curElmt_;
|
||||||
@ -190,7 +199,7 @@ inline bool Foam::SLListBase::iterator::operator!=(const iterator& iter) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::SLListBase::link& Foam::SLListBase::iterator::operator*()
|
inline Foam::SLListBase::link& Foam::SLListBase::iterator::operator*() const
|
||||||
{
|
{
|
||||||
return *curElmt_;
|
return *curElmt_;
|
||||||
}
|
}
|
||||||
@ -198,9 +207,9 @@ inline Foam::SLListBase::link& Foam::SLListBase::iterator::operator*()
|
|||||||
|
|
||||||
inline Foam::SLListBase::iterator& Foam::SLListBase::iterator::operator++()
|
inline Foam::SLListBase::iterator& Foam::SLListBase::iterator::operator++()
|
||||||
{
|
{
|
||||||
if (curElmt_ == curList_.last_ || curList_.last_ == 0)
|
if (curElmt_ == curList_.last_ || curList_.last_ == nullptr)
|
||||||
{
|
{
|
||||||
curElmt_ = 0;
|
curElmt_ = nullptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -255,13 +264,22 @@ inline Foam::SLListBase::const_iterator::const_iterator
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::SLListBase::const_iterator::const_iterator(const iterator& iter)
|
inline Foam::SLListBase::const_iterator::const_iterator
|
||||||
|
(
|
||||||
|
const SLListBase::iterator& iter
|
||||||
|
)
|
||||||
:
|
:
|
||||||
curList_(iter.curList_),
|
curList_(iter.curList_),
|
||||||
curElmt_(iter.curElmt_)
|
curElmt_(iter.curElmt_)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::SLListBase::const_iterator::found() const
|
||||||
|
{
|
||||||
|
return (curElmt_ != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::SLListBase::const_iterator::operator=
|
inline void Foam::SLListBase::const_iterator::operator=
|
||||||
(
|
(
|
||||||
const const_iterator& iter
|
const const_iterator& iter
|
||||||
@ -290,7 +308,7 @@ inline bool Foam::SLListBase::const_iterator::operator!=
|
|||||||
|
|
||||||
|
|
||||||
inline const Foam::SLListBase::link&
|
inline const Foam::SLListBase::link&
|
||||||
Foam::SLListBase::const_iterator::operator*()
|
Foam::SLListBase::const_iterator::operator*() const
|
||||||
{
|
{
|
||||||
return *curElmt_;
|
return *curElmt_;
|
||||||
}
|
}
|
||||||
@ -301,7 +319,7 @@ Foam::SLListBase::const_iterator::operator++()
|
|||||||
{
|
{
|
||||||
if (curElmt_ == curList_.last_)
|
if (curElmt_ == curList_.last_)
|
||||||
{
|
{
|
||||||
curElmt_ = 0;
|
curElmt_ = nullptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user