Commit b70a000a authored by Robert Maynard's avatar Robert Maynard
Browse files

Allow resetting the Type and Storage of a DynamicArrayHandle in a single call.

vtkm::filter has the use case where we need to reset both the type and
storage of an array handle, by doing both at the same time we can reduce
the number of temporary objects, and invalid conversions of arrays.
parent b93658b4
......@@ -276,6 +276,22 @@ public:
return DynamicArrayHandleBase<TypeList,NewStorageList>(*this);
}
/// Changes the value, and array storage types to try casting to when
/// resolving this dynamic array. Since C++ does not allow you to actually
/// change the template arguments, this method returns a new dynamic array
/// object. This method is particularly useful when you have both custom
/// types and traits.
///
template<typename NewTypeList, typename NewStorageList>
VTKM_CONT_EXPORT
DynamicArrayHandleBase<NewTypeList,NewStorageList>
ResetTypeAndStorageLists(NewTypeList = NewTypeList(),
NewStorageList = NewStorageList()) const {
VTKM_IS_LIST_TAG(NewTypeList);
VTKM_IS_LIST_TAG(NewStorageList);
return DynamicArrayHandleBase<NewTypeList,NewStorageList>(*this);
}
/// Attempts to cast the held array to a specific value type and storage,
/// then call the given functor with the cast array. The types and storage
/// tried in the cast are those in the lists defined by the TypeList and
......
......@@ -332,6 +332,19 @@ void TryUnusualTypeAndStorage()
std::cout << " Caught exception for unrecognized type." << std::endl;
}
try
{
//resetting the string and tag should result in a valid array handle
CheckDynamicArray(array.ResetTypeAndStorageLists(TypeListTagString(),
StorageListTagUnusual()),
1);
}
catch (vtkm::cont::ErrorControlBadValue)
{
VTKM_TEST_FAIL("ResetTypeAndStorageLists should have handled the custom type/storage.");
}
CheckCalled = false;
CheckDynamicArray(array
.ResetTypeList(TypeListTagString())
......@@ -345,6 +358,13 @@ void TryUnusualTypeAndStorage()
.ResetTypeList(TypeListTagString()),
1);
std::cout << " Found instance when storage and type lists were reset." << std:: endl;
CheckCalled = false;
CheckDynamicArray(array
.ResetTypeAndStorageLists(TypeListTagString(),
StorageListTagUnusual()),
1);
std::cout << " Found instance when storage and type lists were reset." << std:: endl;
}
void TryCastToArrayHandle()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment