IODA Bundle
odc::SharedIterator< T > Class Template Reference

Represents a smart iterator. More...

#include <SharedIterator.h>

Public Types

typedef T::difference_type difference_type
 Difference type of the managed iterator. Provided for compatibility with C++ STL algorithms. More...
 
typedef T::value_type value_type
 Value type of the managed iterator. Provided for compatibility with C++ STL algorithms. More...
 
typedef T::reference reference
 Reference type of the managed iterator. Provided for compatibility with C++ STL algorithms. More...
 
typedef T::pointer pointer
 Pointer type of the managed iterator. Provided for compatibility with C++ STL algorithms. More...
 
typedef T::iterator_category iterator_category
 Cagegory of the managed iterator. Provided for compatibility with C++ STL algorithms. More...
 

Public Member Functions

template<typename U >
 SharedIterator (U *it)
 Creates a smart iterator. More...
 
 SharedIterator (const SharedIterator &other)
 Creates a smart iterator which shares ownership of the iterator object managed by the other smart iterator. More...
 
template<typename U >
 SharedIterator (const SharedIterator< U > &other)
 Creates a smart iterator which shares ownership of the iterator object managed by the other smart iterator. More...
 
 ~SharedIterator ()
 Destroys the managed iterator if there are no more SharedIterator instances referring to it. More...
 
SharedIteratoroperator= (const SharedIterator &other)
 Replaces the wrapped iterator object with the one managed by other. More...
 
bool operator== (const SharedIterator &other)
 Compares two managed iterator objects. More...
 
bool operator!= (const SharedIterator &other)
 Compares two managed iterator objects. More...
 
SharedIteratoroperator++ ()
 Increments the managed iterator object. More...
 
reference operator* () const
 Dereferences the managed iterator object. More...
 
pointer operator-> () const
 Dereferences the managed iterator object. More...
 
T * get () const
 Returns pointer to the managed iterator object. More...
 
bool unique () const
 Checks if this is the only SharedIterator instance managing the iterator object. More...
 
long useCount () const
 Returns the number of SharedIterator instances (including this) managing the same iterator object. More...
 

Private Member Functions

void destruct ()
 

Private Attributes

T * it_
 
long * useCount_
 

Detailed Description

template<typename T>
class odc::SharedIterator< T >

Represents a smart iterator.

The SharedIterator class uses reference counting to manage shared ownership of an iterator object. Several instances of SharedIterator may refer to the same iterator object. The managed iterator object is destroyed only when the last SharedIterator pointing to it is destroyed.

See also
IteratorFacade
Todo:
Write some test cases.

Definition at line 20 of file SharedIterator.h.

Member Typedef Documentation

◆ difference_type

template<typename T >
typedef T::difference_type odc::SharedIterator< T >::difference_type

Difference type of the managed iterator. Provided for compatibility with C++ STL algorithms.

Definition at line 26 of file SharedIterator.h.

◆ iterator_category

template<typename T >
typedef T::iterator_category odc::SharedIterator< T >::iterator_category

Cagegory of the managed iterator. Provided for compatibility with C++ STL algorithms.

Definition at line 46 of file SharedIterator.h.

◆ pointer

template<typename T >
typedef T::pointer odc::SharedIterator< T >::pointer

Pointer type of the managed iterator. Provided for compatibility with C++ STL algorithms.

Definition at line 41 of file SharedIterator.h.

◆ reference

template<typename T >
typedef T::reference odc::SharedIterator< T >::reference

Reference type of the managed iterator. Provided for compatibility with C++ STL algorithms.

Definition at line 36 of file SharedIterator.h.

◆ value_type

template<typename T >
typedef T::value_type odc::SharedIterator< T >::value_type

Value type of the managed iterator. Provided for compatibility with C++ STL algorithms.

Definition at line 31 of file SharedIterator.h.

Constructor & Destructor Documentation

◆ SharedIterator() [1/3]

template<typename T >
template<typename U >
odc::SharedIterator< T >::SharedIterator ( U *  it)
inlineexplicit

Creates a smart iterator.

This templated constructor allows to create a new SharedIterator instance from any pointer to an iterator object it that is implicitly convertible to type T.

Warning
If the iterator object pointed to by it is already owned by some other SharedIterator instance, the usage of this SharedIterator will result in undefined behavior.

Definition at line 59 of file SharedIterator.h.

◆ SharedIterator() [2/3]

template<typename T >
odc::SharedIterator< T >::SharedIterator ( const SharedIterator< T > &  other)
inline

Creates a smart iterator which shares ownership of the iterator object managed by the other smart iterator.

Definition at line 69 of file SharedIterator.h.

◆ SharedIterator() [3/3]

template<typename T >
template<typename U >
odc::SharedIterator< T >::SharedIterator ( const SharedIterator< U > &  other)
inline

Creates a smart iterator which shares ownership of the iterator object managed by the other smart iterator.

This templated copy-constructor allows to create new SharedIterator from any other SharedIterator who's iterator type is implicitly convertible to T.

Definition at line 84 of file SharedIterator.h.

◆ ~SharedIterator()

template<typename T >
odc::SharedIterator< T >::~SharedIterator ( )
inline

Destroys the managed iterator if there are no more SharedIterator instances referring to it.

Definition at line 93 of file SharedIterator.h.

Here is the call graph for this function:

Member Function Documentation

◆ destruct()

template<typename T >
void odc::SharedIterator< T >::destruct ( )
inlineprivate

Definition at line 162 of file SharedIterator.h.

Here is the caller graph for this function:

◆ get()

template<typename T >
T* odc::SharedIterator< T >::get ( ) const
inline

Returns pointer to the managed iterator object.

Definition at line 139 of file SharedIterator.h.

Here is the caller graph for this function:

◆ operator!=()

template<typename T >
bool odc::SharedIterator< T >::operator!= ( const SharedIterator< T > &  other)
inline

Compares two managed iterator objects.

Definition at line 120 of file SharedIterator.h.

◆ operator*()

template<typename T >
reference odc::SharedIterator< T >::operator* ( ) const
inline

Dereferences the managed iterator object.

Definition at line 133 of file SharedIterator.h.

◆ operator++()

template<typename T >
SharedIterator& odc::SharedIterator< T >::operator++ ( )
inline

Increments the managed iterator object.

Definition at line 126 of file SharedIterator.h.

◆ operator->()

template<typename T >
pointer odc::SharedIterator< T >::operator-> ( ) const
inline

Dereferences the managed iterator object.

Definition at line 136 of file SharedIterator.h.

◆ operator=()

template<typename T >
SharedIterator& odc::SharedIterator< T >::operator= ( const SharedIterator< T > &  other)
inline

Replaces the wrapped iterator object with the one managed by other.

Definition at line 99 of file SharedIterator.h.

Here is the call graph for this function:

◆ operator==()

template<typename T >
bool odc::SharedIterator< T >::operator== ( const SharedIterator< T > &  other)
inline

Compares two managed iterator objects.

Definition at line 114 of file SharedIterator.h.

◆ unique()

template<typename T >
bool odc::SharedIterator< T >::unique ( ) const
inline

Checks if this is the only SharedIterator instance managing the iterator object.

Retuns true if this is the only SharedIterator instance managing the current iterator object (i.e. useCount() == 1), otherwise returns false.

Definition at line 148 of file SharedIterator.h.

◆ useCount()

template<typename T >
long odc::SharedIterator< T >::useCount ( ) const
inline

Returns the number of SharedIterator instances (including this) managing the same iterator object.

Definition at line 156 of file SharedIterator.h.

Member Data Documentation

◆ it_

template<typename T >
T* odc::SharedIterator< T >::it_
private

Definition at line 171 of file SharedIterator.h.

◆ useCount_

template<typename T >
long* odc::SharedIterator< T >::useCount_
private

Definition at line 172 of file SharedIterator.h.


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