PtrList: Added const_iterator
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -32,6 +32,7 @@ Description
|
|||||||
pointer.
|
pointer.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
|
PtrListI.H
|
||||||
PtrList.C
|
PtrList.C
|
||||||
PtrListIO.C
|
PtrListIO.C
|
||||||
|
|
||||||
@ -80,6 +81,34 @@ inline label operator-
|
|||||||
const typename PtrList<T>::iterator&
|
const typename PtrList<T>::iterator&
|
||||||
);
|
);
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename PtrList<T>::const_iterator operator+
|
||||||
|
(
|
||||||
|
const typename PtrList<T>::const_iterator&,
|
||||||
|
label
|
||||||
|
);
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename PtrList<T>::const_iterator operator+
|
||||||
|
(
|
||||||
|
label,
|
||||||
|
const typename PtrList<T>::const_iterator&
|
||||||
|
);
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename PtrList<T>::const_iterator operator-
|
||||||
|
(
|
||||||
|
const typename PtrList<T>::const_iterator&,
|
||||||
|
label
|
||||||
|
);
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline label operator-
|
||||||
|
(
|
||||||
|
const typename PtrList<T>::const_iterator&,
|
||||||
|
const typename PtrList<T>::const_iterator&
|
||||||
|
);
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Istream& operator>>(Istream&, PtrList<T>&);
|
Istream& operator>>(Istream&, PtrList<T>&);
|
||||||
|
|
||||||
@ -245,7 +274,9 @@ public:
|
|||||||
// Random access iterator for traversing PtrList.
|
// Random access iterator for traversing PtrList.
|
||||||
|
|
||||||
class iterator;
|
class iterator;
|
||||||
|
class const_iterator;
|
||||||
friend class iterator;
|
friend class iterator;
|
||||||
|
friend class const_iterator;
|
||||||
|
|
||||||
//- An STL-conforming iterator
|
//- An STL-conforming iterator
|
||||||
class iterator
|
class iterator
|
||||||
@ -254,6 +285,8 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
friend class const_iterator;
|
||||||
|
|
||||||
//- Construct for a given PtrList entry
|
//- Construct for a given PtrList entry
|
||||||
inline iterator(T**);
|
inline iterator(T**);
|
||||||
|
|
||||||
@ -303,6 +336,87 @@ public:
|
|||||||
inline iterator end();
|
inline iterator end();
|
||||||
|
|
||||||
|
|
||||||
|
// STL const_iterator
|
||||||
|
// Random access iterator for traversing PtrList.
|
||||||
|
|
||||||
|
//- An STL-conforming const_iterator
|
||||||
|
class const_iterator
|
||||||
|
{
|
||||||
|
const T* const* ptr_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Construct for a given PtrList entry
|
||||||
|
inline const_iterator(const T* const*);
|
||||||
|
|
||||||
|
//- Construct from an iterator
|
||||||
|
inline const_iterator(const iterator&);
|
||||||
|
|
||||||
|
|
||||||
|
// Member operators
|
||||||
|
|
||||||
|
inline bool operator==(const const_iterator&) const;
|
||||||
|
inline bool operator!=(const const_iterator&) const;
|
||||||
|
|
||||||
|
typedef const T& Tref;
|
||||||
|
inline Tref operator*();
|
||||||
|
inline Tref operator()();
|
||||||
|
|
||||||
|
inline const_iterator operator++();
|
||||||
|
inline const_iterator operator++(int);
|
||||||
|
|
||||||
|
inline const_iterator operator--();
|
||||||
|
inline const_iterator operator--(int);
|
||||||
|
|
||||||
|
inline const_iterator operator+=(label);
|
||||||
|
|
||||||
|
friend const_iterator operator+ <T>
|
||||||
|
(
|
||||||
|
const const_iterator&,
|
||||||
|
label
|
||||||
|
);
|
||||||
|
friend const_iterator operator+ <T>
|
||||||
|
(
|
||||||
|
label,
|
||||||
|
const const_iterator&
|
||||||
|
);
|
||||||
|
|
||||||
|
inline const_iterator operator-=(label);
|
||||||
|
|
||||||
|
friend const_iterator operator- <T>
|
||||||
|
(
|
||||||
|
const const_iterator&,
|
||||||
|
label
|
||||||
|
);
|
||||||
|
|
||||||
|
friend label operator- <T>
|
||||||
|
(
|
||||||
|
const const_iterator&,
|
||||||
|
const const_iterator&
|
||||||
|
);
|
||||||
|
|
||||||
|
inline const T& operator[](label);
|
||||||
|
|
||||||
|
inline bool operator<(const const_iterator&) const;
|
||||||
|
inline bool operator>(const const_iterator&) const;
|
||||||
|
|
||||||
|
inline bool operator<=(const const_iterator&) const;
|
||||||
|
inline bool operator>=(const const_iterator&) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
//- Return an const_iterator to begin traversing the PtrList.
|
||||||
|
inline const_iterator cbegin() const;
|
||||||
|
|
||||||
|
//- Return an const_iterator to end traversing the PtrList.
|
||||||
|
inline const_iterator cend() const;
|
||||||
|
|
||||||
|
//- Return an const_iterator to begin traversing the PtrList.
|
||||||
|
inline const_iterator begin() const;
|
||||||
|
|
||||||
|
//- Return an const_iterator to end traversing the PtrList.
|
||||||
|
inline const_iterator end() const;
|
||||||
|
|
||||||
|
|
||||||
// IOstream operator
|
// IOstream operator
|
||||||
|
|
||||||
//- Read List from Istream, discarding contents of existing List.
|
//- Read List from Istream, discarding contents of existing List.
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -23,8 +23,6 @@ License
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "error.H"
|
|
||||||
|
|
||||||
#include "autoPtr.H"
|
#include "autoPtr.H"
|
||||||
#include "tmp.H"
|
#include "tmp.H"
|
||||||
|
|
||||||
@ -373,4 +371,227 @@ inline typename Foam::PtrList<T>::iterator Foam::PtrList<T>::end()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline Foam::PtrList<T>::const_iterator::const_iterator(const T* const* ptr)
|
||||||
|
:
|
||||||
|
ptr_(ptr)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline Foam::PtrList<T>::const_iterator::const_iterator(const iterator& iter)
|
||||||
|
:
|
||||||
|
ptr_(iter.ptr_)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline bool Foam::PtrList<T>::const_iterator::operator==
|
||||||
|
(
|
||||||
|
const const_iterator& iter
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return ptr_ == iter.ptr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline bool Foam::PtrList<T>::const_iterator::operator!=
|
||||||
|
(
|
||||||
|
const const_iterator& iter
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return ptr_ != iter.ptr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline const T& Foam::PtrList<T>::const_iterator::operator*()
|
||||||
|
{
|
||||||
|
return **ptr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline const T& Foam::PtrList<T>::const_iterator::operator()()
|
||||||
|
{
|
||||||
|
return operator*();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename Foam::PtrList<T>::const_iterator
|
||||||
|
Foam::PtrList<T>::const_iterator::operator++()
|
||||||
|
{
|
||||||
|
++ptr_;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename Foam::PtrList<T>::const_iterator
|
||||||
|
Foam::PtrList<T>::const_iterator::operator++(int)
|
||||||
|
{
|
||||||
|
const_iterator tmp = *this;
|
||||||
|
++ptr_;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename Foam::PtrList<T>::const_iterator
|
||||||
|
Foam::PtrList<T>::const_iterator::operator--()
|
||||||
|
{
|
||||||
|
--ptr_;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename Foam::PtrList<T>::const_iterator
|
||||||
|
Foam::PtrList<T>::const_iterator::operator--(int)
|
||||||
|
{
|
||||||
|
const_iterator tmp = *this;
|
||||||
|
--ptr_;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename Foam::PtrList<T>::const_iterator
|
||||||
|
Foam::PtrList<T>::const_iterator::operator+=(label n)
|
||||||
|
{
|
||||||
|
ptr_ += n;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename Foam::PtrList<T>::const_iterator
|
||||||
|
Foam::operator+(const typename PtrList<T>::const_iterator& iter, label n)
|
||||||
|
{
|
||||||
|
typename PtrList<T>::const_iterator tmp = iter;
|
||||||
|
return tmp += n;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename Foam::PtrList<T>::const_iterator
|
||||||
|
Foam::operator+(label n, const typename PtrList<T>::const_iterator& iter)
|
||||||
|
{
|
||||||
|
typename PtrList<T>::const_iterator tmp = iter;
|
||||||
|
return tmp += n;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename Foam::PtrList<T>::const_iterator
|
||||||
|
Foam::PtrList<T>::const_iterator::operator-=(label n)
|
||||||
|
{
|
||||||
|
ptr_ -= n;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename Foam::PtrList<T>::const_iterator
|
||||||
|
Foam::operator-(const typename PtrList<T>::const_iterator& iter, label n)
|
||||||
|
{
|
||||||
|
typename PtrList<T>::const_iterator tmp = iter;
|
||||||
|
return tmp -= n;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline Foam::label Foam::operator-
|
||||||
|
(
|
||||||
|
const typename PtrList<T>::const_iterator& iter1,
|
||||||
|
const typename PtrList<T>::const_iterator& iter2
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return (iter1.ptr_ - iter2.ptr_)/sizeof(T*);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline const T& Foam::PtrList<T>::const_iterator::operator[](label n)
|
||||||
|
{
|
||||||
|
return *(*this + n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline bool Foam::PtrList<T>::const_iterator::operator<
|
||||||
|
(
|
||||||
|
const const_iterator& iter
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return ptr_ < iter.ptr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline bool Foam::PtrList<T>::const_iterator::operator>
|
||||||
|
(
|
||||||
|
const const_iterator& iter
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return ptr_ > iter.ptr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline bool Foam::PtrList<T>::const_iterator::operator<=
|
||||||
|
(
|
||||||
|
const const_iterator& iter
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return ptr_ <= iter.ptr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline bool Foam::PtrList<T>::const_iterator::operator>=
|
||||||
|
(
|
||||||
|
const const_iterator& iter
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return ptr_ >= iter.ptr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename Foam::PtrList<T>::const_iterator
|
||||||
|
Foam::PtrList<T>::begin() const
|
||||||
|
{
|
||||||
|
return ptrs_.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename Foam::PtrList<T>::const_iterator
|
||||||
|
Foam::PtrList<T>::end() const
|
||||||
|
{
|
||||||
|
return ptrs_.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename Foam::PtrList<T>::const_iterator
|
||||||
|
Foam::PtrList<T>::cbegin() const
|
||||||
|
{
|
||||||
|
return ptrs_.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename Foam::PtrList<T>::const_iterator
|
||||||
|
Foam::PtrList<T>::cend() const
|
||||||
|
{
|
||||||
|
return ptrs_.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
Reference in New Issue
Block a user