vtk-m/vtkm/cont/ArrayHandleConstant.h

115 lines
3.1 KiB
C
Raw Normal View History

2019-04-15 23:24:21 +00:00
//============================================================================
2015-05-13 20:24:51 +00:00
// 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.
2019-04-15 23:24:21 +00:00
//============================================================================
2015-05-13 20:24:51 +00:00
#ifndef vtk_m_cont_ArrayHandleConstant_h
#define vtk_m_cont_ArrayHandleConstant_h
#include <vtkm/cont/ArrayHandleImplicit.h>
2017-05-18 14:29:41 +00:00
namespace vtkm
{
namespace cont
{
2015-05-13 20:24:51 +00:00
2017-05-18 14:29:41 +00:00
namespace detail
{
2015-05-13 20:24:51 +00:00
2017-05-18 14:29:41 +00:00
template <typename ValueType>
struct VTKM_ALWAYS_EXPORT ConstantFunctor
2015-05-13 20:24:51 +00:00
{
VTKM_EXEC_CONT
2017-05-18 14:29:41 +00:00
ConstantFunctor(const ValueType& value = ValueType())
: Value(value)
2015-05-13 20:24:51 +00:00
{
}
2017-05-18 14:29:41 +00:00
VTKM_EXEC_CONT
ValueType operator()(vtkm::Id vtkmNotUsed(index)) const { return this->Value; }
2015-05-13 20:24:51 +00:00
private:
ValueType Value;
};
} // namespace detail
/// \brief An array handle with a constant value.
///
/// ArrayHandleConstant is an implicit array handle with a constant value. A
/// constant array handle is constructed by giving a value and an array length.
/// The resulting array is of the given size with each entry the same value
/// given in the constructor. The array is defined implicitly, so there it
/// takes (almost) no memory.
///
2017-05-18 14:29:41 +00:00
template <typename T>
2017-05-30 15:13:18 +00:00
class ArrayHandleConstant : public vtkm::cont::ArrayHandleImplicit<detail::ConstantFunctor<T>>
2015-05-13 20:24:51 +00:00
{
public:
VTKM_ARRAY_HANDLE_SUBCLASS(ArrayHandleConstant,
(ArrayHandleConstant<T>),
2017-05-30 15:13:18 +00:00
(vtkm::cont::ArrayHandleImplicit<detail::ConstantFunctor<T>>));
VTKM_CONT
ArrayHandleConstant(T value, vtkm::Id numberOfValues = 0)
2017-05-18 14:29:41 +00:00
: Superclass(detail::ConstantFunctor<T>(value), numberOfValues)
{
}
2015-05-13 20:24:51 +00:00
};
/// make_ArrayHandleConstant is convenience function to generate an
2015-05-13 20:24:51 +00:00
/// ArrayHandleImplicit. It takes a functor and the virtual length of the
/// array.
2015-05-13 20:24:51 +00:00
///
2017-05-18 14:29:41 +00:00
template <typename T>
vtkm::cont::ArrayHandleConstant<T> make_ArrayHandleConstant(T value, vtkm::Id numberOfValues)
2015-05-13 20:24:51 +00:00
{
return vtkm::cont::ArrayHandleConstant<T>(value, numberOfValues);
}
}
} // vtkm::cont
2018-06-08 15:56:40 +00:00
//=============================================================================
// Specializations of serialization related classes
/// @cond SERIALIZATION
2018-06-08 15:56:40 +00:00
namespace vtkm
{
namespace cont
{
template <typename T>
struct SerializableTypeString<vtkm::cont::detail::ConstantFunctor<T>>
2018-06-08 15:56:40 +00:00
{
static VTKM_CONT const std::string& Get()
{
static std::string name = "AH_ConstantFunctor<" + SerializableTypeString<T>::Get() + ">";
2018-06-08 15:56:40 +00:00
return name;
}
};
template <typename T>
struct SerializableTypeString<vtkm::cont::ArrayHandleConstant<T>>
: SerializableTypeString<vtkm::cont::ArrayHandleImplicit<vtkm::cont::detail::ConstantFunctor<T>>>
2018-06-08 15:56:40 +00:00
{
};
}
} // vtkm::cont
namespace mangled_diy_namespace
2018-06-08 15:56:40 +00:00
{
template <typename T>
struct Serialization<vtkm::cont::ArrayHandleConstant<T>>
: Serialization<vtkm::cont::ArrayHandleImplicit<vtkm::cont::detail::ConstantFunctor<T>>>
{
};
} // diy
/// @endcond SERIALIZATION
2018-06-08 15:56:40 +00:00
2015-05-13 20:24:51 +00:00
#endif //vtk_m_cont_ArrayHandleConstant_h