2018-11-06 16:20:30 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2018-11-06 16:20:30 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtk_m_cont_ArrayHandleVirtual_h
|
|
|
|
#define vtk_m_cont_ArrayHandleVirtual_h
|
|
|
|
|
|
|
|
#include <vtkm/cont/vtkm_cont_export.h>
|
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
2018-12-24 19:29:12 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
|
2019-04-03 20:28:31 +00:00
|
|
|
#include <vtkm/cont/DeviceAdapterTag.h>
|
2018-11-06 16:20:30 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/StorageVirtual.h>
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2020-09-03 19:54:24 +00:00
|
|
|
#ifdef VTKM_NO_DEPRECATED_VIRTUAL
|
|
|
|
#error "ArrayHandleVirtual is removed. Do not include ArrayHandleVirtual.h"
|
|
|
|
#endif
|
|
|
|
|
2018-11-06 16:20:30 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
|
2019-02-10 08:46:43 +00:00
|
|
|
|
2020-09-02 22:36:52 +00:00
|
|
|
VTKM_DEPRECATED_SUPPRESS_BEGIN
|
2018-11-06 16:20:30 +00:00
|
|
|
template <typename T>
|
2020-09-02 22:36:52 +00:00
|
|
|
class VTKM_ALWAYS_EXPORT VTKM_DEPRECATED(1.6) ArrayHandleVirtual
|
2019-02-26 19:23:18 +00:00
|
|
|
: public vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagVirtual>
|
2018-11-06 16:20:30 +00:00
|
|
|
{
|
2019-02-10 08:46:43 +00:00
|
|
|
using StorageType = vtkm::cont::internal::Storage<T, vtkm::cont::StorageTagVirtual>;
|
2018-11-06 16:20:30 +00:00
|
|
|
|
2019-02-10 08:46:43 +00:00
|
|
|
public:
|
|
|
|
VTKM_ARRAY_HANDLE_SUBCLASS(ArrayHandleVirtual,
|
|
|
|
(ArrayHandleVirtual<T>),
|
|
|
|
(vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagVirtual>));
|
2018-12-24 19:29:12 +00:00
|
|
|
|
|
|
|
///Construct a valid ArrayHandleVirtual from an existing ArrayHandle
|
|
|
|
///that doesn't derive from ArrayHandleVirtual.
|
|
|
|
///Note left non-explicit to allow:
|
|
|
|
///
|
|
|
|
/// std::vector<vtkm::cont::ArrayHandleVirtual<vtkm::Float64>> vectorOfArrays;
|
|
|
|
/// //Make basic array.
|
|
|
|
/// vtkm::cont::ArrayHandle<vtkm::Float64> basicArray;
|
|
|
|
/// //Fill basicArray...
|
|
|
|
/// vectorOfArrays.push_back(basicArray);
|
|
|
|
///
|
|
|
|
/// // Make fancy array.
|
|
|
|
/// vtkm::cont::ArrayHandleCounting<vtkm::Float64> fancyArray(-1.0, 0.1, ARRAY_SIZE);
|
|
|
|
/// vectorOfArrays.push_back(fancyArray);
|
|
|
|
template <typename S>
|
2019-02-10 08:46:43 +00:00
|
|
|
ArrayHandleVirtual(const vtkm::cont::ArrayHandle<T, S>& ah)
|
|
|
|
: Superclass(StorageType(ah))
|
2018-12-24 19:29:12 +00:00
|
|
|
{
|
2019-02-10 08:46:43 +00:00
|
|
|
using is_base = std::is_base_of<StorageType, S>;
|
2018-12-24 19:29:12 +00:00
|
|
|
static_assert(!is_base::value, "Wrong specialization for ArrayHandleVirtual selected");
|
|
|
|
}
|
|
|
|
|
2018-12-31 15:20:54 +00:00
|
|
|
/// Returns true if this array matches the type passed in.
|
2018-11-06 16:20:30 +00:00
|
|
|
///
|
|
|
|
template <typename ArrayHandleType>
|
|
|
|
VTKM_CONT bool IsType() const
|
|
|
|
{
|
|
|
|
VTKM_IS_ARRAY_HANDLE(ArrayHandleType);
|
|
|
|
|
2018-11-06 16:40:39 +00:00
|
|
|
//We need to determine if we are checking that `ArrayHandleType`
|
|
|
|
//is a virtual array handle since that is an easy check.
|
|
|
|
//Or if we have to go ask the storage if they are holding
|
|
|
|
//
|
2018-11-06 16:20:30 +00:00
|
|
|
using ST = typename ArrayHandleType::StorageTag;
|
2018-11-06 16:40:39 +00:00
|
|
|
using is_base = std::is_same<vtkm::cont::StorageTagVirtual, ST>;
|
2018-12-31 15:20:54 +00:00
|
|
|
|
|
|
|
//Determine if the Value type of the virtual and ArrayHandleType
|
|
|
|
//are the same. This an easy compile time check, and doesn't need
|
|
|
|
// to be done at runtime.
|
|
|
|
using VT = typename ArrayHandleType::ValueType;
|
|
|
|
using same_value_type = std::is_same<T, VT>;
|
|
|
|
|
|
|
|
return this->IsSameType<ArrayHandleType>(same_value_type{}, is_base{});
|
2018-11-06 16:20:30 +00:00
|
|
|
}
|
|
|
|
|
2018-12-18 20:10:55 +00:00
|
|
|
/// Returns this array cast to the given \c ArrayHandle type. Throws \c
|
|
|
|
/// ErrorBadType if the cast does not work. Use \c IsType
|
|
|
|
/// to check if the cast can happen.
|
|
|
|
///
|
|
|
|
template <typename ArrayHandleType>
|
|
|
|
VTKM_CONT ArrayHandleType Cast() const
|
|
|
|
{
|
|
|
|
VTKM_IS_ARRAY_HANDLE(ArrayHandleType);
|
|
|
|
//We need to determine if we are checking that `ArrayHandleType`
|
|
|
|
//is a virtual array handle since that is an easy check.
|
|
|
|
//Or if we have to go ask the storage if they are holding
|
|
|
|
//
|
|
|
|
using ST = typename ArrayHandleType::StorageTag;
|
|
|
|
using is_base = std::is_same<vtkm::cont::StorageTagVirtual, ST>;
|
2018-12-31 15:20:54 +00:00
|
|
|
|
|
|
|
//Determine if the Value type of the virtual and ArrayHandleType
|
|
|
|
//are the same. This an easy compile time check, and doesn't need
|
|
|
|
// to be done at runtime.
|
|
|
|
using VT = typename ArrayHandleType::ValueType;
|
|
|
|
using same_value_type = std::is_same<T, VT>;
|
|
|
|
|
|
|
|
return this->CastToType<ArrayHandleType>(same_value_type{}, is_base{});
|
2018-12-18 20:10:55 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 16:20:30 +00:00
|
|
|
/// Returns a new instance of an ArrayHandleVirtual with the same storage
|
|
|
|
///
|
2019-02-10 08:46:43 +00:00
|
|
|
VTKM_CONT ArrayHandleVirtual<T> NewInstance() const
|
2018-11-06 16:20:30 +00:00
|
|
|
{
|
2019-02-10 08:46:43 +00:00
|
|
|
return ArrayHandleVirtual<T>(this->GetStorage().NewInstance());
|
2018-11-06 16:20:30 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 16:40:39 +00:00
|
|
|
private:
|
|
|
|
template <typename ArrayHandleType>
|
2018-12-31 15:20:54 +00:00
|
|
|
inline bool IsSameType(std::false_type, std::true_type) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
template <typename ArrayHandleType>
|
|
|
|
inline bool IsSameType(std::false_type, std::false_type) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ArrayHandleType>
|
|
|
|
inline bool IsSameType(std::true_type vtkmNotUsed(valueTypesMatch),
|
|
|
|
std::true_type vtkmNotUsed(inheritsFromArrayHandleVirtual)) const
|
2018-11-06 16:40:39 +00:00
|
|
|
{
|
2019-01-08 14:37:20 +00:00
|
|
|
//The type being past has no requirements in being the most derived type
|
|
|
|
//so the typeid info won't match but dynamic_cast will work
|
2018-12-31 15:20:54 +00:00
|
|
|
auto casted = dynamic_cast<const ArrayHandleType*>(this);
|
|
|
|
return casted != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ArrayHandleType>
|
|
|
|
inline bool IsSameType(std::true_type vtkmNotUsed(valueTypesMatch),
|
|
|
|
std::false_type vtkmNotUsed(notFromArrayHandleVirtual)) const
|
|
|
|
{
|
2019-02-10 08:46:43 +00:00
|
|
|
auto* storage = this->GetStorage().GetStorageVirtual();
|
|
|
|
if (!storage)
|
2018-12-31 15:20:54 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
using S = typename ArrayHandleType::StorageTag;
|
2019-02-10 08:46:43 +00:00
|
|
|
return storage->template IsType<vtkm::cont::internal::detail::StorageVirtualImpl<T, S>>();
|
2018-11-06 16:40:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ArrayHandleType>
|
2018-12-31 15:20:54 +00:00
|
|
|
inline ArrayHandleType CastToType(std::false_type vtkmNotUsed(valueTypesMatch),
|
|
|
|
std::true_type vtkmNotUsed(notFromArrayHandleVirtual)) const
|
|
|
|
{
|
|
|
|
VTKM_LOG_CAST_FAIL(*this, ArrayHandleType);
|
2019-02-28 18:15:27 +00:00
|
|
|
throwFailedDynamicCast("ArrayHandleVirtual", vtkm::cont::TypeToString<ArrayHandleType>());
|
2018-12-31 15:20:54 +00:00
|
|
|
return ArrayHandleType{};
|
|
|
|
}
|
2018-12-18 20:10:55 +00:00
|
|
|
|
|
|
|
template <typename ArrayHandleType>
|
2018-12-31 15:20:54 +00:00
|
|
|
inline ArrayHandleType CastToType(std::false_type vtkmNotUsed(valueTypesMatch),
|
|
|
|
std::false_type vtkmNotUsed(notFromArrayHandleVirtual)) const
|
|
|
|
{
|
|
|
|
VTKM_LOG_CAST_FAIL(*this, ArrayHandleType);
|
2019-02-28 18:15:27 +00:00
|
|
|
throwFailedDynamicCast("ArrayHandleVirtual", vtkm::cont::TypeToString<ArrayHandleType>());
|
2018-12-31 15:20:54 +00:00
|
|
|
return ArrayHandleType{};
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ArrayHandleType>
|
|
|
|
inline ArrayHandleType CastToType(
|
|
|
|
std::true_type vtkmNotUsed(valueTypesMatch),
|
|
|
|
std::true_type vtkmNotUsed(inheritsFromArrayHandleVirtual)) const
|
2018-11-06 16:40:39 +00:00
|
|
|
{
|
2019-01-08 14:37:20 +00:00
|
|
|
//The type being passed has no requirements in being the most derived type
|
|
|
|
//so the typeid info won't match but dynamic_cast will work
|
2018-12-18 20:10:55 +00:00
|
|
|
const ArrayHandleType* derived = dynamic_cast<const ArrayHandleType*>(this);
|
|
|
|
if (!derived)
|
|
|
|
{
|
|
|
|
VTKM_LOG_CAST_FAIL(*this, ArrayHandleType);
|
2019-02-28 18:15:27 +00:00
|
|
|
throwFailedDynamicCast("ArrayHandleVirtual", vtkm::cont::TypeToString<ArrayHandleType>());
|
2018-12-18 20:10:55 +00:00
|
|
|
}
|
|
|
|
VTKM_LOG_CAST_SUCC(*this, derived);
|
|
|
|
return *derived;
|
2018-11-06 16:40:39 +00:00
|
|
|
}
|
2018-12-18 20:10:55 +00:00
|
|
|
|
|
|
|
template <typename ArrayHandleType>
|
2018-12-31 15:20:54 +00:00
|
|
|
ArrayHandleType CastToType(std::true_type vtkmNotUsed(valueTypesMatch),
|
|
|
|
std::false_type vtkmNotUsed(notFromArrayHandleVirtual)) const;
|
2018-11-06 16:20:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-12-24 19:29:12 +00:00
|
|
|
//=============================================================================
|
|
|
|
/// A convenience function for creating an ArrayHandleVirtual.
|
|
|
|
template <typename T, typename S>
|
|
|
|
VTKM_CONT vtkm::cont::ArrayHandleVirtual<T> make_ArrayHandleVirtual(
|
|
|
|
const vtkm::cont::ArrayHandle<T, S>& ah)
|
|
|
|
{
|
|
|
|
return vtkm::cont::ArrayHandleVirtual<T>(ah);
|
|
|
|
}
|
|
|
|
|
2018-12-18 20:10:55 +00:00
|
|
|
//=============================================================================
|
|
|
|
// Free function casting helpers
|
|
|
|
|
2018-12-31 15:20:54 +00:00
|
|
|
/// Returns true if \c virtHandle matches the type of ArrayHandleType.
|
|
|
|
///
|
2018-12-18 20:10:55 +00:00
|
|
|
template <typename ArrayHandleType, typename T>
|
2019-04-08 19:42:53 +00:00
|
|
|
VTKM_CONT inline bool IsType(
|
|
|
|
const vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagVirtual>& virtHandle)
|
2018-12-18 20:10:55 +00:00
|
|
|
{
|
2019-04-08 19:42:53 +00:00
|
|
|
return static_cast<vtkm::cont::ArrayHandleVirtual<T>>(virtHandle)
|
|
|
|
.template IsType<ArrayHandleType>();
|
2018-12-18 20:10:55 +00:00
|
|
|
}
|
|
|
|
|
2018-12-31 15:20:54 +00:00
|
|
|
/// Returns \c virtHandle cast to the given \c ArrayHandle type. Throws \c
|
|
|
|
/// ErrorBadType if the cast does not work. Use \c IsType
|
|
|
|
/// to check if the cast can happen.
|
|
|
|
///
|
2018-12-18 20:10:55 +00:00
|
|
|
template <typename ArrayHandleType, typename T>
|
2019-04-08 19:42:53 +00:00
|
|
|
VTKM_CONT inline ArrayHandleType Cast(
|
|
|
|
const vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagVirtual>& virtHandle)
|
2018-12-18 20:10:55 +00:00
|
|
|
{
|
2019-04-08 19:42:53 +00:00
|
|
|
return static_cast<vtkm::cont::ArrayHandleVirtual<T>>(virtHandle)
|
|
|
|
.template Cast<ArrayHandleType>();
|
2018-12-18 20:10:55 +00:00
|
|
|
}
|
2018-12-06 15:04:43 +00:00
|
|
|
//=============================================================================
|
|
|
|
// Specializations of serialization related classes
|
2019-09-12 21:19:36 +00:00
|
|
|
/// @cond SERIALIZATION
|
2018-12-06 15:04:43 +00:00
|
|
|
template <typename T>
|
2019-02-28 18:15:27 +00:00
|
|
|
struct SerializableTypeString<vtkm::cont::ArrayHandleVirtual<T>>
|
2018-12-06 15:04:43 +00:00
|
|
|
{
|
|
|
|
static VTKM_CONT const std::string& Get()
|
|
|
|
{
|
2019-02-28 18:15:27 +00:00
|
|
|
static std::string name = "AH_Virtual<" + SerializableTypeString<T>::Get() + ">";
|
2018-12-06 15:04:43 +00:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
};
|
2019-02-26 19:23:18 +00:00
|
|
|
|
2019-04-08 19:42:53 +00:00
|
|
|
template <typename T>
|
|
|
|
struct SerializableTypeString<vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagVirtual>>
|
|
|
|
: public SerializableTypeString<vtkm::cont::ArrayHandleVirtual<T>>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2019-02-26 19:23:18 +00:00
|
|
|
#ifndef vtk_m_cont_ArrayHandleVirtual_cxx
|
|
|
|
|
|
|
|
#define VTK_M_ARRAY_HANDLE_VIRTUAL_EXPORT(T) \
|
|
|
|
extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<T, StorageTagVirtual>; \
|
|
|
|
extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandleVirtual<T>; \
|
|
|
|
extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::Vec<T, 2>, StorageTagVirtual>; \
|
|
|
|
extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandleVirtual<vtkm::Vec<T, 2>>; \
|
|
|
|
extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::Vec<T, 3>, StorageTagVirtual>; \
|
|
|
|
extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandleVirtual<vtkm::Vec<T, 3>>; \
|
|
|
|
extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::Vec<T, 4>, StorageTagVirtual>; \
|
|
|
|
extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandleVirtual<vtkm::Vec<T, 4>>
|
|
|
|
|
|
|
|
VTK_M_ARRAY_HANDLE_VIRTUAL_EXPORT(char);
|
|
|
|
VTK_M_ARRAY_HANDLE_VIRTUAL_EXPORT(vtkm::Int8);
|
|
|
|
VTK_M_ARRAY_HANDLE_VIRTUAL_EXPORT(vtkm::UInt8);
|
|
|
|
VTK_M_ARRAY_HANDLE_VIRTUAL_EXPORT(vtkm::Int16);
|
|
|
|
VTK_M_ARRAY_HANDLE_VIRTUAL_EXPORT(vtkm::UInt16);
|
|
|
|
VTK_M_ARRAY_HANDLE_VIRTUAL_EXPORT(vtkm::Int32);
|
|
|
|
VTK_M_ARRAY_HANDLE_VIRTUAL_EXPORT(vtkm::UInt32);
|
|
|
|
VTK_M_ARRAY_HANDLE_VIRTUAL_EXPORT(vtkm::Int64);
|
|
|
|
VTK_M_ARRAY_HANDLE_VIRTUAL_EXPORT(vtkm::UInt64);
|
|
|
|
VTK_M_ARRAY_HANDLE_VIRTUAL_EXPORT(vtkm::Float32);
|
|
|
|
VTK_M_ARRAY_HANDLE_VIRTUAL_EXPORT(vtkm::Float64);
|
|
|
|
|
|
|
|
#undef VTK_M_ARRAY_HANDLE_VIRTUAL_EXPORT
|
|
|
|
|
|
|
|
#endif //vtk_m_cont_ArrayHandleVirtual_cxx
|
2020-09-02 22:36:52 +00:00
|
|
|
VTKM_DEPRECATED_SUPPRESS_END
|
2018-12-06 15:04:43 +00:00
|
|
|
}
|
|
|
|
} //namespace vtkm::cont
|
2018-11-06 16:20:30 +00:00
|
|
|
|
2020-03-23 23:55:46 +00:00
|
|
|
/// @endcond SERIALIZATION
|
2018-11-06 16:20:30 +00:00
|
|
|
|
2018-12-06 15:04:43 +00:00
|
|
|
#endif //vtk_m_cont_ArrayHandleVirtual_h
|