GenericReader module

Module contents

template<typename sequence_object_type>
class GenericReader

Generic reader that exposes an InputIterator

This reader implements a pattern where new objects can be retrieved one at a time and exposes the resulting sequence as an InputIterator. You must implement the following method:

sequence_object_type* next_item(): Retrieve and return the next item in the sequence (or NULL if the sequence has terminated).

The template takes care of the mechanics of exposing the objects and maintaining references for as long as necessary.

You must also implement whatever machinery you need to set up the input source to the reader.

Subclassed by tracktable::TrajectoryReader< trajectory_type >

Public Types

typedef GenericInputIterator iterator

Public Functions

inline GenericReader()

Instantiate an empty reader.

inline GenericReader(GenericReader const &other)

Copy contructor, create a reader with a copy of another

Parameters:

other[in] Reader to copy from

inline virtual ~GenericReader()

Destructor for a generic reader.

inline GenericInputIterator begin()

Get an iterator pointing to the current sequence

Note

We assume that begin() will usually be called just once in order to iterate over the entire sequence from beginning to end. Since this is an InputIterator, we do not guarantee that calling begin() a second time will yield a new iterator that will reproduce the sequence. (In fact, we can almost guarantee the opposite.)

Returns:

Iterator pointing to current sequence

inline GenericInputIterator end()

Get an iterator pointing past the end of the sequence

Returns:

Iterator pointing to end of sequence

Protected Functions

virtual sequence_object_ptr next_item() = 0

Pure virtual function to get the next item in the sequence.

Private Types

typedef boost::shared_ptr<sequence_object_type> sequence_object_ptr

Private Functions

inline virtual void advance()

Advance the pointer to the next item in the sequence

inline virtual bool sequence_is_finished() const

Check if the sequence is finished

Returns:

Boolean indicating completion of sequence

Private Members

sequence_object_ptr CurrentSequenceObject
sequence_object_ptr PreviousSequenceObject
class GenericInputIterator

Generic input iterator class

Generates a iterator that can traverse the given parent generic reader sequence

Public Types

using iterator_category = std::input_iterator_tag
using value_type = sequence_object_type
using difference_type = std::ptrdiff_t
using reference = value_type const&
using const_reference = value_type const&
using pointer = value_type*
using const_pointer = const value_type*

Public Functions

inline GenericInputIterator()

Instantiate an empty input iterator.

inline GenericInputIterator(GenericReader *parent)

Copy contructor, create a input iterator with a copy of a parent GenericReader

inline GenericInputIterator(GenericInputIterator const &other)

Copy contructor, create a input iterator with a copy of another.

inline virtual ~GenericInputIterator()

Destructor for a generic input iterator.

inline GenericInputIterator &operator=(GenericInputIterator const &other)
inline bool operator==(GenericInputIterator const &other) const

Check whether one iterator is equal to another by comparing all the items.

Two items are equal if all of their points are equal.

Parameters:

other[in] Iterator for comparison

Returns:

Boolean indicating equivalency

inline bool operator!=(GenericInputIterator const &other) const

Check whether two iterators are unequal.

Parameters:

other[in] Iterator for comparison

Returns:

Boolean indicating equivalency

inline reference operator*()

Multiply an iterator.

Returns:

Result of the multiplication

inline const_reference operator*() const

Multiply an iterator.

Returns:

Result of the multiplication

inline pointer operator->()

Get the current iterator object.

Returns:

Current iterator

inline const_pointer operator->() const

Get the current iterator object.

Returns:

Current iterator

inline GenericInputIterator &operator++()

Advance the iterator to the next position in the sequence.

Throws:

std::runtime_error – If iterator is at the end of the sequence

Returns:

Pointer to the next iterator in the sequence

inline GenericInputIterator operator++(int)

Advance the iterator to the next position in the sequence.

Throws:

std::runtime_error – If iterator is at the end of the sequence

Returns:

Pointer to the next iterator in the sequence

Private Types

typedef boost::shared_ptr<sequence_object_type> sequence_object_ptr

Private Members

sequence_object_ptr CurrentSequenceObject
GenericReader *Parent