Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
internal::BlockVectorIterators::Iterator< BlockVectorType, constness > Class Template Reference

#include <block_vector_base.h>

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

Public Types

typedef types::global_dof_index size_type
 
typedef Types< BlockVectorType,
constness >::value_type 
value_type
 
typedef
std::random_access_iterator_tag 
iterator_type
 
typedef std::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 size_type 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)
 
 DeclException0 (ExcPointerToDifferentVectors)
 
 DeclException0 (ExcCastingAwayConstness)
 

Private Types

typedef Iterator
< BlockVectorType,!constness > 
InverseConstnessIterator
 

Private Member Functions

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

Private Attributes

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

Friends

template<typename N , bool C>
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

Definition at line 293 of file block_vector_base.h.

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.

Definition at line 304 of file block_vector_base.h.

template<class BlockVectorType, bool constness>
typedef types::global_dof_index internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::size_type

Declare the type for container size.

Definition at line 310 of file block_vector_base.h.

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.

Definition at line 323 of file block_vector_base.h.

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.

Definition at line 333 of file block_vector_base.h.

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).

Definition at line 351 of file block_vector_base.h.

Constructor & Destructor Documentation

template<class BlockVectorType, bool constness>
internal::BlockVectorIterators::Iterator< BlockVectorType, constness >::Iterator ( BlockVector parent,
const size_type  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 size_type  global_index,
const size_type  current_block,
const size_type  index_within_block,
const size_type  next_break_forward,
const size_type  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>
template<typename N , bool C>
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.

Definition at line 674 of file block_vector_base.h.

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.

Definition at line 620 of file block_vector_base.h.

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

Global index of the element to which we presently point.

Definition at line 627 of file block_vector_base.h.

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.

Definition at line 635 of file block_vector_base.h.

template<class BlockVectorType, bool constness>
size_type 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.

Definition at line 650 of file block_vector_base.h.


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