deal.II version GIT relicensing-2169-gec1b43f35b 2024-11-22 07:10:00+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
internal::BlockVectorIterators::Iterator< BlockVectorType, Constness > Class Template Reference

#include <deal.II/lac/block_vector_base.h>

Public Types

using size_type = types::global_dof_index
 
using value_type = std::conditional_t< Constness, const typename BlockVectorType::value_type, typename BlockVectorType::value_type >
 
using iterator_category = std::random_access_iterator_tag
 
using difference_type = std::ptrdiff_t
 
using reference = typename BlockVectorType::reference
 
using pointer = value_type *
 
using dereference_type = std::conditional_t< Constness, value_type, typename BlockVectorType::BlockType::reference >
 
using BlockVector = std::conditional_t< Constness, const BlockVectorType, BlockVectorType >
 

Public Member Functions

 Iterator (BlockVector &parent, const size_type global_index)
 
 Iterator (const Iterator< BlockVectorType, !Constness > &c)
 
 Iterator (const Iterator &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)
 
template<bool OtherConstness>
bool operator== (const Iterator< BlockVectorType, OtherConstness > &i) const
 
template<bool OtherConstness>
bool operator!= (const Iterator< BlockVectorType, OtherConstness > &i) const
 
template<bool OtherConstness>
bool operator< (const Iterator< BlockVectorType, OtherConstness > &i) const
 
template<bool OtherConstness>
bool operator<= (const Iterator< BlockVectorType, OtherConstness > &i) const
 
template<bool OtherConstness>
bool operator> (const Iterator< BlockVectorType, OtherConstness > &i) const
 
template<bool OtherConstness>
bool operator>= (const Iterator< BlockVectorType, OtherConstness > &i) const
 
template<bool OtherConstness>
difference_type operator- (const Iterator< BlockVectorType, OtherConstness > &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)
 

Static Public Member Functions

static ::ExceptionBaseExcPointerToDifferentVectors ()
 

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 , bool >
class Iterator
 

Detailed Description

template<typename 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.

Definition at line 120 of file block_vector_base.h.

Member Typedef Documentation

◆ size_type

template<typename BlockVectorType , bool Constness>
using internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::size_type = types::global_dof_index

Declare the type for container size.

Definition at line 126 of file block_vector_base.h.

◆ value_type

template<typename BlockVectorType , bool Constness>
using internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::value_type = std::conditional_t<Constness, const typename BlockVectorType::value_type, typename BlockVectorType::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 133 of file block_vector_base.h.

◆ iterator_category

template<typename BlockVectorType , bool Constness>
using internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::iterator_category = std::random_access_iterator_tag

Declare some aliases that are standard for iterators and are used by algorithms to enquire about the specifics of the iterators they work on. (Example: std::next(), which needs to know about a local type named difference_type.)

As for the iterator_category, C++20 has a more specialized contiguous_iterator_tag, but the elements of block vectors are not stored in a contiguous manner. They can be accessed in a random access order, though, with O(1) effort as long as we assume that the number of blocks of a vector is a constant (even though the size of the vector is not).

Definition at line 151 of file block_vector_base.h.

◆ difference_type

template<typename BlockVectorType , bool Constness>
using internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::difference_type = std::ptrdiff_t

Definition at line 152 of file block_vector_base.h.

◆ reference

template<typename BlockVectorType , bool Constness>
using internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::reference = typename BlockVectorType::reference

Definition at line 153 of file block_vector_base.h.

◆ pointer

template<typename BlockVectorType , bool Constness>
using internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::pointer = value_type *

Definition at line 154 of file block_vector_base.h.

◆ dereference_type

template<typename BlockVectorType , bool Constness>
using internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::dereference_type = std::conditional_t<Constness, value_type, typename BlockVectorType::BlockType::reference>

Definition at line 156 of file block_vector_base.h.

◆ BlockVector

template<typename BlockVectorType , bool Constness>
using internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::BlockVector = std::conditional_t<Constness, const BlockVectorType, BlockVectorType>

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

Definition at line 165 of file block_vector_base.h.

Constructor & Destructor Documentation

◆ Iterator() [1/4]

template<typename 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.

◆ Iterator() [2/4]

template<typename BlockVectorType , bool Constness>
internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::Iterator ( const Iterator< BlockVectorType, !Constness > &  c)

Copy constructor from an iterator of different constness.

Note
Constructing a non-const iterator from a const iterator does not make sense. Attempting this will result in a compile-time error (via static_assert).

◆ Iterator() [3/4]

template<typename BlockVectorType , bool Constness>
internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::Iterator ( const Iterator< BlockVectorType, Constness > &  c)

Copy constructor from an iterator with the same constness.

◆ Iterator() [4/4]

template<typename 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

◆ operator=()

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

Copy operator.

◆ operator*()

template<typename 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.

◆ operator[]()

template<typename 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.

◆ operator++() [1/2]

template<typename 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.

◆ operator++() [2/2]

template<typename 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.

◆ operator--() [1/2]

template<typename 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.

◆ operator--() [2/2]

template<typename 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.

◆ operator==()

template<typename BlockVectorType , bool Constness>
template<bool OtherConstness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::operator== ( const Iterator< BlockVectorType, OtherConstness > &  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.

◆ operator!=()

template<typename BlockVectorType , bool Constness>
template<bool OtherConstness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::operator!= ( const Iterator< BlockVectorType, OtherConstness > &  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.

◆ operator<()

template<typename BlockVectorType , bool Constness>
template<bool OtherConstness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::operator< ( const Iterator< BlockVectorType, OtherConstness > &  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.

◆ operator<=()

template<typename BlockVectorType , bool Constness>
template<bool OtherConstness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::operator<= ( const Iterator< BlockVectorType, OtherConstness > &  i) const

Comparison operator alike to the one above.

◆ operator>()

template<typename BlockVectorType , bool Constness>
template<bool OtherConstness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::operator> ( const Iterator< BlockVectorType, OtherConstness > &  i) const

Comparison operator alike to the one above.

◆ operator>=()

template<typename BlockVectorType , bool Constness>
template<bool OtherConstness>
bool internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::operator>= ( const Iterator< BlockVectorType, OtherConstness > &  i) const

Comparison operator alike to the one above.

◆ operator-() [1/2]

template<typename BlockVectorType , bool Constness>
template<bool OtherConstness>
difference_type internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::operator- ( const Iterator< BlockVectorType, OtherConstness > &  i) const

Return the distance between the two iterators, in elements.

◆ operator+()

template<typename 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.

◆ operator-() [2/2]

template<typename 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.

◆ operator+=()

template<typename 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.

◆ operator-=()

template<typename 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.

◆ move_forward()

template<typename BlockVectorType , bool Constness>
void internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::move_forward ( )
private

Move forward one element.

◆ move_backward()

template<typename BlockVectorType , bool Constness>
void internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::move_backward ( )
private

Move backward one element.

Friends And Related Symbol Documentation

◆ Iterator

template<typename BlockVectorType , bool Constness>
template<typename , bool >
friend class Iterator
friend

Definition at line 396 of file block_vector_base.h.

Member Data Documentation

◆ parent

template<typename 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 359 of file block_vector_base.h.

◆ global_index

template<typename 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 364 of file block_vector_base.h.

◆ current_block

template<typename 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 370 of file block_vector_base.h.

◆ index_within_block

template<typename BlockVectorType , bool Constness>
size_type internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::index_within_block
private

Definition at line 371 of file block_vector_base.h.

◆ next_break_forward

template<typename 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 379 of file block_vector_base.h.

◆ next_break_backward

template<typename BlockVectorType , bool Constness>
size_type internal::BlockVectorIterators::Iterator< BlockVectorType, Constness >::next_break_backward
private

Definition at line 380 of file block_vector_base.h.


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