interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

VUtil::Iterator< T > Class Template Reference

#include <vos/vos/iterator.hh>

Inheritance diagram for VUtil::Iterator< T >:

A3DL::MaterialIterator A3DL::PortalIterator A3DL::TextureIterator VOS::ACLIterator VOS::MetaObjectIterator VOS::PCRIterator VOS::RSSEIterator VOS::RVSEIterator VOS::SiteIterator VOS::VobjectIterator List of all members.

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

Protected Types

Protected Attributes


Member Typedef Documentation

template<class T>
typedef std::vector<T>::size_type VUtil::Iterator< T >::size_type [protected]

Definition at line 81 of file iterator.hh.


Constructor & Destructor Documentation

template<class T>
VUtil::Iterator< T >::Iterator (  )  [inline]

Constructor.

Produces an empty iterator.

Definition at line 87 of file iterator.hh.

template<class T>
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.

template<class T>
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

template<class T>
bool VUtil::Iterator< T >::atStart (  )  [inline]

Returns:
true if the iterator is at the starting position

Definition at line 157 of file iterator.hh.

template<class T>
bool VUtil::Iterator< T >::hasItem ( 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.

template<class T>
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().

template<class T>
void VUtil::Iterator< T >::operator++ ( int   )  [inline]

Increment our current position.

Definition at line 126 of file iterator.hh.

template<class T>
void VUtil::Iterator< T >::operator++ (  )  [inline]

Increment our current position.

Definition at line 120 of file iterator.hh.

template<class T>
void VUtil::Iterator< T >::operator-- ( int   )  [inline]

Decrement our current position.

Definition at line 129 of file iterator.hh.

template<class T>
void VUtil::Iterator< T >::operator-- (  )  [inline]

Decrement our current position.

Definition at line 123 of file iterator.hh.

template<class T>
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.

template<class T>
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.

template<class T>
void VUtil::Iterator< T >::reset (  )  [inline]

sets the iterator to the starting position

Definition at line 160 of file iterator.hh.

template<class T>
void VUtil::Iterator< T >::setPos ( size_type  p  )  [inline]

Set the position of the iterator.

Definition at line 171 of file iterator.hh.

template<class T>
size_type VUtil::Iterator< T >::size (  )  [inline]


Member Data Documentation

template<class T>
std::vector<T>* VUtil::Iterator< T >::items [protected]

template<class T>
size_type VUtil::Iterator< T >::pos [protected]

template<class T>
int* VUtil::Iterator< T >::refcount [protected]


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