OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
pfc::MultiIndex< D > Class Template Reference

MultiIndex class for iterating over multi-dimensional indices. More...

#include <multi_index.hpp>

Classes

class  Iterator
 Iterator class for iterating over multi-dimensional indices. More...
 

Public Member Functions

 MultiIndex (std::array< int, D > size, std::array< int, D > offset=std::array< int, D >())
 Constructs a MultiIndex object with the specified offset and size in each dimension.
 
const std::array< int, D > & get_begin () const
 
const std::array< int, D > & get_size () const
 
const std::array< int, D > & get_end () const
 
const size_tget_linear_begin () const
 
const size_tget_linear_size () const
 
const size_tget_linear_end () const
 
size_t to_linear (const std::array< int, D > &indices) const
 Converts a multi-dimensional index to its corresponding linear index.
 
std::array< int, D > to_multi (size_t idx) const
 Converts a linear index to its corresponding multi-dimensional indices.
 
bool inbounds (const std::array< int, D > &indices) const
 Checks whether given indices are in bounds or not.
 
Iterator begin ()
 Returns an iterator pointing to the beginning of the range.
 
Iterator end ()
 Returns an iterator pointing to the end of the range.
 
Iterator begin () const
 Returns a const iterator pointing to the beginning of the range.
 
Iterator end () const
 Returns a const iterator pointing to the end of the range.
 
Iterator from (std::array< int, D > from)
 Returns an iterator starting from the specified multi-dimensional indices.
 
Iterator from (size_t from)
 Returns an iterator starting from the specified linear index.
 

Friends

class Iterator
 
std::ostream & operator<< (std::ostream &os, const MultiIndex< D > &index)
 Outputs the index to the specified output stream.
 

Detailed Description

template<size_t D>
class pfc::MultiIndex< D >

MultiIndex class for iterating over multi-dimensional indices.

The MultiIndex class provides a convenient way to iterate over multi-dimensional indices. It supports iterating over a range defined by an offset and size in each dimension. The class also provides conversion functions between linear and multi-dimensional indices.

Template Parameters
DThe number of dimensions.
Examples
06_multi_index.cpp.

Constructor & Destructor Documentation

◆ MultiIndex()

template<size_t D>
pfc::MultiIndex< D >::MultiIndex ( std::array< int, D >  size,
std::array< int, D >  offset = std::array<int, D>() 
)
inline

Constructs a MultiIndex object with the specified offset and size in each dimension.

Parameters
sizeThe size of the range in each dimension.
offsetThe offset of the range in each dimension (default: 0)

Member Function Documentation

◆ begin() [1/2]

template<size_t D>
Iterator pfc::MultiIndex< D >::begin ( )
inline

Returns an iterator pointing to the beginning of the range.

Returns
An iterator pointing to the beginning of the range.
Examples
06_multi_index.cpp.

◆ begin() [2/2]

template<size_t D>
Iterator pfc::MultiIndex< D >::begin ( ) const
inline

Returns a const iterator pointing to the beginning of the range.

Returns
A const iterator pointing to the beginning of the range.

◆ end() [1/2]

template<size_t D>
Iterator pfc::MultiIndex< D >::end ( )
inline

Returns an iterator pointing to the end of the range.

Returns
An iterator pointing to the end of the range.
Examples
06_multi_index.cpp.

◆ end() [2/2]

template<size_t D>
Iterator pfc::MultiIndex< D >::end ( ) const
inline

Returns a const iterator pointing to the end of the range.

Returns
A const iterator pointing to the end of the range.

◆ from() [1/2]

template<size_t D>
Iterator pfc::MultiIndex< D >::from ( size_t  from)
inline

Returns an iterator starting from the specified linear index.

This function creates an iterator starting from the specified linear index. The linear index is converted to the corresponding multi-dimensional indices, and the iterator is constructed using these indices and the current MultiIndex object.

Parameters
fromThe linear index to start from.
Returns
An iterator starting from the specified linear index.
Here is the call graph for this function:

◆ from() [2/2]

template<size_t D>
Iterator pfc::MultiIndex< D >::from ( std::array< int, D >  from)
inline

Returns an iterator starting from the specified multi-dimensional indices.

Parameters
fromThe multi-dimensional indices to start from.
Returns
An iterator starting from the specified multi-dimensional indices.
Examples
06_multi_index.cpp.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ inbounds()

template<size_t D>
bool pfc::MultiIndex< D >::inbounds ( const std::array< int, D > &  indices) const
inline

Checks whether given indices are in bounds or not.

Parameters
indicesArray of indices.
Returns
true if in bounds, false otherwise

◆ to_linear()

template<size_t D>
size_t pfc::MultiIndex< D >::to_linear ( const std::array< int, D > &  indices) const
inline

Converts a multi-dimensional index to its corresponding linear index.

Parameters
indicesThe multi-dimensional indices.
Returns
The linear index corresponding to the given indices.
Here is the caller graph for this function:

◆ to_multi()

template<size_t D>
std::array< int, D > pfc::MultiIndex< D >::to_multi ( size_t  idx) const
inline

Converts a linear index to its corresponding multi-dimensional indices.

Parameters
idxThe linear index.
Returns
The multi-dimensional indices corresponding to the given linear index.
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator<<

template<size_t D>
std::ostream & operator<< ( std::ostream &  os,
const MultiIndex< D > &  index 
)
friend

Outputs the index to the specified output stream.

Parameters
osThe output stream.
indexThe index to output.
Returns
Reference to the output stream.

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