Chemical Data Processing Library C++ API - Version 1.4.0
Public Types | Public Member Functions | Friends | List of all members
CDPL::Math::Grid< T, A > Class Template Reference

Dynamically-sized dense 3D grid ( \( d_1 \times d_2 \times d_3 \)) with configurable underlying storage. More...

#include <Grid.hpp>

+ Inheritance diagram for CDPL::Math::Grid< T, A >:

Public Types

typedef T ValueType
 The scalar value type stored in the grid. More...
 
typedef T & Reference
 Mutable reference type to an element. More...
 
typedef const T & ConstReference
 Constant reference type to an element. More...
 
typedef A::size_type SizeType
 The unsigned size type used by the underlying storage container. More...
 
typedef A::difference_type DifferenceType
 The signed difference type used by the underlying storage container. More...
 
typedef A ArrayType
 The underlying storage container type. More...
 
typedef T * Pointer
 Pointer type for raw element access. More...
 
typedef const T * ConstPointer
 Constant pointer type for raw element access. More...
 
typedef GridReference< SelfTypeClosureType
 Closure type used when this grid appears inside another expression. More...
 
typedef const GridReference< const SelfTypeConstClosureType
 Constant closure type used when this grid appears inside another expression. More...
 
typedef SelfType GridTemporaryType
 Concrete temporary grid type used by expression-template machinery. More...
 
typedef std::shared_ptr< SelfTypeSharedPointer
 A reference-counted smart pointer [SHPTR] for dynamically allocated Grid instances. More...
 
- Public Types inherited from CDPL::Math::GridContainer< Grid< T, std::vector< T > > >
typedef Grid< T, std::vector< T > > ContainerType
 The derived grid container type. More...
 
- Public Types inherited from CDPL::Math::GridExpression< E >
typedef E ExpressionType
 The derived grid expression type. More...
 
- Public Types inherited from CDPL::Math::Expression< E >
typedef E ExpressionType
 The derived expression type (made available to expression-template machinery). More...
 

Public Member Functions

 Grid ()
 Constructs an empty grid (zero size on every axis). More...
 
 Grid (SizeType m, SizeType n, SizeType o)
 Constructs an m × n × o grid with default-initialized elements. More...
 
 Grid (SizeType m, SizeType n, SizeType o, const ValueType &v)
 Constructs an m × n × o grid with every element initialized to v. More...
 
 Grid (const Grid &g)
 Constructs a copy of the grid g. More...
 
 Grid (Grid &&g)
 Move-constructs a grid from g (g is left in a valid empty state). More...
 
template<typename E >
 Grid (const GridExpression< E > &e)
 Constructs the grid from the grid expression e (materializing the expression result). More...
 
Reference operator() (SizeType i)
 Returns a mutable reference to the element at linear index i. More...
 
ConstReference operator() (SizeType i) const
 Returns a const reference to the element at linear index i. More...
 
Reference operator() (SizeType i, SizeType j, SizeType k)
 Returns a mutable reference to the element at (i, j, k). More...
 
ConstReference operator() (SizeType i, SizeType j, SizeType k) const
 Returns a const reference to the element at (i, j, k). More...
 
bool isEmpty () const
 Tells whether the grid is empty. More...
 
SizeType getSize () const
 Returns the total cell count \( \mathrm{size}_1 \cdot \mathrm{size}_2 \cdot \mathrm{size}_3 \). More...
 
SizeType getSize1 () const
 Returns the first-axis size. More...
 
SizeType getSize2 () const
 Returns the second-axis size. More...
 
SizeType getSize3 () const
 Returns the third-axis size. More...
 
SizeType getMaxSize () const
 Returns the maximum total cell count the underlying storage container can hold. More...
 
ArrayTypegetData ()
 Returns a mutable reference to the underlying storage container. More...
 
const ArrayTypegetData () const
 Returns a const reference to the underlying storage container. More...
 
Gridoperator= (const Grid &g)
 Copy-assigns the contents of g to this grid. More...
 
Gridoperator= (Grid &&g)
 Move-assigns the contents of g to this grid. More...
 
template<typename C >
Gridoperator= (const GridContainer< C > &c)
 Assigns the contents of the grid container c to this grid (no alias check needed). More...
 
template<typename E >
Gridoperator= (const GridExpression< E > &e)
 Assigns the grid expression e to this grid (via a temporary to handle aliasing). More...
 
template<typename C >
Gridoperator+= (const GridContainer< C > &c)
 Adds the contents of the grid container c cell-wise to this grid (no alias check needed). More...
 
template<typename E >
Gridoperator+= (const GridExpression< E > &e)
 Adds the grid expression e cell-wise to this grid (via a temporary to handle aliasing). More...
 
template<typename C >
Gridoperator-= (const GridContainer< C > &c)
 Subtracts the contents of the grid container c cell-wise from this grid (no alias check needed). More...
 
template<typename E >
Gridoperator-= (const GridExpression< E > &e)
 Subtracts the grid expression e cell-wise from this grid (via a temporary to handle aliasing). More...
 
template<typename T1 >
std::enable_if< IsScalar< T1 >::value, Grid >::type & operator*= (const T1 &t)
 Multiplies every cell by the scalar t. More...
 
template<typename T1 >
std::enable_if< IsScalar< T1 >::value, Grid >::type & operator/= (const T1 &t)
 Divides every cell by the scalar t. More...
 
template<typename E >
Gridassign (const GridExpression< E > &e)
 Resizes this grid to match e and assigns its cells without intermediate temporary. More...
 
template<typename E >
GridplusAssign (const GridExpression< E > &e)
 Adds the cells of the grid expression e to this grid without intermediate temporary. More...
 
template<typename E >
GridminusAssign (const GridExpression< E > &e)
 Subtracts the cells of the grid expression e from this grid without intermediate temporary. More...
 
void swap (Grid &g)
 Swaps the contents of this grid with those of g. More...
 
void clear (const ValueType &v=ValueType())
 Sets every cell of the grid to the value v. More...
 
void resize (SizeType m, SizeType n, SizeType o, bool preserve=true, const ValueType &v=ValueType())
 Resizes the grid to \( m \times n \times o \) cells. More...
 
- Public Member Functions inherited from CDPL::Math::GridContainer< Grid< T, std::vector< T > > >
const ContainerTypeoperator() () const
 Returns a const reference to the derived grid container. More...
 
ContainerTypeoperator() ()
 Returns a reference to the derived grid container. More...
 
- Public Member Functions inherited from CDPL::Math::GridExpression< E >
const ExpressionTypeoperator() () const
 Returns a const reference to the derived grid expression. More...
 
ExpressionTypeoperator() ()
 Returns a reference to the derived grid expression. More...
 

Friends

void swap (Grid &g1, Grid &g2)
 ADL-enabled free-function form of swap(). More...
 

Additional Inherited Members

- Protected Member Functions inherited from CDPL::Math::GridContainer< Grid< T, std::vector< T > > >
 GridContainer ()
 
 ~GridContainer ()
 
- Protected Member Functions inherited from CDPL::Math::GridExpression< E >
 GridExpression ()
 
 ~GridExpression ()
 
- Protected Member Functions inherited from CDPL::Math::Expression< E >
 Expression ()
 
 ~Expression ()
 

Detailed Description

template<typename T, typename A = std::vector<T>>
class CDPL::Math::Grid< T, A >

Dynamically-sized dense 3D grid ( \( d_1 \times d_2 \times d_3 \)) with configurable underlying storage.

Template Parameters
TThe scalar value type.
AThe underlying storage container type (default: std::vector).

Member Typedef Documentation

◆ ValueType

template<typename T , typename A = std::vector<T>>
typedef T CDPL::Math::Grid< T, A >::ValueType

The scalar value type stored in the grid.

◆ Reference

template<typename T , typename A = std::vector<T>>
typedef T& CDPL::Math::Grid< T, A >::Reference

Mutable reference type to an element.

◆ ConstReference

template<typename T , typename A = std::vector<T>>
typedef const T& CDPL::Math::Grid< T, A >::ConstReference

Constant reference type to an element.

◆ SizeType

template<typename T , typename A = std::vector<T>>
typedef A::size_type CDPL::Math::Grid< T, A >::SizeType

The unsigned size type used by the underlying storage container.

◆ DifferenceType

template<typename T , typename A = std::vector<T>>
typedef A::difference_type CDPL::Math::Grid< T, A >::DifferenceType

The signed difference type used by the underlying storage container.

◆ ArrayType

template<typename T , typename A = std::vector<T>>
typedef A CDPL::Math::Grid< T, A >::ArrayType

The underlying storage container type.

◆ Pointer

template<typename T , typename A = std::vector<T>>
typedef T* CDPL::Math::Grid< T, A >::Pointer

Pointer type for raw element access.

◆ ConstPointer

template<typename T , typename A = std::vector<T>>
typedef const T* CDPL::Math::Grid< T, A >::ConstPointer

Constant pointer type for raw element access.

◆ ClosureType

template<typename T , typename A = std::vector<T>>
typedef GridReference<SelfType> CDPL::Math::Grid< T, A >::ClosureType

Closure type used when this grid appears inside another expression.

◆ ConstClosureType

template<typename T , typename A = std::vector<T>>
typedef const GridReference<const SelfType> CDPL::Math::Grid< T, A >::ConstClosureType

Constant closure type used when this grid appears inside another expression.

◆ GridTemporaryType

template<typename T , typename A = std::vector<T>>
typedef SelfType CDPL::Math::Grid< T, A >::GridTemporaryType

Concrete temporary grid type used by expression-template machinery.

◆ SharedPointer

template<typename T , typename A = std::vector<T>>
typedef std::shared_ptr<SelfType> CDPL::Math::Grid< T, A >::SharedPointer

A reference-counted smart pointer [SHPTR] for dynamically allocated Grid instances.

Constructor & Destructor Documentation

◆ Grid() [1/6]

template<typename T , typename A = std::vector<T>>
CDPL::Math::Grid< T, A >::Grid ( )
inline

Constructs an empty grid (zero size on every axis).

◆ Grid() [2/6]

template<typename T , typename A = std::vector<T>>
CDPL::Math::Grid< T, A >::Grid ( SizeType  m,
SizeType  n,
SizeType  o 
)
inline

Constructs an m × n × o grid with default-initialized elements.

Parameters
mThe size along the first axis.
nThe size along the second axis.
oThe size along the third axis.

◆ Grid() [3/6]

template<typename T , typename A = std::vector<T>>
CDPL::Math::Grid< T, A >::Grid ( SizeType  m,
SizeType  n,
SizeType  o,
const ValueType v 
)
inline

Constructs an m × n × o grid with every element initialized to v.

Parameters
mThe size along the first axis.
nThe size along the second axis.
oThe size along the third axis.
vThe element value used to initialize every cell.

◆ Grid() [4/6]

template<typename T , typename A = std::vector<T>>
CDPL::Math::Grid< T, A >::Grid ( const Grid< T, A > &  g)
inline

Constructs a copy of the grid g.

Parameters
gThe grid to copy.

◆ Grid() [5/6]

template<typename T , typename A = std::vector<T>>
CDPL::Math::Grid< T, A >::Grid ( Grid< T, A > &&  g)
inline

Move-constructs a grid from g (g is left in a valid empty state).

Parameters
gThe grid to move from.

◆ Grid() [6/6]

template<typename T , typename A = std::vector<T>>
template<typename E >
CDPL::Math::Grid< T, A >::Grid ( const GridExpression< E > &  e)
inline

Constructs the grid from the grid expression e (materializing the expression result).

Template Parameters
EThe grid expression type.
Parameters
eThe grid expression to materialize.

Member Function Documentation

◆ operator()() [1/4]

template<typename T , typename A = std::vector<T>>
Reference CDPL::Math::Grid< T, A >::operator() ( SizeType  i)
inline

Returns a mutable reference to the element at linear index i.

Parameters
iThe zero-based linear index.
Returns
A mutable reference to the cell.
Exceptions
Base::IndexErrorif i is out of range.

◆ operator()() [2/4]

template<typename T , typename A = std::vector<T>>
ConstReference CDPL::Math::Grid< T, A >::operator() ( SizeType  i) const
inline

Returns a const reference to the element at linear index i.

Parameters
iThe zero-based linear index.
Returns
A const reference to the cell.
Exceptions
Base::IndexErrorif i is out of range.

◆ operator()() [3/4]

template<typename T , typename A = std::vector<T>>
Reference CDPL::Math::Grid< T, A >::operator() ( SizeType  i,
SizeType  j,
SizeType  k 
)
inline

Returns a mutable reference to the element at (i, j, k).

Parameters
iThe zero-based first-axis index.
jThe zero-based second-axis index.
kThe zero-based third-axis index.
Returns
A mutable reference to the cell.
Exceptions
Base::IndexErrorif any of the indices is out of range.

◆ operator()() [4/4]

template<typename T , typename A = std::vector<T>>
ConstReference CDPL::Math::Grid< T, A >::operator() ( SizeType  i,
SizeType  j,
SizeType  k 
) const
inline

Returns a const reference to the element at (i, j, k).

Parameters
iThe zero-based first-axis index.
jThe zero-based second-axis index.
kThe zero-based third-axis index.
Returns
A const reference to the cell.
Exceptions
Base::IndexErrorif any of the indices is out of range.

◆ isEmpty()

template<typename T , typename A = std::vector<T>>
bool CDPL::Math::Grid< T, A >::isEmpty ( ) const
inline

Tells whether the grid is empty.

Returns
true if the underlying storage holds no elements, and false otherwise.

◆ getSize()

template<typename T , typename A = std::vector<T>>
SizeType CDPL::Math::Grid< T, A >::getSize ( ) const
inline

Returns the total cell count \( \mathrm{size}_1 \cdot \mathrm{size}_2 \cdot \mathrm{size}_3 \).

Returns
The total number of cells.

◆ getSize1()

template<typename T , typename A = std::vector<T>>
SizeType CDPL::Math::Grid< T, A >::getSize1 ( ) const
inline

Returns the first-axis size.

Returns
The size along the first axis.

◆ getSize2()

template<typename T , typename A = std::vector<T>>
SizeType CDPL::Math::Grid< T, A >::getSize2 ( ) const
inline

Returns the second-axis size.

Returns
The size along the second axis.

◆ getSize3()

template<typename T , typename A = std::vector<T>>
SizeType CDPL::Math::Grid< T, A >::getSize3 ( ) const
inline

Returns the third-axis size.

Returns
The size along the third axis.

◆ getMaxSize()

template<typename T , typename A = std::vector<T>>
SizeType CDPL::Math::Grid< T, A >::getMaxSize ( ) const
inline

Returns the maximum total cell count the underlying storage container can hold.

Returns
The maximum cell count.

◆ getData() [1/2]

template<typename T , typename A = std::vector<T>>
ArrayType& CDPL::Math::Grid< T, A >::getData ( )
inline

Returns a mutable reference to the underlying storage container.

Returns
A mutable reference to the storage container.

◆ getData() [2/2]

template<typename T , typename A = std::vector<T>>
const ArrayType& CDPL::Math::Grid< T, A >::getData ( ) const
inline

Returns a const reference to the underlying storage container.

Returns
A const reference to the storage container.

◆ operator=() [1/4]

template<typename T , typename A = std::vector<T>>
Grid& CDPL::Math::Grid< T, A >::operator= ( const Grid< T, A > &  g)
inline

Copy-assigns the contents of g to this grid.

Parameters
gThe source grid.
Returns
A reference to itself.

◆ operator=() [2/4]

template<typename T , typename A = std::vector<T>>
Grid& CDPL::Math::Grid< T, A >::operator= ( Grid< T, A > &&  g)
inline

Move-assigns the contents of g to this grid.

Parameters
gThe source grid (left in a valid but unspecified state).
Returns
A reference to itself.

◆ operator=() [3/4]

template<typename T , typename A = std::vector<T>>
template<typename C >
Grid& CDPL::Math::Grid< T, A >::operator= ( const GridContainer< C > &  c)
inline

Assigns the contents of the grid container c to this grid (no alias check needed).

Template Parameters
CThe source grid container type.
Parameters
cThe source grid container.
Returns
A reference to itself.

◆ operator=() [4/4]

template<typename T , typename A = std::vector<T>>
template<typename E >
Grid& CDPL::Math::Grid< T, A >::operator= ( const GridExpression< E > &  e)
inline

Assigns the grid expression e to this grid (via a temporary to handle aliasing).

Template Parameters
EThe source grid expression type.
Parameters
eThe source grid expression.
Returns
A reference to itself.

◆ operator+=() [1/2]

template<typename T , typename A = std::vector<T>>
template<typename C >
Grid& CDPL::Math::Grid< T, A >::operator+= ( const GridContainer< C > &  c)
inline

Adds the contents of the grid container c cell-wise to this grid (no alias check needed).

Template Parameters
CThe source grid container type.
Parameters
cThe source grid container.
Returns
A reference to itself.

◆ operator+=() [2/2]

template<typename T , typename A = std::vector<T>>
template<typename E >
Grid& CDPL::Math::Grid< T, A >::operator+= ( const GridExpression< E > &  e)
inline

Adds the grid expression e cell-wise to this grid (via a temporary to handle aliasing).

Template Parameters
EThe source grid expression type.
Parameters
eThe source grid expression.
Returns
A reference to itself.

◆ operator-=() [1/2]

template<typename T , typename A = std::vector<T>>
template<typename C >
Grid& CDPL::Math::Grid< T, A >::operator-= ( const GridContainer< C > &  c)
inline

Subtracts the contents of the grid container c cell-wise from this grid (no alias check needed).

Template Parameters
CThe source grid container type.
Parameters
cThe source grid container.
Returns
A reference to itself.

◆ operator-=() [2/2]

template<typename T , typename A = std::vector<T>>
template<typename E >
Grid& CDPL::Math::Grid< T, A >::operator-= ( const GridExpression< E > &  e)
inline

Subtracts the grid expression e cell-wise from this grid (via a temporary to handle aliasing).

Template Parameters
EThe source grid expression type.
Parameters
eThe source grid expression.
Returns
A reference to itself.

◆ operator*=()

template<typename T , typename A = std::vector<T>>
template<typename T1 >
std::enable_if<IsScalar<T1>::value, Grid>::type& CDPL::Math::Grid< T, A >::operator*= ( const T1 &  t)
inline

Multiplies every cell by the scalar t.

Template Parameters
T1The scalar type.
Parameters
tThe scalar multiplier.
Returns
A reference to itself.

◆ operator/=()

template<typename T , typename A = std::vector<T>>
template<typename T1 >
std::enable_if<IsScalar<T1>::value, Grid>::type& CDPL::Math::Grid< T, A >::operator/= ( const T1 &  t)
inline

Divides every cell by the scalar t.

Template Parameters
T1The scalar type.
Parameters
tThe scalar divisor.
Returns
A reference to itself.

◆ assign()

template<typename T , typename A = std::vector<T>>
template<typename E >
Grid& CDPL::Math::Grid< T, A >::assign ( const GridExpression< E > &  e)
inline

Resizes this grid to match e and assigns its cells without intermediate temporary.

Template Parameters
EThe source grid expression type.
Parameters
eThe source grid expression.
Returns
A reference to itself.

◆ plusAssign()

template<typename T , typename A = std::vector<T>>
template<typename E >
Grid& CDPL::Math::Grid< T, A >::plusAssign ( const GridExpression< E > &  e)
inline

Adds the cells of the grid expression e to this grid without intermediate temporary.

Template Parameters
EThe source grid expression type.
Parameters
eThe source grid expression.
Returns
A reference to itself.

◆ minusAssign()

template<typename T , typename A = std::vector<T>>
template<typename E >
Grid& CDPL::Math::Grid< T, A >::minusAssign ( const GridExpression< E > &  e)
inline

Subtracts the cells of the grid expression e from this grid without intermediate temporary.

Template Parameters
EThe source grid expression type.
Parameters
eThe source grid expression.
Returns
A reference to itself.

◆ swap()

template<typename T , typename A = std::vector<T>>
void CDPL::Math::Grid< T, A >::swap ( Grid< T, A > &  g)
inline

Swaps the contents of this grid with those of g.

Parameters
gThe grid to swap with.

◆ clear()

template<typename T , typename A = std::vector<T>>
void CDPL::Math::Grid< T, A >::clear ( const ValueType v = ValueType())
inline

Sets every cell of the grid to the value v.

Parameters
vThe fill value.

◆ resize()

template<typename T , typename A = std::vector<T>>
void CDPL::Math::Grid< T, A >::resize ( SizeType  m,
SizeType  n,
SizeType  o,
bool  preserve = true,
const ValueType v = ValueType() 
)
inline

Resizes the grid to \( m \times n \times o \) cells.

Parameters
mThe new first-axis size.
nThe new second-axis size.
oThe new third-axis size.
preserveIf true, existing cell values at indices that remain valid are kept; if false, all cells are set to v.
vThe fill value for newly added cells (or for all cells when preserve is false).

Friends And Related Function Documentation

◆ swap

template<typename T , typename A = std::vector<T>>
void swap ( Grid< T, A > &  g1,
Grid< T, A > &  g2 
)
friend

ADL-enabled free-function form of swap().

Parameters
g1The first grid.
g2The second grid.

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