2014-02-10 18:57:46 +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.
|
|
|
|
//
|
|
|
|
// Copyright 2014 Sandia Corporation.
|
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
2015-05-21 12:09:22 +00:00
|
|
|
// Copyright 2014 Los Alamos National Security.
|
2014-02-10 18:57:46 +00:00
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
|
|
|
// 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.
|
|
|
|
//============================================================================
|
2014-03-07 15:19:09 +00:00
|
|
|
#ifndef vtk_m_TypeTraits_h
|
|
|
|
#define vtk_m_TypeTraits_h
|
2014-02-10 18:57:46 +00:00
|
|
|
|
|
|
|
#include <vtkm/Types.h>
|
|
|
|
|
|
|
|
namespace vtkm {
|
|
|
|
|
2015-06-16 12:34:29 +00:00
|
|
|
/// Tag used to identify types that aren't Real, Integer, Scalar or Vector.
|
|
|
|
///
|
2015-07-07 16:23:10 +00:00
|
|
|
struct TypeTraitsUnknownTag {};
|
2015-06-16 12:34:29 +00:00
|
|
|
|
2014-02-10 18:57:46 +00:00
|
|
|
/// Tag used to identify types that store real (floating-point) numbers. A
|
|
|
|
/// TypeTraits class will typedef this class to NumericTag if it stores real
|
|
|
|
/// numbers (or vectors of real numbers).
|
|
|
|
///
|
|
|
|
struct TypeTraitsRealTag {};
|
|
|
|
|
|
|
|
/// Tag used to identify types that store integer numbers. A TypeTraits class
|
|
|
|
/// will typedef this class to NumericTag if it stores integer numbers (or
|
|
|
|
/// vectors of integers).
|
|
|
|
///
|
|
|
|
struct TypeTraitsIntegerTag {};
|
|
|
|
|
|
|
|
/// Tag used to identify 0 dimensional types (scalars). Scalars can also be
|
2014-10-07 23:27:31 +00:00
|
|
|
/// treated like vectors when used with VecTraits. A TypeTraits class will
|
2014-02-10 18:57:46 +00:00
|
|
|
/// typedef this class to DimensionalityTag.
|
|
|
|
///
|
|
|
|
struct TypeTraitsScalarTag {};
|
|
|
|
|
|
|
|
/// Tag used to identify 1 dimensional types (vectors). A TypeTraits class will
|
|
|
|
/// typedef this class to DimensionalityTag.
|
|
|
|
///
|
|
|
|
struct TypeTraitsVectorTag {};
|
|
|
|
|
|
|
|
|
|
|
|
/// The TypeTraits class provides helpful compile-time information about the
|
|
|
|
/// basic types used in VTKm (and a few others for convienience). The majority
|
|
|
|
/// of TypeTraits contents are typedefs to tags that can be used to easily
|
|
|
|
/// override behavior of called functions.
|
|
|
|
///
|
|
|
|
template<typename T>
|
2014-02-11 21:20:30 +00:00
|
|
|
class TypeTraits
|
|
|
|
{
|
2014-02-10 18:57:46 +00:00
|
|
|
public:
|
|
|
|
/// \brief A tag to determing whether the type is integer or real.
|
|
|
|
///
|
|
|
|
/// This tag is either TypeTraitsRealTag or TypeTraitsIntegerTag.
|
2015-07-07 16:23:10 +00:00
|
|
|
typedef TypeTraitsUnknownTag NumericTag;
|
2014-02-10 18:57:46 +00:00
|
|
|
|
|
|
|
/// \brief A tag to determine whether the type has multiple components.
|
|
|
|
///
|
|
|
|
/// This tag is either TypeTraitsScalarTag or TypeTraitsVectorTag. Scalars can
|
|
|
|
/// also be treated as vectors.
|
2015-07-07 16:23:10 +00:00
|
|
|
typedef TypeTraitsUnknownTag DimensionalityTag;
|
2014-02-10 18:57:46 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT static T ZeroInitialization() { return T(); }
|
2015-06-16 12:34:29 +00:00
|
|
|
};
|
2014-02-10 18:57:46 +00:00
|
|
|
|
|
|
|
// Const types should have the same traits as their non-const counterparts.
|
|
|
|
//
|
|
|
|
template<typename T>
|
|
|
|
struct TypeTraits<const T> : TypeTraits<T>
|
|
|
|
{ };
|
|
|
|
|
|
|
|
#define VTKM_BASIC_REAL_TYPE(T) \
|
2014-02-11 21:20:30 +00:00
|
|
|
template<> struct TypeTraits<T> { \
|
|
|
|
typedef TypeTraitsRealTag NumericTag; \
|
|
|
|
typedef TypeTraitsScalarTag DimensionalityTag; \
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT static T ZeroInitialization() { return T(); } \
|
2016-02-12 21:31:00 +00:00
|
|
|
};
|
2014-02-10 18:57:46 +00:00
|
|
|
|
|
|
|
#define VTKM_BASIC_INTEGER_TYPE(T) \
|
2016-02-12 21:31:00 +00:00
|
|
|
template<> struct TypeTraits< T > { \
|
2014-02-11 21:20:30 +00:00
|
|
|
typedef TypeTraitsIntegerTag NumericTag; \
|
|
|
|
typedef TypeTraitsScalarTag DimensionalityTag; \
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT static T ZeroInitialization() \
|
2016-02-12 21:31:00 +00:00
|
|
|
{ \
|
|
|
|
typedef T ReturnType; \
|
|
|
|
return ReturnType(); \
|
|
|
|
} \
|
|
|
|
}; \
|
2014-02-10 18:57:46 +00:00
|
|
|
|
|
|
|
/// Traits for basic C++ types.
|
|
|
|
///
|
|
|
|
|
2016-02-12 21:31:00 +00:00
|
|
|
VTKM_BASIC_REAL_TYPE(float)
|
|
|
|
VTKM_BASIC_REAL_TYPE(double)
|
|
|
|
|
|
|
|
VTKM_BASIC_INTEGER_TYPE(char)
|
|
|
|
VTKM_BASIC_INTEGER_TYPE(signed char)
|
|
|
|
VTKM_BASIC_INTEGER_TYPE(unsigned char)
|
|
|
|
VTKM_BASIC_INTEGER_TYPE(short)
|
|
|
|
VTKM_BASIC_INTEGER_TYPE(unsigned short)
|
|
|
|
VTKM_BASIC_INTEGER_TYPE(int)
|
|
|
|
VTKM_BASIC_INTEGER_TYPE(unsigned int)
|
|
|
|
VTKM_BASIC_INTEGER_TYPE(long)
|
|
|
|
VTKM_BASIC_INTEGER_TYPE(unsigned long)
|
|
|
|
VTKM_BASIC_INTEGER_TYPE(long long)
|
|
|
|
VTKM_BASIC_INTEGER_TYPE(unsigned long long)
|
|
|
|
|
2014-02-10 18:57:46 +00:00
|
|
|
|
|
|
|
#undef VTKM_BASIC_REAL_TYPE
|
|
|
|
#undef VTKM_BASIC_INTEGER_TYPE
|
|
|
|
|
2014-10-09 14:54:56 +00:00
|
|
|
/// Traits for Vec types.
|
2014-02-10 18:57:46 +00:00
|
|
|
///
|
2014-10-07 16:59:34 +00:00
|
|
|
template<typename T, vtkm::IdComponent Size>
|
2014-10-09 14:54:56 +00:00
|
|
|
struct TypeTraits<vtkm::Vec<T,Size> >
|
2014-02-11 21:20:30 +00:00
|
|
|
{
|
2014-10-09 14:54:56 +00:00
|
|
|
typedef typename vtkm::TypeTraits<T>::NumericTag NumericTag;
|
2014-02-10 18:57:46 +00:00
|
|
|
typedef TypeTraitsVectorTag DimensionalityTag;
|
2015-06-16 12:34:29 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2015-06-16 12:34:29 +00:00
|
|
|
static vtkm::Vec<T,Size> ZeroInitialization()
|
2016-12-05 21:41:33 +00:00
|
|
|
{
|
|
|
|
return vtkm::Vec<T,Size>(vtkm::TypeTraits<T>::ZeroInitialization());
|
|
|
|
}
|
2014-02-10 18:57:46 +00:00
|
|
|
};
|
|
|
|
|
2016-11-30 22:03:30 +00:00
|
|
|
/// Traits for VecCConst types.
|
|
|
|
///
|
|
|
|
template<typename T>
|
|
|
|
struct TypeTraits<vtkm::VecCConst<T> >
|
|
|
|
{
|
|
|
|
using NumericTag = typename vtkm::TypeTraits<T>::NumericTag;
|
|
|
|
using DimensionalityTag = TypeTraitsVectorTag;
|
|
|
|
|
|
|
|
VTKM_EXEC_CONT
|
|
|
|
static vtkm::VecCConst<T> ZeroInitialization()
|
|
|
|
{ return vtkm::VecCConst<T>(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Traits for VecC types.
|
|
|
|
///
|
|
|
|
template<typename T>
|
|
|
|
struct TypeTraits<vtkm::VecC<T> >
|
|
|
|
{
|
|
|
|
using NumericTag = typename vtkm::TypeTraits<T>::NumericTag;
|
|
|
|
using DimensionalityTag = TypeTraitsVectorTag;
|
|
|
|
|
|
|
|
VTKM_EXEC_CONT
|
|
|
|
static vtkm::VecC<T> ZeroInitialization()
|
|
|
|
{ return vtkm::VecC<T>(); }
|
|
|
|
};
|
|
|
|
|
2015-09-20 06:01:04 +00:00
|
|
|
/// \brief Traits for Pair types.
|
|
|
|
///
|
|
|
|
template<typename T, typename U>
|
|
|
|
struct TypeTraits<vtkm::Pair<T,U> >
|
|
|
|
{
|
|
|
|
typedef TypeTraitsUnknownTag NumericTag;
|
|
|
|
typedef TypeTraitsScalarTag DimensionalityTag;
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2015-09-20 06:01:04 +00:00
|
|
|
static vtkm::Pair<T,U> ZeroInitialization()
|
|
|
|
{
|
|
|
|
return vtkm::Pair<T,U>(TypeTraits<T>::ZeroInitialization(),
|
|
|
|
TypeTraits<U>::ZeroInitialization());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-10 18:57:46 +00:00
|
|
|
} // namespace vtkm
|
|
|
|
|
2014-06-11 16:43:36 +00:00
|
|
|
#endif //vtk_m_TypeTraits_h
|