Guiliani  Version 2.5 revision 7293 (documentation build 13)
eC_TSafeIterator< T > Class Template Reference

An iterator that stays valid even if elements are deleted from the list. More...

#include <eC_TList_Iterators.h>

Inheritance diagram for eC_TSafeIterator< T >:

Public Member Functions

 eC_TSafeIterator ()
 
 eC_TSafeIterator (const eC_TSafeIterator< T > &kIter)
 
virtual eC_Bool IsInsideList () const
 
eC_Bool IsNextValid () const
 
eC_Bool IsPreviousValid () const
 
eC_Bool operator!= (const eC_TSafeIterator &kIter)
 
eC_TSafeIteratoroperator++ ()
 
eC_TSafeIteratoroperator-- ()
 
eC_TSafeIteratoroperator= (const eC_TSafeIterator &kIter)
 
eC_Bool operator== (const eC_TSafeIterator &kIter) const
 
- Public Member Functions inherited from eC_TIterator< T >
 eC_TIterator ()
 
 eC_TIterator (const eC_TIterator< T > &x)
 
 eC_TIterator (Node *pNode)
 
virtual ~eC_TIterator ()
 Destructor.
 
virtual eC_Bool IsInsideList () const
 
eC_Bool IsValid () const
 
eC_Bool operator!= (const eC_TIterator &kIter) const
 
T & operator* ()
 
eC_TIteratoroperator++ ()
 
eC_TIterator operator++ (int)
 
eC_TIteratoroperator-- ()
 
eC_TIterator operator-- (int)
 
eC_TIteratoroperator= (const eC_TIterator &kIter)
 
eC_Bool operator== (const eC_TIterator &kIter) const
 
eC_Bool operator== (const Node *const ptrNode) const
 

Friends

class eC_TListDoubleLinked< T >
 

Additional Inherited Members

- Protected Types inherited from eC_TIterator< T >
typedef ListNode< T > Node
 typedef for node
 
- Protected Member Functions inherited from eC_TIterator< T >
NodeGetNode () const
 
- Protected Attributes inherited from eC_TIterator< T >
Nodem_pNode
 this node More...
 

Detailed Description

template<class T>
class eC_TSafeIterator< T >

An iterator that stays valid even if elements are deleted from the list.

With safe iterators it is possible to remove elements while iterating through a list.

With IsValid() it can be tested if the iterator may be dereferenced. If an item is deleted, the iterator is invalid, but you can still iterate through the list. After the next step (increment or decrement) the iterator is valid again (until you remove another element). After sorting and eC_TListDoubleLinked<T>::RemoveAll() all safe iterators are invalid and have to be set again.

Example:

for (my_SafeIterator = m_list.GetBegin(); my_SafeIterator.InsideList(); ++my_SafeIterator)
{
if (*my_SafeIterator == testValue)
{
m_list.Remove(testValue);
}
if (my_SafeIterator.IsValid())
{
// The iterator is still valid and can be used to get a reference to
// the element.
cout << *my_SafeIterator << endl;
}
else
{
// If testValue was removed, the iterator cannot be used to get
// reference to the element.
cout << "Value invalid" << endl;
}
}
An iterator that stays valid even if elements are deleted from the list.
Definition: eC_TList_Iterators.h:313

If you remove an item and add one at the position of the removed element (in one iteration step) it is possible that the new element is "lost" in that iteration.

Example

3-5-8

5 is deleted 7 is added

3-7-8

In this case 7 will be "lost" if iterator pointed at 5, because iterator is now pointing at 7, and after next iteration step it will be pointing at 8.

Note: This iterator does not have postfix increment/decrement operators because implementing them for the current approach for this safe iterator is not effective.

Constructor & Destructor Documentation

◆ eC_TSafeIterator() [1/2]

template<class T >
eC_TSafeIterator< T >::eC_TSafeIterator ( )
inline

Constructor needs pointer to list, iterator will be used with. This is necessary to register iterator in this list, so that iterators can be updated if list is modified.

◆ eC_TSafeIterator() [2/2]

template<class T >
eC_TSafeIterator< T >::eC_TSafeIterator ( const eC_TSafeIterator< T > &  kIter)
inline

Copy constructor.

Parameters
kIterWhere to copy from

Member Function Documentation

◆ IsInsideList()

template<class T >
virtual eC_Bool eC_TSafeIterator< T >::IsInsideList ( ) const
inlinevirtual

!DO NOT USE WHEN ITERATING BACKWARDS AND DELETING NODES! Use FOR_ALL_BACKWARD_SAFE instead. Used to test if iterator is not pointing beyond list.

Returns
True, if iterator is pointing an element of the list, false if iterator is pointing in front of first or behind last list element.

Reimplemented from eC_TIterator< T >.

◆ IsNextValid()

template<class T >
eC_Bool eC_TSafeIterator< T >::IsNextValid ( ) const
inline
Returns
Returns if a valid node is available behind the current node.

◆ IsPreviousValid()

template<class T >
eC_Bool eC_TSafeIterator< T >::IsPreviousValid ( ) const
inline
Returns
Returns if a valid node is available in front of the current node.

◆ operator!=()

template<class T >
eC_Bool eC_TSafeIterator< T >::operator!= ( const eC_TSafeIterator< T > &  kIter)
inline

Used to compare two Iterators.

Parameters
kIterWhat to compare with
Returns
False, if iterators are pointing to the same list element and iterator would behave in the same way in case of iteration, True if not

◆ operator++()

template<class T >
eC_TSafeIterator & eC_TSafeIterator< T >::operator++ ( )
inline

Used to increment Iterator. Prefix version. Iterator is pointing to next list element.

Returns
Unchanged iterator. If current element is beyond the end of the list then an interator will be returned that will evaluate IsInsideList() to false, as before.

◆ operator--()

template<class T >
eC_TSafeIterator & eC_TSafeIterator< T >::operator-- ( )
inline

Used to decrement Iterator. Prefix version. Iterator is pointing to previous list element.

Returns
Unchanged iterator. If current element is beyond the beginning of the list then an interator will be returned that will evaluate IsInsideList() to false, as before.

◆ operator=()

template<class T >
eC_TSafeIterator & eC_TSafeIterator< T >::operator= ( const eC_TSafeIterator< T > &  kIter)
inline

Assignment operator.

Returns
eC_TSafeIterator& to local node after assignment
Parameters
kIterWhere to copy from

◆ operator==()

template<class T >
eC_Bool eC_TSafeIterator< T >::operator== ( const eC_TSafeIterator< T > &  kIter) const
inline

Used to compare two iterators.

Parameters
kIterWhat to compare with
Returns
True, if iterators are pointing to the same list element and iterator would behave in the same way in case of iteration, False if not

The documentation for this class was generated from the following file: