internal::BlockVectorIterators::Iterator< BlockVectorType, constness > Class Template Reference

Inheritance diagram for internal::BlockVectorIterators::Iterator< BlockVectorType, constness >:

Inheritance graph
[legend]

List of all members.

Classes

class  ExcCastingAwayConstness
class  ExcPointerToDifferentVectors

Public Types

typedef Types< BlockVectorType,
constness >::value_type 
value_type
typedef
std::random_access_iterator_tag 
iterator_type
typedef ptrdiff_t difference_type
typedef BlockVectorType::reference reference
typedef value_typepointer
typedef Types< BlockVectorType,
constness >::dereference_type 
dereference_type
typedef Types< BlockVectorType,
constness >::BlockVector 
BlockVector

Public Member Functions

 Iterator (BlockVector &parent, const unsigned int global_index)
 Iterator (const Iterator< BlockVectorType, constness > &c)
 Iterator (const InverseConstnessIterator &c)
Iteratoroperator= (const Iterator &c)
dereference_type operator* () const
dereference_type operator[] (const difference_type d) const
Iteratoroperator++ ()
Iterator operator++ (int)
Iteratoroperator-- ()
Iterator operator-- (int)
bool operator== (const Iterator &i) const
bool operator== (const InverseConstnessIterator &i) const
bool operator!= (const Iterator &i) const
bool operator!= (const InverseConstnessIterator &i) const
bool operator< (const Iterator &i) const
bool operator< (const InverseConstnessIterator &i) const
bool operator<= (const Iterator &i) const
bool operator<= (const InverseConstnessIterator &i) const
bool operator> (const Iterator &i) const
bool operator> (const InverseConstnessIterator &i) const
bool operator>= (const Iterator &i) const
bool operator>= (const InverseConstnessIterator &i) const
difference_type operator- (const Iterator &i) const
difference_type operator- (const InverseConstnessIterator &i) const
Iterator operator+ (const difference_type &d) const
Iterator operator- (const difference_type &d) const
Iteratoroperator+= (const difference_type &d)
Iteratoroperator-= (const difference_type &d)

Private Types

typedef Iterator
< BlockVectorType,!constness > 
InverseConstnessIterator

Private Member Functions

 Iterator (BlockVector &parent, const unsigned int global_index, const unsigned int current_block, const unsigned int index_within_block, const unsigned int next_break_forward, const unsigned int next_break_backward)
void move_forward ()
void move_backward ()

Private Attributes

BlockVectorparent
unsigned int global_index
unsigned int current_block
unsigned int index_within_block
unsigned int next_break_forward
unsigned int next_break_backward

Friends

class Iterator


Detailed Description

template<class BlockVectorType, bool constness>
class internal::BlockVectorIterators::Iterator< BlockVectorType, constness >

General random-access iterator class for block vectors. Since we do not want to have two classes for non-const iterator and const_iterator, we take a second template argument which denotes whether the vector we point into is a constant object or not. The first template argument is always the number type of the block vector in use.

This class satisfies all requirements of random access iterators defined in the C++ standard. Operations on these iterators are constant in the number of elements in the block vector. However, they are sometimes linear in the number of blocks in the vector, but since that does rarely change dynamically within an application, this is a constant and we again have that the iterator satisfies the requirements of a random access iterator.

The implementation of this class has to work around some problems in compilers and standard libraries. One of these requires us to write all comparison operators twice, once comparison with iterators of the same type and once with iterators pointing to numbers of opposite constness specification. The reason is that if we would have written the comparison operators as a template on the constness of the right hand side, then gcc2.95 signals an error that these operators ambiguate operators declared somewhere within the standard library. Likewise, we have to work around some problems with granting other iterators friendship. This makes the implementation somewhat non-optimal at places, but at least everything works.

Author:
Wolfgang Bangerth, 2001

Member Typedef Documentation

template<class BlockVectorType, bool constness>
typedef Iterator<BlockVectorType,!constness> internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::InverseConstnessIterator [private]

Typedef an iterator with opposite constness requirements on the elements it points to.

template<class BlockVectorType, bool constness>
typedef Types<BlockVectorType,constness>::value_type internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::value_type

Type of the number this iterator points to. Depending on the value of the second template parameter, this is either a constant or non-const number.

template<class BlockVectorType, bool constness>
typedef std::random_access_iterator_tag internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::iterator_type

Declare some typedefs which are standard for iterators and are used by algorithms to enquire about the specifics of the iterators they work on.

template<class BlockVectorType, bool constness>
typedef ptrdiff_t internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::difference_type

template<class BlockVectorType, bool constness>
typedef BlockVectorType::reference internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::reference

template<class BlockVectorType, bool constness>
typedef value_type* internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::pointer

template<class BlockVectorType, bool constness>
typedef Types<BlockVectorType,constness>::dereference_type internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::dereference_type

template<class BlockVectorType, bool constness>
typedef Types<BlockVectorType,constness>::BlockVector internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::BlockVector

Typedef the type of the block vector (which differs in constness, depending on the second template parameter).


Constructor & Destructor Documentation

template<class BlockVectorType, bool constness>
internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::Iterator ( BlockVector parent,
const unsigned int  global_index 
)

Construct an iterator from a vector to which we point and the global index of the element pointed to.

Depending on the value of the constness template argument of this class, the first argument of this constructor is either is a const or non-const reference.

template<class BlockVectorType, bool constness>
internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::Iterator ( const Iterator< BlockVectorType, constness > &  c  ) 

Copy constructor.

template<class BlockVectorType, bool constness>
internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::Iterator ( const InverseConstnessIterator< BlockVectorType, constness > &  c  ) 

Copy constructor for conversion between iterators with different constness requirements. This constructor throws an error if an attempt is made at converting a constant to a non-constant iterator.

template<class BlockVectorType, bool constness>
internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::Iterator ( BlockVector parent,
const unsigned int  global_index,
const unsigned int  current_block,
const unsigned int  index_within_block,
const unsigned int  next_break_forward,
const unsigned int  next_break_backward 
) [private]

Constructor used internally in this class. The arguments match exactly the values of the respective member variables.


Member Function Documentation

template<class BlockVectorType, bool constness>
Iterator& internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator= ( const Iterator< BlockVectorType, constness > &  c  ) 

Copy operator.

template<class BlockVectorType, bool constness>
dereference_type internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator* (  )  const

Dereferencing operator. If the template argument constness is true, then no writing to the result is possible, making this a const_iterator.

template<class BlockVectorType, bool constness>
dereference_type internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator[] ( const difference_type  d  )  const

Random access operator, grant access to arbitrary elements relative to the one presently pointed to.

template<class BlockVectorType, bool constness>
Iterator& internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator++ (  ) 

Prefix increment operator. This operator advances the iterator to the next element and returns a reference to *this.

template<class BlockVectorType, bool constness>
Iterator internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator++ ( int   ) 

Postfix increment operator. This operator advances the iterator to the next element and returns a copy of the old value of this iterator.

template<class BlockVectorType, bool constness>
Iterator& internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator-- (  ) 

Prefix decrement operator. This operator retracts the iterator to the previous element and returns a reference to *this.

template<class BlockVectorType, bool constness>
Iterator internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator-- ( int   ) 

Postfix decrement operator. This operator retracts the iterator to the previous element and returns a copy of the old value of this iterator.

template<class BlockVectorType, bool constness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator== ( const Iterator< BlockVectorType, constness > &  i  )  const

Compare for equality of iterators. This operator checks whether the vectors pointed to are the same, and if not it throws an exception.

template<class BlockVectorType, bool constness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator== ( const InverseConstnessIterator< BlockVectorType, constness > &  i  )  const

Same, but compare with an iterator of different constness.

template<class BlockVectorType, bool constness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator!= ( const Iterator< BlockVectorType, constness > &  i  )  const

Compare for inequality of iterators. This operator checks whether the vectors pointed to are the same, and if not it throws an exception.

template<class BlockVectorType, bool constness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator!= ( const InverseConstnessIterator< BlockVectorType, constness > &  i  )  const

Same, but compare with an iterator of different constness.

template<class BlockVectorType, bool constness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator< ( const Iterator< BlockVectorType, constness > &  i  )  const

Check whether this iterators points to an element previous to the one pointed to by the given argument. This operator checks whether the vectors pointed to are the same, and if not it throws an exception.

template<class BlockVectorType, bool constness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator< ( const InverseConstnessIterator< BlockVectorType, constness > &  i  )  const

Same, but compare with an iterator of different constness.

template<class BlockVectorType, bool constness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator<= ( const Iterator< BlockVectorType, constness > &  i  )  const

Comparison operator alike to the one above.

template<class BlockVectorType, bool constness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator<= ( const InverseConstnessIterator< BlockVectorType, constness > &  i  )  const

Same, but compare with an iterator of different constness.

template<class BlockVectorType, bool constness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator> ( const Iterator< BlockVectorType, constness > &  i  )  const

Comparison operator alike to the one above.

template<class BlockVectorType, bool constness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator> ( const InverseConstnessIterator< BlockVectorType, constness > &  i  )  const

Same, but compare with an iterator of different constness.

template<class BlockVectorType, bool constness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator>= ( const Iterator< BlockVectorType, constness > &  i  )  const

Comparison operator alike to the one above.

template<class BlockVectorType, bool constness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator>= ( const InverseConstnessIterator< BlockVectorType, constness > &  i  )  const

Same, but compare with an iterator of different constness.

template<class BlockVectorType, bool constness>
difference_type internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator- ( const Iterator< BlockVectorType, constness > &  i  )  const

Return the distance between the two iterators, in elements.

template<class BlockVectorType, bool constness>
difference_type internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator- ( const InverseConstnessIterator< BlockVectorType, constness > &  i  )  const

Same, but for iterators of opposite constness.

template<class BlockVectorType, bool constness>
Iterator internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator+ ( const difference_type d  )  const

Return an iterator which is the given number of elements in front of the present one.

template<class BlockVectorType, bool constness>
Iterator internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator- ( const difference_type d  )  const

Return an iterator which is the given number of elements behind the present one.

template<class BlockVectorType, bool constness>
Iterator& internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator+= ( const difference_type d  ) 

Move the iterator d elements forward at once, and return the result.

template<class BlockVectorType, bool constness>
Iterator& internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::operator-= ( const difference_type d  ) 

Move the iterator d elements backward at once, and return the result.

template<class BlockVectorType, bool constness>
void internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::move_forward (  )  [private]

Move forward one element.

template<class BlockVectorType, bool constness>
void internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::move_backward (  )  [private]

Move backward one element.


Friends And Related Function Documentation

template<class BlockVectorType, bool constness>
friend class Iterator [friend]

Mark all other instances of this template as friends. In fact, we only need the inverse constness iterator as friend, but this is something that ISO C++ does not allow to specify. If we have detected a compiler bug during configuration of the library, use a workaround that works for this particular compiler, but is not ISO C++ conforming.


Member Data Documentation

template<class BlockVectorType, bool constness>
BlockVector* internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::parent [private]

Pointer to the block vector object to which this iterator points. Depending on the value of the constness template argument of this class, this is a const or non-const pointer.

template<class BlockVectorType, bool constness>
unsigned int internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::global_index [private]

Global index of the element to which we presently point.

template<class BlockVectorType, bool constness>
unsigned int internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::current_block [private]

Current block and index within this block of the element presently pointed to.

template<class BlockVectorType, bool constness>
unsigned int internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::index_within_block [private]

template<class BlockVectorType, bool constness>
unsigned int internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::next_break_forward [private]

Indices of the global element address at which we have to move on to another block when moving forward and backward. These indices are kept as a cache since this is much more efficient than always asking the parent object.

template<class BlockVectorType, bool constness>
unsigned int internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::next_break_backward [private]


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

deal.II documentation generated on Sat Aug 15 16:52:37 2009 by doxygen 1.5.9