//============================================================================ // 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 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). // Copyright 2014 UT-Battelle, LLC. // Copyright 2014 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_ArrayHandleCounting_h #define vtk_m_cont_ArrayHandleCounting_h #include #include #include namespace vtkm { namespace cont { namespace internal { /// \brief An implicit array portal that returns an counting value. template class VTKM_ALWAYS_EXPORT ArrayPortalCounting { using ComponentType = typename vtkm::VecTraits::ComponentType; public: using ValueType = CountingValueType; VTKM_EXEC_CONT ArrayPortalCounting() : Start(0) , Step(1) , NumberOfValues(0) { } VTKM_EXEC_CONT ArrayPortalCounting(ValueType start, ValueType step, vtkm::Id numValues) : Start(start) , Step(step) , NumberOfValues(numValues) { } template VTKM_EXEC_CONT ArrayPortalCounting(const ArrayPortalCounting& src) : Start(src.Start) , Step(src.Step) , NumberOfValues(src.NumberOfValues) { } template VTKM_EXEC_CONT ArrayPortalCounting& operator=( const ArrayPortalCounting& src) { this->Start = src.Start; this->Step = src.Step; this->NumberOfValues = src.NumberOfValues; return *this; } VTKM_EXEC_CONT vtkm::Id GetNumberOfValues() const { return this->NumberOfValues; } VTKM_EXEC_CONT ValueType Get(vtkm::Id index) const { return ValueType(this->Start + this->Step * ValueType(static_cast(index))); } VTKM_EXEC_CONT void Set(vtkm::Id vtkmNotUsed(index), const ValueType& vtkmNotUsed(value)) const { VTKM_ASSERT(false && "Cannot write to read-only counting array."); } private: ValueType Start; ValueType Step; vtkm::Id NumberOfValues; }; /// A convenience class that provides a typedef to the appropriate tag for /// a counting storage. template struct ArrayHandleCountingTraits { using Tag = vtkm::cont::StorageTagImplicit>; }; } // namespace internal /// ArrayHandleCounting is a specialization of ArrayHandle. By default it /// contains a increment value, that is increment for each step between zero /// and the passed in length template class ArrayHandleCounting : public vtkm::cont::ArrayHandle< CountingValueType, typename internal::ArrayHandleCountingTraits::Tag> { public: VTKM_ARRAY_HANDLE_SUBCLASS( ArrayHandleCounting, (ArrayHandleCounting), (vtkm::cont::ArrayHandle< CountingValueType, typename internal::ArrayHandleCountingTraits::Tag>)); VTKM_CONT ArrayHandleCounting(CountingValueType start, CountingValueType step, vtkm::Id length) : Superclass(typename Superclass::PortalConstControl(start, step, length)) { } }; /// A convenience function for creating an ArrayHandleCounting. It takes the /// value to start counting from and and the number of times to increment. template VTKM_CONT vtkm::cont::ArrayHandleCounting make_ArrayHandleCounting(CountingValueType start, CountingValueType step, vtkm::Id length) { return vtkm::cont::ArrayHandleCounting(start, step, length); } } } // namespace vtkm::cont #endif //vtk_m_cont_ArrayHandleCounting_h