//============================================================================= // // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt for details. // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. // // Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS). // Copyright 2015 UT-Battelle, LLC. // Copyright 2015 Los Alamos National Security. // // Under the terms of Contract DE-NA0003525 with NTESS, // the U.S. Government retains certain rights in this software. // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National // Laboratory (LANL), the U.S. Government retains certain rights in // this software. // //============================================================================= #ifndef vtk_m_cont_ArrayHandleCast_h #define vtk_m_cont_ArrayHandleCast_h #include namespace vtkm { namespace cont { namespace internal { template struct VTKM_ALWAYS_EXPORT Cast { VTKM_EXEC_CONT ToType operator()(const FromType& val) const { return static_cast(val); } }; } // namespace internal /// \brief Cast the values of an array to the specified type, on demand. /// /// ArrayHandleCast is a specialization of ArrayHandleTransform. Given an ArrayHandle /// and a type, it creates a new handle that returns the elements of the array cast /// to the specified type. /// template class ArrayHandleCast : public vtkm::cont::ArrayHandleTransform, internal::Cast> { public: VTKM_ARRAY_HANDLE_SUBCLASS( ArrayHandleCast, (ArrayHandleCast), (vtkm::cont::ArrayHandleTransform, internal::Cast>)); ArrayHandleCast(const ArrayHandleType& handle) : Superclass(handle) { } }; namespace detail { template struct MakeArrayHandleCastImpl { using ReturnType = vtkm::cont::ArrayHandleCast; VTKM_CONT static ReturnType DoMake(const ArrayType& array) { return ReturnType(array); } }; template struct MakeArrayHandleCastImpl { using ReturnType = ArrayType; VTKM_CONT static ReturnType DoMake(const ArrayType& array) { return array; } }; } // namespace detail /// make_ArrayHandleCast is convenience function to generate an /// ArrayHandleCast. /// template VTKM_CONT typename detail::MakeArrayHandleCastImpl::ReturnType make_ArrayHandleCast(const ArrayType& array, const T& = T()) { VTKM_IS_ARRAY_HANDLE(ArrayType); using MakeImpl = detail::MakeArrayHandleCastImpl; return MakeImpl::DoMake(array); } } } // namespace vtkm::cont #endif // vtk_m_cont_ArrayHandleCast_h