1 //============================================================================= 2 // 3 // Copyright (c) Kitware, Inc. 4 // All rights reserved. 5 // See LICENSE.txt for details. 6 // 7 // This software is distributed WITHOUT ANY WARRANTY; without even 8 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 9 // PURPOSE. See the above copyright notice for more information. 10 // 11 // Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 12 // Copyright 2015 UT-Battelle, LLC. 13 // Copyright 2015 Los Alamos National Security. 14 // 15 // Under the terms of Contract DE-NA0003525 with NTESS, 16 // the U.S. Government retains certain rights in this software. 17 // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National 18 // Laboratory (LANL), the U.S. Government retains certain rights in 19 // this software. 20 // 21 //============================================================================= 22 #ifndef vtk_m_cont_ArrayHandleIndex_h 23 #define vtk_m_cont_ArrayHandleIndex_h 24 25 #include <vtkm/cont/ArrayHandleImplicit.h> 26 27 namespace vtkm 28 { 29 namespace cont 30 { 31 32 namespace detail 33 { 34 35 struct VTKM_ALWAYS_EXPORT IndexFunctor 36 { 37 VTKM_EXEC_CONT operatorIndexFunctor38 vtkm::Id operator()(vtkm::Id index) const { return index; } 39 }; 40 41 } // namespace detail 42 43 /// \brief An implicit array handle containing the its own indices. 44 /// 45 /// \c ArrayHandleIndex is an implicit array handle containing the values 46 /// 0, 1, 2, 3,... to a specified size. Every value in the array is the same 47 /// as the index to that value. 48 /// 49 class ArrayHandleIndex : public vtkm::cont::ArrayHandleImplicit<detail::IndexFunctor> 50 { 51 public: 52 VTKM_ARRAY_HANDLE_SUBCLASS_NT(ArrayHandleIndex, 53 (vtkm::cont::ArrayHandleImplicit<detail::IndexFunctor>)); 54 55 VTKM_CONT ArrayHandleIndex(vtkm::Id length)56 ArrayHandleIndex(vtkm::Id length) 57 : Superclass(detail::IndexFunctor(), length) 58 { 59 } 60 }; 61 } 62 } // namespace vtkm::cont 63 64 //============================================================================= 65 // Specializations of serialization related classes 66 67 namespace vtkm 68 { 69 namespace cont 70 { 71 72 template <> 73 struct TypeString<vtkm::cont::detail::IndexFunctor> 74 { 75 static VTKM_CONT const std::string Get() { return "AH_IndexFunctor"; } 76 }; 77 78 template <> 79 struct TypeString<vtkm::cont::ArrayHandleIndex> 80 : TypeString<vtkm::cont::ArrayHandleImplicit<vtkm::cont::detail::IndexFunctor>> 81 { 82 }; 83 } 84 } // vtkm::cont 85 86 namespace diy 87 { 88 89 template <> 90 struct Serialization<vtkm::cont::detail::IndexFunctor> 91 { 92 static VTKM_CONT void save(BinaryBuffer&, const vtkm::cont::detail::IndexFunctor&) {} 93 94 static VTKM_CONT void load(BinaryBuffer&, vtkm::cont::detail::IndexFunctor&) {} 95 }; 96 97 template <> 98 struct Serialization<vtkm::cont::ArrayHandleIndex> 99 : Serialization<vtkm::cont::ArrayHandleImplicit<vtkm::cont::detail::IndexFunctor>> 100 { 101 }; 102 103 } // diy 104 105 #endif //vtk_m_cont_ArrayHandleIndex_h 106