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

Index slice ( \( start, stride, size \)) used for strided slicing of vector and matrix expressions. More...

#include <Slice.hpp>

+ Inheritance diagram for CDPL::Math::Slice< S, D >:

Public Types

typedef S SizeType
 The integral size/index type. More...
 
typedef D DifferenceType
 The signed difference type used for the stride. More...
 

Public Member Functions

 Slice ()
 Constructs an empty slice ( \( 0, 0, 0 \)). More...
 
 Slice (SizeType start, DifferenceType stride, SizeType size)
 Constructs the slice (start, stride, size). More...
 
SizeType operator() (SizeType i) const
 Maps the local position i to the global index \( start + i \cdot stride \). More...
 
SizeType getStart () const
 Returns the starting global index. More...
 
DifferenceType getStride () const
 Returns the signed step size between consecutive entries. More...
 
SizeType getSize () const
 Returns the number of entries in the slice. More...
 
bool isEmpty () const
 Tells whether the slice is empty. More...
 
bool operator== (const Slice &s) const
 Equality comparison. More...
 
bool operator!= (const Slice &s) const
 Inequality comparison. More...
 
void swap (Slice &s)
 Swaps the contents of *this and s. More...
 

Friends

void swap (Slice &s1, Slice &s2)
 Free-function swap overload. More...
 

Detailed Description

template<typename S, typename D>
class CDPL::Math::Slice< S, D >

Index slice ( \( start, stride, size \)) used for strided slicing of vector and matrix expressions.

Local position i is mapped to the global index \( start + i \cdot stride \). Negative strides (reverse iteration) are supported as long as the resulting indices stay non-negative.

Template Parameters
SThe integral size/index type.
DThe signed difference type used for the stride.

Member Typedef Documentation

◆ SizeType

template<typename S , typename D >
typedef S CDPL::Math::Slice< S, D >::SizeType

The integral size/index type.

◆ DifferenceType

template<typename S , typename D >
typedef D CDPL::Math::Slice< S, D >::DifferenceType

The signed difference type used for the stride.

Constructor & Destructor Documentation

◆ Slice() [1/2]

template<typename S , typename D >
CDPL::Math::Slice< S, D >::Slice ( )
inline

Constructs an empty slice ( \( 0, 0, 0 \)).

◆ Slice() [2/2]

template<typename S , typename D >
CDPL::Math::Slice< S, D >::Slice ( SizeType  start,
DifferenceType  stride,
SizeType  size 
)
inline

Constructs the slice (start, stride, size).

Parameters
startThe starting global index.
strideThe signed step size between consecutive entries.
sizeThe number of entries.
Exceptions
Base::RangeErrorif the slice would produce a negative global index.

Member Function Documentation

◆ operator()()

template<typename S , typename D >
SizeType CDPL::Math::Slice< S, D >::operator() ( SizeType  i) const
inline

Maps the local position i to the global index \( start + i \cdot stride \).

Parameters
iThe zero-based local position.
Returns
The global index.
Exceptions
Base::IndexErrorif i is not in the range \( [0, size) \).

◆ getStart()

template<typename S , typename D >
SizeType CDPL::Math::Slice< S, D >::getStart ( ) const
inline

Returns the starting global index.

Returns
The starting index.

◆ getStride()

template<typename S , typename D >
DifferenceType CDPL::Math::Slice< S, D >::getStride ( ) const
inline

Returns the signed step size between consecutive entries.

Returns
The stride.

◆ getSize()

template<typename S , typename D >
SizeType CDPL::Math::Slice< S, D >::getSize ( ) const
inline

Returns the number of entries in the slice.

Returns
The slice size.

◆ isEmpty()

template<typename S , typename D >
bool CDPL::Math::Slice< S, D >::isEmpty ( ) const
inline

Tells whether the slice is empty.

Returns
true if the slice contains no entries, and false otherwise.

◆ operator==()

template<typename S , typename D >
bool CDPL::Math::Slice< S, D >::operator== ( const Slice< S, D > &  s) const
inline

Equality comparison.

Parameters
sThe other slice.
Returns
true if both slices have the same start, stride and size, and false otherwise.

◆ operator!=()

template<typename S , typename D >
bool CDPL::Math::Slice< S, D >::operator!= ( const Slice< S, D > &  s) const
inline

Inequality comparison.

Parameters
sThe other slice.
Returns
true if the slices differ in start, stride or size, and false otherwise.

◆ swap()

template<typename S , typename D >
void CDPL::Math::Slice< S, D >::swap ( Slice< S, D > &  s)
inline

Swaps the contents of *this and s.

Parameters
sThe other slice.

Friends And Related Function Documentation

◆ swap

template<typename S , typename D >
void swap ( Slice< S, D > &  s1,
Slice< S, D > &  s2 
)
friend

Free-function swap overload.

Parameters
s1The first slice.
s2The second slice.

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