VTK-m  2.1
Public Types | Static Public Member Functions | Static Public Attributes | List of all members
vtkm::VecTraits< T > Struct Template Reference

Traits that can be queried to treat any type as a Vec. More...

#include <VecTraits.h>

Inheritance diagram for vtkm::VecTraits< T >:
vtkm::VecTraits< const T & > vtkm::VecTraits< const T > vtkm::VecTraits< T & > vtkm::VecTraits< T * > vtkm::VecTraits< const T * >

Public Types

using ComponentType = T
 Type of the components in the vector. More...
 
using BaseComponentType = T
 Base component type in the vector. More...
 
using HasMultipleComponents = vtkm::VecTraitsTagSingleComponent
 A tag specifying whether this vector has multiple components (i.e. More...
 
using IsSizeStatic = vtkm::VecTraitsTagSizeStatic
 A tag specifying whether the size of this vector is known at compile time. More...
 
template<typename NewComponentType >
using ReplaceComponentType = NewComponentType
 Get a vector of the same type but with a different component. More...
 
template<typename NewComponentType >
using ReplaceBaseComponentType = NewComponentType
 Get a vector of the same type but with a different base component. More...
 

Static Public Member Functions

static constexpr vtkm::IdComponent GetNumberOfComponents (const T &)
 Returns the number of components in the given vector. More...
 
static const ComponentTypeGetComponent (const T &vector, vtkm::IdComponent)
 Returns the value in a given component of the vector. More...
 
static ComponentTypeGetComponent (T &vector, vtkm::IdComponent)
 Returns the value in a given component of the vector. More...
 
static void SetComponent (T &vector, vtkm::IdComponent, ComponentType value)
 Changes the value in a given component of the vector. More...
 
template<vtkm::IdComponent destSize>
static void CopyInto (const T &src, vtkm::Vec< ComponentType, destSize > &dest)
 Copies the components in the given vector into a given Vec object. More...
 

Static Public Attributes

static constexpr vtkm::IdComponent NUM_COMPONENTS = 1
 Number of components in the vector. More...
 

Detailed Description

template<class T>
struct vtkm::VecTraits< T >

Traits that can be queried to treat any type as a Vec.

The VecTraits class gives several static members that define how to use a given type as a vector. This is useful for templated functions and methods that have a parameter that could be either a standard scalar type or a Vec or some other Vec-like object. When using this class, scalar objects are treated like a Vec of size 1.

The default implementation of this template treats the type as a scalar. Types that actually behave like vectors should specialize this template to provide the proper information.

Member Typedef Documentation

◆ BaseComponentType

template<class T >
using vtkm::VecTraits< T >::BaseComponentType = T

Base component type in the vector.

Similar to ComponentType except that for nested vectors (e.g. Vec<Vec<T, M>, N>), it returns the base scalar type at the end of the composition (T in this example).

◆ ComponentType

template<class T >
using vtkm::VecTraits< T >::ComponentType = T

Type of the components in the vector.

If the type is really a scalar, then the component type is the same as the scalar type.

◆ HasMultipleComponents

A tag specifying whether this vector has multiple components (i.e.

is a "real" vector).

This type is set to either vtkm::VecTraitsTagSingleComponent if the vector length is size 1 or vtkm::VecTraitsTagMultipleComponents otherwise. This tag can be useful for creating specialized functions when a vector is really just a scalar. If the vector type is of variable size (that is, IsSizeStatic is vtkm::VecTraitsTagSizeVariable), then HasMultipleComponents might be vtkm::VecTraitsTagMultipleComponents even when at run time there is only one component.

◆ IsSizeStatic

template<class T >
using vtkm::VecTraits< T >::IsSizeStatic = vtkm::VecTraitsTagSizeStatic

A tag specifying whether the size of this vector is known at compile time.

If set to VecTraitsTagSizeStatic, then NUM_COMPONENTS is set. If set to VecTraitsTagSizeVariable, then the number of components is not known at compile time and must be queried with GetNumberOfComponents.

◆ ReplaceBaseComponentType

template<class T >
template<typename NewComponentType >
using vtkm::VecTraits< T >::ReplaceBaseComponentType = NewComponentType

Get a vector of the same type but with a different base component.

This type resolves to another vector with a different base component type. The replacement is recursive for nested types. For example, VecTraits<Vec<Vec<T, M>, N>::ReplaceBaseComponentType<T2> is Vec<Vec<T2, M>, N>.

◆ ReplaceComponentType

template<class T >
template<typename NewComponentType >
using vtkm::VecTraits< T >::ReplaceComponentType = NewComponentType

Get a vector of the same type but with a different component.

This type resolves to another vector with a different component type. For example, vtkm::VecTraits<vtkm::Vec<T, N>>::ReplaceComponentType<T2> is vtkm::Vec<T2, N>. This replacement is not recursive. So VecTraits<Vec<Vec<T, M>, N>::ReplaceComponentType<T2> is vtkm::Vec<T2, N>.

Member Function Documentation

◆ CopyInto()

template<class T >
template<vtkm::IdComponent destSize>
static void vtkm::VecTraits< T >::CopyInto ( const T &  src,
vtkm::Vec< ComponentType, destSize > &  dest 
)
inlinestatic

Copies the components in the given vector into a given Vec object.

◆ GetComponent() [1/2]

template<class T >
static const ComponentType& vtkm::VecTraits< T >::GetComponent ( const T &  vector,
vtkm::IdComponent   
)
inlinestatic

Returns the value in a given component of the vector.

◆ GetComponent() [2/2]

template<class T >
static ComponentType& vtkm::VecTraits< T >::GetComponent ( T &  vector,
vtkm::IdComponent   
)
inlinestatic

Returns the value in a given component of the vector.

◆ GetNumberOfComponents()

template<class T >
static constexpr vtkm::IdComponent vtkm::VecTraits< T >::GetNumberOfComponents ( const T &  )
inlinestaticconstexpr

Returns the number of components in the given vector.

The result of GetNumberOfComponents() is the same value of NUM_COMPONENTS for vector types that have a static size (that is, IsSizeStatic is vtkm::VecTraitsTagSizeStatic). But unlike NUM_COMPONENTS, GetNumberOfComponents() works for vectors of any type.

◆ SetComponent()

template<class T >
static void vtkm::VecTraits< T >::SetComponent ( T &  vector,
vtkm::IdComponent  ,
ComponentType  value 
)
inlinestatic

Changes the value in a given component of the vector.

Member Data Documentation

◆ NUM_COMPONENTS

template<class T >
constexpr vtkm::IdComponent vtkm::VecTraits< T >::NUM_COMPONENTS = 1
staticconstexpr

Number of components in the vector.

This is only defined for vectors of a static size. That is, NUM_COMPONENTS is not available when IsSizeStatic is set to vtkm::VecTraitsTagSizeVariable.


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