VTK-m  1.4
Public Member Functions | Private Member Functions | Private Attributes | List of all members
vtkm::cont::VariantArrayHandleBase< TypeList > Class Template Reference

Holds an array handle without having to specify template parameters. More...

#include <VariantArrayHandleContainer.h>

Public Member Functions

VTKM_CONT VariantArrayHandleBase ()=default
 
template<typename T , typename Storage >
VTKM_CONT VariantArrayHandleBase (const vtkm::cont::ArrayHandle< T, Storage > &array)
 
template<typename T >
VTKM_CONT VariantArrayHandleBase (const vtkm::cont::ArrayHandle< T, vtkm::cont::StorageTagVirtual > &array)
 
template<typename OtherTypeList >
VTKM_CONT VariantArrayHandleBase (const VariantArrayHandleBase< OtherTypeList > &src)
 
VTKM_CONT VariantArrayHandleBase (const VariantArrayHandleBase &)=default
 
VTKM_CONT VariantArrayHandleBase (VariantArrayHandleBase &&) noexcept=default
 
VTKM_CONT ~VariantArrayHandleBase ()
 
VTKM_CONT VariantArrayHandleBase< TypeList > & operator= (const VariantArrayHandleBase< TypeList > &)=default
 
VTKM_CONT VariantArrayHandleBase< TypeList > & operator= (VariantArrayHandleBase< TypeList > &&) noexcept=default
 
template<typename ArrayHandleType >
VTKM_CONT bool IsType () const
 Returns true if this array matches the array handle type passed in. More...
 
template<typename T >
VTKM_CONT bool IsValueType () const
 Returns true if this array matches the ValueType type passed in. More...
 
template<typename ArrayHandleType >
VTKM_CONT ArrayHandleType Cast () const
 Returns this array cast to the given ArrayHandle type. More...
 
template<typename T , typename StorageTagList = VTKM_DEFAULT_STORAGE_LIST_TAG>
VTKM_CONT vtkm::cont::ArrayHandleVirtual< T > AsVirtual () const
 Returns this array cast to a ArrayHandleVirtual of the given type. More...
 
template<typename ArrayHandleType >
VTKM_CONT void CopyTo (ArrayHandleType &array) const
 Given a references to an ArrayHandle object, casts this array to the ArrayHandle's type and sets the given ArrayHandle to this array. More...
 
template<typename NewTypeList >
VTKM_CONT VariantArrayHandleBase< NewTypeList > ResetTypes (NewTypeList=NewTypeList()) const
 Changes the types to try casting to when resolving this variant array, which is specified with a list tag like those in TypeListTag.h. More...
 
VTKM_CONT VariantArrayHandleBase< TypeList > NewInstance () const
 Create a new array of the same type as this array. More...
 
void ReleaseResourcesExecution ()
 Releases any resources being used in the execution environment (that are not being shared by the control environment). More...
 
void ReleaseResources ()
 Releases all resources in both the control and execution environments. More...
 
VTKM_CONT vtkm::IdComponent GetNumberOfComponents () const
 Get the number of components in each array value. More...
 
VTKM_CONT vtkm::Id GetNumberOfValues () const
 Get the number of values in the array. More...
 
VTKM_CONT void PrintSummary (std::ostream &out) const
 
template<typename StorageTagList , typename Functor, typename... Args>
VTKM_CONT void CastAndCallImpl (std::true_type, StorageTagList, Functor &&f, Args &&...args) const
 
template<typename... T>
VTKM_CONT void AsMultiplexer (vtkm::cont::ArrayHandleMultiplexer< T... > &result) const
 Returns this array cast to a ArrayHandleMultiplexer of the given type. More...
 
template<typename ArrayHandleMultiplexerType >
VTKM_CONT ArrayHandleMultiplexerType AsMultiplexer () const
 Returns this array cast to a ArrayHandleMultiplexer of the given type. More...
 
template<typename FunctorOrStorageList , typename... Args>
VTKM_CONT void CastAndCall (FunctorOrStorageList &&functorOrStorageList, Args &&...args) const
 Call a functor using the underlying array type. More...
 
template<typename Functor >
VTKM_CONT void CastAndCall (Functor &&f) const
 Call a functor using the underlying array type. More...
 

Private Member Functions

template<typename Functor , typename... Args>
VTKM_CONT void CastAndCallImpl (std::false_type, Functor &&f, Args &&...args) const
 
template<typename StorageTagList , typename Functor , typename... Args>
VTKM_CONT void CastAndCallImpl (std::true_type, StorageTagList, Functor &&f, Args &&...) const
 

Private Attributes

std::shared_ptr< vtkm::cont::internal::VariantArrayHandleContainerBase > ArrayContainer
 

Detailed Description

template<typename TypeList>
class vtkm::cont::VariantArrayHandleBase< TypeList >

Holds an array handle without having to specify template parameters.

VariantArrayHandle holds an ArrayHandle or ArrayHandleVirtual object using runtime polymorphism to manage different value types and storage rather than compile-time templates. This adds a programming convenience that helps avoid a proliferation of templates. It also provides the management necessary to interface VTK-m with data sources where types will not be known until runtime.

To interface between the runtime polymorphism and the templated algorithms in VTK-m, VariantArrayHandle contains a method named CastAndCall that will determine the correct type from some known list of types. It returns an ArrayHandleVirtual which type erases the storage type by using polymorphism. This mechanism is used internally by VTK-m's worklet invocation mechanism to determine the type when running algorithms.

By default, VariantArrayHandle will assume that the value type in the array matches one of the types specified by VTKM_DEFAULT_TYPE_LIST_TAG This list can be changed by using the ResetTypes. It is worthwhile to match these lists closely to the possible types that might be used. If a type is missing you will get a runtime error. If there are more types than necessary, then the template mechanism will create a lot of object code that is never used, and keep in mind that the number of combinations grows exponentially when using multiple VariantArrayHandle objects.

The actual implementation of VariantArrayHandle is in a templated class named VariantArrayHandleBase, which is templated on the list of component types.

Constructor & Destructor Documentation

template<typename TypeList>
VTKM_CONT vtkm::cont::VariantArrayHandleBase< TypeList >::VariantArrayHandleBase ( )
default
template<typename TypeList>
template<typename T , typename Storage >
VTKM_CONT vtkm::cont::VariantArrayHandleBase< TypeList >::VariantArrayHandleBase ( const vtkm::cont::ArrayHandle< T, Storage > &  array)
inline
template<typename TypeList>
template<typename T >
VTKM_CONT vtkm::cont::VariantArrayHandleBase< TypeList >::VariantArrayHandleBase ( const vtkm::cont::ArrayHandle< T, vtkm::cont::StorageTagVirtual > &  array)
inlineexplicit
template<typename TypeList>
template<typename OtherTypeList >
VTKM_CONT vtkm::cont::VariantArrayHandleBase< TypeList >::VariantArrayHandleBase ( const VariantArrayHandleBase< OtherTypeList > &  src)
inlineexplicit
template<typename TypeList>
VTKM_CONT vtkm::cont::VariantArrayHandleBase< TypeList >::VariantArrayHandleBase ( const VariantArrayHandleBase< TypeList > &  )
default
template<typename TypeList>
VTKM_CONT vtkm::cont::VariantArrayHandleBase< TypeList >::VariantArrayHandleBase ( VariantArrayHandleBase< TypeList > &&  )
defaultnoexcept
template<typename TypeList>
VTKM_CONT vtkm::cont::VariantArrayHandleBase< TypeList >::~VariantArrayHandleBase ( )
inline

Member Function Documentation

template<typename TypeList >
template<typename... T>
VTKM_CONT void vtkm::cont::VariantArrayHandleBase< TypeList >::AsMultiplexer ( vtkm::cont::ArrayHandleMultiplexer< T... > &  result) const
inline

Returns this array cast to a ArrayHandleMultiplexer of the given type.

This will attempt to cast the internal array to each supported type of the multiplexer. If none are supported, an invalid ArrayHandleMultiplexer is returned.

As a special case, if one of the arrays in the ArrayHandleMultiplexer's type list is an ArrayHandleCast, then the multiplexer will look for type type of array being cast rather than an actual cast array.

template<typename TypeList>
template<typename ArrayHandleMultiplexerType >
VTKM_CONT ArrayHandleMultiplexerType vtkm::cont::VariantArrayHandleBase< TypeList >::AsMultiplexer ( ) const
inline

Returns this array cast to a ArrayHandleMultiplexer of the given type.

This will attempt to cast the internal array to each supported type of the multiplexer. If none are supported, an invalid ArrayHandleMultiplexer is returned.

As a special case, if one of the arrays in the ArrayHandleMultiplexer's type list is an ArrayHandleCast, then the multiplexer will look for type type of array being cast rather than an actual cast array.

template<typename TypeList>
template<typename T , typename StorageTagList = VTKM_DEFAULT_STORAGE_LIST_TAG>
VTKM_CONT vtkm::cont::ArrayHandleVirtual<T> vtkm::cont::VariantArrayHandleBase< TypeList >::AsVirtual ( ) const
inline

Returns this array cast to a ArrayHandleVirtual of the given type.

This will perform type conversions as necessary, and will log warnings if the conversion is lossy.

This method internally uses CastAndCall. A custom storage tag list may be specified in the second template parameter, which will be passed to the CastAndCall.

template<typename TypeList>
template<typename ArrayHandleType >
VTKM_CONT ArrayHandleType vtkm::cont::VariantArrayHandleBase< TypeList >::Cast ( ) const
inline

Returns this array cast to the given ArrayHandle type.

Throws ErrorBadType if the cast does not work. Use IsType to check if the cast can happen.

template<typename TypeList>
template<typename FunctorOrStorageList , typename... Args>
VTKM_CONT void vtkm::cont::VariantArrayHandleBase< TypeList >::CastAndCall ( FunctorOrStorageList &&  functorOrStorageList,
Args &&...  args 
) const
inline

Call a functor using the underlying array type.

CastAndCall Attempts to cast the held array to a specific value type, then call the given functor with the cast array. The types tried in the cast are those in the lists defined by the TypeList. By default VariantArrayHandle set this to VTKM_DEFAULT_TYPE_LIST_TAG.

In addition to the value type, an ArrayHandle also requires a storage tag. By default, CastAndCall attempts to cast the array using the storage tags listed in VTKM_DEFAULT_STORAGE_LIST_TAG. You can optionally give a custom list of storage tags as the second argument. If the storage of the underlying array does not match any of the storage tags given, then the array will be cast to an ArrayHandleVirtual, which can hold any array given the appropriate value type. To always use ArrayHandleVirtual, pass vtkm::ListTagEmpty as thefirst argument.

As previous stated, if a storage tag list is provided, it is given in the first argument. The functor to call with the cast array is given as the next argument (or the first argument if a storage tag list is not provided). The remaning arguments, if any, are passed to the functor.

The functor will be called with the cast array as its first argument. Any remaining arguments are passed from the arguments to CastAndCall.

template<typename TypeList>
template<typename Functor >
VTKM_CONT void vtkm::cont::VariantArrayHandleBase< TypeList >::CastAndCall ( Functor &&  f) const
inline

Call a functor using the underlying array type.

CastAndCall Attempts to cast the held array to a specific value type, then call the given functor with the cast array. The types tried in the cast are those in the lists defined by the TypeList. By default VariantArrayHandle set this to VTKM_DEFAULT_TYPE_LIST_TAG.

In addition to the value type, an ArrayHandle also requires a storage tag. By default, CastAndCall attempts to cast the array using the storage tags listed in VTKM_DEFAULT_STORAGE_LIST_TAG. You can optionally give a custom list of storage tags as the second argument. If the storage of the underlying array does not match any of the storage tags given, then the array will be cast to an ArrayHandleVirtual, which can hold any array given the appropriate value type. To always use ArrayHandleVirtual, pass vtkm::ListTagEmpty as thefirst argument.

As previous stated, if a storage tag list is provided, it is given in the first argument. The functor to call with the cast array is given as the next argument (or the first argument if a storage tag list is not provided). The remaning arguments, if any, are passed to the functor.

The functor will be called with the cast array as its first argument. Any remaining arguments are passed from the arguments to CastAndCall.

template<typename TypeList>
template<typename Functor , typename... Args>
VTKM_CONT void vtkm::cont::VariantArrayHandleBase< TypeList >::CastAndCallImpl ( std::false_type  ,
Functor &&  f,
Args &&...  args 
) const
inlineprivate
template<typename TypeList>
template<typename StorageTagList , typename Functor , typename... Args>
VTKM_CONT void vtkm::cont::VariantArrayHandleBase< TypeList >::CastAndCallImpl ( std::true_type  ,
StorageTagList  ,
Functor &&  f,
Args &&  ... 
) const
private
template<typename TypeList>
template<typename StorageTagList , typename Functor, typename... Args>
VTKM_CONT void vtkm::cont::VariantArrayHandleBase< TypeList >::CastAndCallImpl ( std::true_type  ,
StorageTagList  ,
Functor &&  f,
Args &&...  args 
) const
template<typename TypeList>
template<typename ArrayHandleType >
VTKM_CONT void vtkm::cont::VariantArrayHandleBase< TypeList >::CopyTo ( ArrayHandleType &  array) const
inline

Given a references to an ArrayHandle object, casts this array to the ArrayHandle's type and sets the given ArrayHandle to this array.

Throws ErrorBadType if the cast does not work. Use ArrayHandleType to check if the cast can happen.

Note that this is a shallow copy. The data are not copied and a change in the data in one array will be reflected in the other.

template<typename TypeList>
VTKM_CONT vtkm::IdComponent vtkm::cont::VariantArrayHandleBase< TypeList >::GetNumberOfComponents ( ) const
inline

Get the number of components in each array value.

This method will query the array type for the number of components in each value of the array. The number of components is determined by the VecTraits::NUM_COMPONENTS trait class.

template<typename TypeList>
VTKM_CONT vtkm::Id vtkm::cont::VariantArrayHandleBase< TypeList >::GetNumberOfValues ( ) const
inline

Get the number of values in the array.

template<typename TypeList>
template<typename ArrayHandleType >
VTKM_CONT bool vtkm::cont::VariantArrayHandleBase< TypeList >::IsType ( ) const
inline

Returns true if this array matches the array handle type passed in.

template<typename TypeList>
template<typename T >
VTKM_CONT bool vtkm::cont::VariantArrayHandleBase< TypeList >::IsValueType ( ) const
inline

Returns true if this array matches the ValueType type passed in.

template<typename TypeList>
VTKM_CONT VariantArrayHandleBase<TypeList> vtkm::cont::VariantArrayHandleBase< TypeList >::NewInstance ( ) const
inline

Create a new array of the same type as this array.

This method creates a new array that is the same type as this one and returns a new variant array handle for it. This method is convenient when creating output arrays that should be the same type as some input array.

template<typename TypeList>
VTKM_CONT VariantArrayHandleBase<TypeList>& vtkm::cont::VariantArrayHandleBase< TypeList >::operator= ( const VariantArrayHandleBase< TypeList > &  )
default
template<typename TypeList>
VTKM_CONT VariantArrayHandleBase<TypeList>& vtkm::cont::VariantArrayHandleBase< TypeList >::operator= ( VariantArrayHandleBase< TypeList > &&  )
defaultnoexcept
template<typename TypeList>
VTKM_CONT void vtkm::cont::VariantArrayHandleBase< TypeList >::PrintSummary ( std::ostream &  out) const
inline
template<typename TypeList>
void vtkm::cont::VariantArrayHandleBase< TypeList >::ReleaseResources ( )
inline

Releases all resources in both the control and execution environments.

template<typename TypeList>
void vtkm::cont::VariantArrayHandleBase< TypeList >::ReleaseResourcesExecution ( )
inline

Releases any resources being used in the execution environment (that are not being shared by the control environment).

template<typename TypeList>
template<typename NewTypeList >
VTKM_CONT VariantArrayHandleBase<NewTypeList> vtkm::cont::VariantArrayHandleBase< TypeList >::ResetTypes ( NewTypeList  = NewTypeList()) const
inline

Changes the types to try casting to when resolving this variant array, which is specified with a list tag like those in TypeListTag.h.

Since C++ does not allow you to actually change the template arguments, this method returns a new variant array object. This method is particularly useful to narrow down (or expand) the types when using an array of particular constraints.

Member Data Documentation

template<typename TypeList>
std::shared_ptr<vtkm::cont::internal::VariantArrayHandleContainerBase> vtkm::cont::VariantArrayHandleBase< TypeList >::ArrayContainer
private

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