StreamIterator Class Reference

StreamIterator Class Reference
+ Related help topics:

#include <adskDataStreamIterator.h>

Class Description

Class handling iteration over Stream members.

The Stream data is not necessarily stored sequentially or as a packed array so this iterator is necessary in order to provide a consistent way to access all Stream elements.

By default the Handle pointed to by the iterator will be positioned at the first Structure member. If you wish a different member you should reposition it after retrieval. (It's recommended for efficiency that you position by Member index rather than by name since that works faster.)

For technical reasons this class lives outside the Stream though really it is part of it. A typedef is set up inside the Stream so that you can use it like a standard iterator:

for( Stream::iterator iterator = myStream.begin(); iterator != myStream.end(); ++iterator ) { processMember( *iterator ); }

If you are processing multiple independent values in your Structure it's most efficient to run multiple loops repositioning the Handle between each loop:

Stream::iterator idIterator = myStream.begin(); colorIterator->setPositionByMemberName( "ID" ); for( ; iterator != myStream.end(); ++iterator ) { processIDMember( iterator->asInt32() ); } Stream::iterator colorIterator = myStream.begin(); colorIterator->setPositionByMemberName( "Color" ); for( ; iterator != myStream.end(); ++iterator ) { processColorMember( iterator->asFloat() ); }

If the values are not independent and are needed at the same time you can still access both values within the same loop by repositioning the Handle each time through the loop:

for( Stream::iterator iterator = myStream.begin(); iterator != myStream.end(); ++iterator ) { iterator->setPositionByMemberIndex( 0 ); int* idValue = iterator->asInt32(); iterator->setPositionByMemberIndex( 1 ); float* colorValues = iterator->asFloat(); processData( idValue, colorValues ); }

+ Examples:

Public Member Functions

 StreamIterator ()
 Default constructor. More...
 
 ~StreamIterator ()
 Destructor, does nothing.
 
 StreamIterator (const StreamIterator &)
 Copy constructor. More...
 
StreamIteratoroperator= (const StreamIterator &)
 Assignment operator. More...
 
bool operator!= (const StreamIterator &) const
 Check to see if this iterator is not equal to the given one. More...
 
bool operator== (const StreamIterator &) const
 Check to see if this iterator is equal to the given one. More...
 
Handleoperator* ()
 Get a reference to the data at the current location of the iterator. More...
 
const Handleoperator* () const
 Get a reference to the data at the current location of the iterator (const version) More...
 
Handleoperator-> ()
 Get the data at the current location of the iterator. More...
 
const Handleoperator-> () const
 Get the data at the current location of the iterator (const version) More...
 
StreamIteratoroperator++ ()
 Pre-increment operator. More...
 
StreamIterator operator++ (int)
 Post-increment operator. More...
 
bool valid () const
 Determine if the iterator is currently pointing to a valid Member. More...
 
Index index () const
 Get the Index for the current iteration position. More...
 

Protected Member Functions

StreamIteratorImpl const & impl () const
 Get the implementation class in const form. More...
 
StreamIteratorImpl & impl ()
 Get the implementation class. More...
 
 StreamIterator (StreamIteratorImpl *)
 Usual constructor, uses an implementation-specific iterator as the actual implementaton of this iterator. More...
 

Friends

class Stream
 Real implementation of the iterator.
 

Constructor & Destructor Documentation

Default constructor.

Should only be used as a temporary object before an assignment operator.

Any access operations called on an iterator with no implementaiton will throw an exception.

StreamIterator ( const StreamIterator rhs)

Copy constructor.

Parameters
[in]rhsIterator to copy
StreamIterator ( StreamIteratorImpl *  myImpl)
protected

Usual constructor, uses an implementation-specific iterator as the actual implementaton of this iterator.

Calls are all forwarded.

Parameters
[in]myImplImplementation of the iterator

Member Function Documentation

StreamIterator & operator= ( const StreamIterator rhs)

Assignment operator.

Copy the members, as pointers.

This copy means that any two iterators constructed or copied from one another will actually point to the same spot in the iteration

Parameters
[in]rhsIterator to copy
bool operator!= ( const StreamIterator rhs) const

Check to see if this iterator is not equal to the given one.

Parameters
[in]rhsIterator to compare against
Returns
True if the two iterators are not the same
bool operator== ( const StreamIterator rhs) const

Check to see if this iterator is equal to the given one.

Parameters
[in]rhsIterator to compare against
Returns
True if the two iterators are equivalent
Handle & operator* ( )

Get a reference to the data at the current location of the iterator.

Exceptions
std::out_of_rangeiterator is past the end.
std::runtime_errorThrown when no implementation is present
Returns
Reference to the current element Handle, throws if iteration is done
const Handle & operator* ( ) const

Get a reference to the data at the current location of the iterator (const version)

The value returned is the Stream element Index. The Handle containing the actual value is always accessible through the handle() method.

Exceptions
std::out_of_rangeiterator is past the end.
std::runtime_errorThrown when no implementation is present
Returns
Reference to the current element Handle, throws if iteration is done
Handle * operator-> ( )

Get the data at the current location of the iterator.

Exceptions
std::out_of_rangeiterator is past the end.
std::runtime_errorThrown when no implementation is present
Returns
Pointer to the current element Handle, throws if iteration is done
const Handle * operator-> ( ) const

Get the data at the current location of the iterator (const version)

Exceptions
std::out_of_rangeiterator is past the end.
std::runtime_errorThrown when no implementation is present
Returns
Pointer to the current element Handle, throws if iteration is done
StreamIterator & operator++ ( )

Pre-increment operator.

Returns
Reference to this iterator, to allow use as a lhs
StreamIterator operator++ ( int  value)

Post-increment operator.

Makes a copy - use pre-increment where possible

Parameters
[in]valueIgnored
Returns
Copy of the iterator before the advance
bool valid ( ) const

Determine if the iterator is currently pointing to a valid Member.

Returns
True if the iterator position is legal (i.e. not done)
Index index ( ) const

Get the Index for the current iteration position.

Exceptions
std::runtime_errorThrown when no implementation is present
Returns
Index where this Stream Iterator is pointed
StreamIteratorImpl const & impl ( ) const
protected

Get the implementation class in const form.

Exceptions
std::runtime_errorThrown when no implementation is present
Returns
Const reference to this class's implementation object
StreamIteratorImpl & impl ( )
protected

Get the implementation class.

Exceptions
std::runtime_errorThrown when no implementation is present
Returns
Reference to this class's implementation object

The documentation for this class was generated from the following files:
  • adskDataStreamIterator.h
  • adskDataStreamIterator.cpp