BaseComponent.h 2.19 KB
Newer Older
1 2 3 4 5 6 7 8
//============================================================================
//  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.
//
9
//  Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 11 12
//  Copyright 2015 UT-Battelle, LLC.
//  Copyright 2015 Los Alamos National Security.
//
13
//  Under the terms of Contract DE-NA0003525 with NTESS,
14 15 16 17 18 19 20 21 22 23 24 25 26
//  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_BaseComponent_h
#define vtk_m_BaseComponent_h

#include <vtkm/Matrix.h>
#include <vtkm/TypeTraits.h>
#include <vtkm/VecTraits.h>

27 28
namespace vtkm
{
29

30 31
namespace detail
{
32

33
template <typename VecType, typename DimensionalityTag>
34 35
struct BaseComponentImpl;

36
template <typename VecType>
37 38 39 40
struct BaseComponentImpl<VecType, vtkm::TypeTraitsVectorTag>
{
private:
  using ComponentType = typename vtkm::VecTraits<VecType>::ComponentType;
41

42 43
public:
  using Type =
44 45
    typename BaseComponentImpl<ComponentType,
                               typename vtkm::TypeTraits<ComponentType>::DimensionalityTag>::Type;
46 47
};

48
template <typename VecType>
49 50
struct BaseComponentImpl<VecType, vtkm::TypeTraitsMatrixTag>
  : BaseComponentImpl<VecType, vtkm::TypeTraitsVectorTag>
51 52
{
};
53

54
template <typename ScalarType>
55 56 57 58 59 60 61 62 63
struct BaseComponentImpl<ScalarType, vtkm::TypeTraitsScalarTag>
{
  using Type = ScalarType;
};

} // namespace detail

// Finds the base component type of a Vec. If you have a Vec of Vecs, it will
// descend all Vecs until you get to the scalar type.
64
template <typename VecType>
65 66 67
struct BaseComponent
{
  using Type =
68 69
    typename detail::BaseComponentImpl<VecType,
                                       typename vtkm::TypeTraits<VecType>::DimensionalityTag>::Type;
70 71 72 73 74
};

} // namespace vtkm

#endif //vtk_m_BaseComponent_h