VUtil::Iterator< T > Class Template Reference
#include <vos/vos/iterator.hh>
Inheritance diagram for VUtil::Iterator< T >:

Detailed Description
template<class T>
class VUtil::Iterator< T >
Template base class for iterators in VOS.
Subclasses dervived from Iterator are returned by various methods in VOS. Unlike some iterator patterns (such as STL iterators), this Iterator class does not iterate over the data structure directly. Instead it copies the data of interest (using operator=) into a temporary std::vector of elements. The reason for doing this is to avoid concurrency conditions: another thread changing the underlying data structure does not invalidate the iterator, nor is the calling thread required to lock the underlying data structure for any longer than the time required to make a copy. Conversely this means that an iterator can be out of date, so an iterator should not be stored for extended periods.
The underlying std::vector is reference counted and may be shared among iterators so an iterator may be efficiently copied using the copy constructor or Iterator::operator=(). Please also note that the iterator class itself is not threadsafe! If you must share it with another thread, make a copy.
Typical iterator usage looks like this:
for(ChildListIterator cli = getChildren(); cli.hasMore(); cli++) { std::cout << (*cli)->getChild()->getURLst() << std::endl; }
Definition at line 77 of file iterator.hh.
Public Member Functions
- Iterator ()
- Iterator (const Iterator &b)
- ~Iterator ()
- void operator++ ()
- void operator-- ()
- void operator++ (int)
- void operator-- (int)
- void operator= (const Iterator< T > &i)
- bool hasMore ()
- bool atStart ()
- void reset ()
- size_type size ()
- size_type remaining ()
- void setPos (size_type p)
- bool hasItem (T i)
Protected Types
Protected Attributes
Member Typedef Documentation
typedef std::vector<T>::size_type VUtil::Iterator< T >::size_type [protected] |
Definition at line 81 of file iterator.hh.
Constructor & Destructor Documentation
| VUtil::Iterator< T >::Iterator | ( | ) | [inline] |
| VUtil::Iterator< T >::Iterator | ( | const Iterator< T > & | b | ) | [inline] |
Constructor.
Copies the state of the iterator. The underlying std::vector is shared and reference counted, so this an efficient operation.
Definition at line 98 of file iterator.hh.
| VUtil::Iterator< T >::~Iterator | ( | ) | [inline] |
Destructor.
Destroys the underlying std::vector if we're the last ones to be using it.
Definition at line 108 of file iterator.hh.
Member Function Documentation
| bool VUtil::Iterator< T >::atStart | ( | ) | [inline] |
- Returns:
- true if the iterator is at the starting position
Definition at line 157 of file iterator.hh.
| bool VUtil::Iterator< T >::hasItem | ( | T | i | ) | [inline] |
- Returns:
- true if the supplied element exists in the list, as tested using operator==. This is a simple linear search.
Definition at line 183 of file iterator.hh.
| bool VUtil::Iterator< T >::hasMore | ( | ) | [inline] |
- Returns:
- true if there are valid elements remaining in the iterator (including the current one)
Definition at line 154 of file iterator.hh.
Referenced by listChildren(), listParents(), and listTypes().
| void VUtil::Iterator< T >::operator++ | ( | int | ) | [inline] |
| void VUtil::Iterator< T >::operator++ | ( | ) | [inline] |
| void VUtil::Iterator< T >::operator-- | ( | int | ) | [inline] |
| void VUtil::Iterator< T >::operator-- | ( | ) | [inline] |
| void VUtil::Iterator< T >::operator= | ( | const Iterator< T > & | i | ) | [inline] |
Copies the state of the iterator.
The underlying std::vector is shared and reference counted, so this an efficient operation.
Definition at line 135 of file iterator.hh.
| size_type VUtil::Iterator< T >::remaining | ( | ) | [inline] |
- Returns:
- number of elements still left, including the current element
Definition at line 168 of file iterator.hh.
| void VUtil::Iterator< T >::reset | ( | ) | [inline] |
| void VUtil::Iterator< T >::setPos | ( | size_type | p | ) | [inline] |
| size_type VUtil::Iterator< T >::size | ( | ) | [inline] |
- Returns:
- total number of elements in the iterator
Definition at line 163 of file iterator.hh.
Referenced by VUtil::Iterator< VOS::MetaObject * >::hasMore(), VOS::SiteIterator::operator *(), A3DL::TextureIterator::operator *(), A3DL::PortalIterator::operator *(), A3DL::MaterialIterator::operator *(), VUtil::Iterator< VOS::MetaObject * >::operator++(), and VUtil::Iterator< VOS::MetaObject * >::operator=().
Member Data Documentation
std::vector<T>* VUtil::Iterator< T >::items [protected] |
Definition at line 80 of file iterator.hh.
Referenced by VUtil::Iterator< VOS::MetaObject * >::hasItem(), VUtil::Iterator< VOS::MetaObject * >::Iterator(), A3DL::MaterialIterator::MaterialIterator(), VUtil::Iterator< VOS::MetaObject * >::operator=(), A3DL::PortalIterator::PortalIterator(), VUtil::Iterator< VOS::MetaObject * >::remaining(), VUtil::Iterator< VOS::MetaObject * >::setPos(), VOS::SiteIterator::SiteIterator(), VUtil::Iterator< VOS::MetaObject * >::size(), A3DL::TextureIterator::TextureIterator(), and VUtil::Iterator< VOS::MetaObject * >::~Iterator().
size_type VUtil::Iterator< T >::pos [protected] |
Definition at line 82 of file iterator.hh.
Referenced by VUtil::Iterator< VOS::MetaObject * >::atStart(), VUtil::Iterator< VOS::MetaObject * >::Iterator(), VOS::SiteIterator::operator *(), A3DL::TextureIterator::operator *(), A3DL::PortalIterator::operator *(), A3DL::MaterialIterator::operator *(), VUtil::Iterator< VOS::MetaObject * >::operator++(), VUtil::Iterator< VOS::MetaObject * >::operator--(), VUtil::Iterator< VOS::MetaObject * >::operator=(), VUtil::Iterator< VOS::MetaObject * >::remaining(), VUtil::Iterator< VOS::MetaObject * >::reset(), and VUtil::Iterator< VOS::MetaObject * >::setPos().
int* VUtil::Iterator< T >::refcount [protected] |
Definition at line 83 of file iterator.hh.
Referenced by VUtil::Iterator< VOS::MetaObject * >::Iterator(), VUtil::Iterator< VOS::MetaObject * >::operator=(), and VUtil::Iterator< VOS::MetaObject * >::~Iterator().
The documentation for this class was generated from the following file:
- /home/tetron/hack/vos/libs/vos/vutil/iterator.hh