make CastAndCall a free function instead of a class.

Overloading the function serves the same purpose of specializing the
class, but requires less syntax sugar to do.
This commit is contained in:
Robert Maynard 2016-08-05 14:47:19 -04:00
parent 9e9e32ace7
commit 146d800968
3 changed files with 33 additions and 36 deletions

@ -258,6 +258,12 @@ public:
}
};
template<typename Functor>
void CastAndCall(const vtkm::cont::CoordinateSystem& coords, const Functor &f)
{
coords.GetData().CastAndCall(f);
}
namespace internal {
template<>
@ -266,17 +272,6 @@ struct DynamicTransformTraits<vtkm::cont::CoordinateSystem>
typedef vtkm::cont::internal::DynamicTransformTagCastAndCall DynamicTag;
};
template<typename Functor>
struct CastAndCall<vtkm::cont::CoordinateSystem, Functor>
{
VTKM_CONT_EXPORT
void operator()(const vtkm::cont::CoordinateSystem &coordinateSystem,
const Functor &func) const
{
coordinateSystem.GetData().CastAndCall(func);
}
};
} // namespace internal
} // namespace cont
} // namespace vtkm

@ -518,23 +518,19 @@ private:
mutable bool ModifiedFlag;
};
namespace internal {
template<typename Functor>
void CastAndCall(const vtkm::cont::Field& field, const Functor &f)
{
field.GetData().CastAndCall(f);
}
namespace internal {
template<>
struct DynamicTransformTraits<vtkm::cont::Field>
{
typedef vtkm::cont::internal::DynamicTransformTagCastAndCall DynamicTag;
};
template<typename Functor>
struct CastAndCall<vtkm::cont::Field, Functor>
{
VTKM_CONT_EXPORT
void operator()(const vtkm::cont::Field &field, const Functor &func) const
{
field.GetData().CastAndCall(func);
}
};
} // namespace internal
} // namespace cont

@ -25,6 +25,26 @@
namespace vtkm {
namespace cont {
template<typename T, typename S> class ArrayHandle;
/// A Generic interface to CastAndCall. The default implementation simply calls
/// DynamicObject's CastAndCall, but specializations of this function exist for
/// other classes (e.g. Field, CoordinateSystem, ArrayHandle).
template<typename DynamicObject, typename Functor>
void CastAndCall(const DynamicObject& dynamicObject, const Functor &f)
{
dynamicObject.CastAndCall(f);
}
/// A specialization of CastAndCall for basic ArrayHandle types,
/// Since the type is already known no deduction is needed.
/// This specialization is used to simplify numerous worklet algorithms
template<typename T, typename U, typename Functor>
void CastAndCall(const vtkm::cont::ArrayHandle<T,U>& handle, const Functor &f)
{
f(handle);
}
namespace internal {
/// Tag used to identify an object that is a dynamic object that contains a
@ -57,19 +77,6 @@ struct DynamicTransformTraits {
typedef vtkm::cont::internal::DynamicTransformTagStatic DynamicTag;
};
/// A Generic interface to CastAndCall. The default implementation simply calls
/// DynamicObject's CastAndCall, but specializations of this function exist for
/// other classes (e.g. Field, CoordinateSystem).
template<typename DynamicObject, typename Functor>
struct CastAndCall
{
VTKM_CONT_EXPORT
void operator()(const DynamicObject& dynamicObject, const Functor &f)
{
dynamicObject.CastAndCall(f);
}
};
/// This functor can be used as the transform in the \c DynamicTransformCont
/// method of \c FunctionInterface. It will allow dynamic objects like
/// \c DynamicArray to be cast to their concrete types for templated operation.
@ -106,8 +113,7 @@ private:
const ContinueFunctor &continueFunc,
vtkm::cont::internal::DynamicTransformTagCastAndCall) const
{
CastAndCall<InputType, ContinueFunctor> castAndCall;
castAndCall(dynamicInput, continueFunc);
CastAndCall(dynamicInput, continueFunc);
}
};