2014-03-31 21:28:09 +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.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2014-03-31 21:28:09 +00:00
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
2015-05-21 12:09:22 +00:00
|
|
|
// Copyright 2014 Los Alamos National Security.
|
2014-03-31 21:28:09 +00:00
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2014-03-31 21:28:09 +00:00
|
|
|
// 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_ListTag_h
|
|
|
|
#define vtk_m_ListTag_h
|
|
|
|
|
2014-10-08 18:53:01 +00:00
|
|
|
#include <vtkm/internal/ListTagDetail.h>
|
|
|
|
|
2015-09-17 19:45:35 +00:00
|
|
|
#include <vtkm/StaticAssert.h>
|
2014-03-31 21:28:09 +00:00
|
|
|
#include <vtkm/internal/ExportMacros.h>
|
|
|
|
|
2016-08-29 15:13:00 +00:00
|
|
|
#include <type_traits>
|
2014-10-22 13:24:04 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
2014-03-31 21:28:09 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace internal
|
|
|
|
{
|
2014-10-22 13:24:04 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ListTag>
|
|
|
|
struct ListTagCheck : std::is_base_of<vtkm::detail::ListRoot, ListTag>
|
2014-10-22 13:24:04 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
static VTKM_CONSTEXPR bool Valid = std::is_base_of<vtkm::detail::ListRoot, ListTag>::value;
|
2014-10-22 13:24:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
/// Checks that the argument is a proper list tag. This is a handy concept
|
|
|
|
/// check for functions and classes to make sure that a template argument is
|
|
|
|
/// actually a device adapter tag. (You can get weird errors elsewhere in the
|
|
|
|
/// code when a mistake is made.)
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
#define VTKM_IS_LIST_TAG(tag) \
|
|
|
|
VTKM_STATIC_ASSERT_MSG((::vtkm::internal::ListTagCheck<tag>::value), \
|
|
|
|
"Provided type is not a valid VTK-m list tag.")
|
2014-10-22 16:35:56 +00:00
|
|
|
|
2016-12-30 20:42:18 +00:00
|
|
|
/// A special tag for a list that represents holding all potential values
|
|
|
|
///
|
|
|
|
/// Note: Can not be used with ForEach for obvious reasons.
|
2017-05-18 14:29:41 +00:00
|
|
|
struct ListTagUniversal : detail::ListRoot
|
|
|
|
{
|
2016-12-30 20:42:18 +00:00
|
|
|
using list = vtkm::detail::ListBase<vtkm::detail::UniversalTag>;
|
|
|
|
};
|
|
|
|
|
2014-05-14 21:05:38 +00:00
|
|
|
/// A special tag for an empty list.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
struct ListTagEmpty : detail::ListRoot
|
|
|
|
{
|
2016-03-03 20:58:09 +00:00
|
|
|
using list = vtkm::detail::ListBase<>;
|
2014-03-31 21:28:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// A tag that is a construction of two other tags joined together. This struct
|
|
|
|
/// can be subclassed and still behave like a list tag.
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ListTag1, typename ListTag2>
|
|
|
|
struct ListTagJoin : detail::ListRoot
|
|
|
|
{
|
|
|
|
using list = typename detail::ListJoin<typename ListTag1::list, typename ListTag2::list>::type;
|
2014-03-31 21:28:09 +00:00
|
|
|
};
|
|
|
|
|
2017-11-06 15:12:49 +00:00
|
|
|
/// A tag that consists of elements that are found in both tags. This struct
|
2016-12-29 21:00:52 +00:00
|
|
|
/// can be subclassed and still behave like a list tag.
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ListTag1, typename ListTag2>
|
|
|
|
struct ListTagIntersect : detail::ListRoot
|
|
|
|
{
|
|
|
|
using list =
|
|
|
|
typename detail::ListIntersect<typename ListTag1::list, typename ListTag2::list>::type;
|
2016-12-29 21:00:52 +00:00
|
|
|
};
|
|
|
|
|
2014-03-31 21:28:09 +00:00
|
|
|
/// For each typename represented by the list tag, call the functor with a
|
|
|
|
/// default instance of that type.
|
|
|
|
///
|
vtkm::ListForEach can handle passing any number of extra arguments
Rather than requiring all the arguments to be placed as member variables to
the functor you can now pass extra arguments that will be added to the functor
call signature.
So for example:
vtkm::ForEach(functor, vtkm::TypeListTagCommon(), double{42.0}, int{42});
will be converted into:
functor(vtkm::Int32, double, int)
functor(vtkm::Int64, double, int)
functor(vtkm::Float32, double, int)
functor(vtkm::Float64, double, int)
...
2017-11-06 22:26:20 +00:00
|
|
|
template <typename Functor, typename ListTag, typename... Args>
|
|
|
|
VTKM_CONT void ListForEach(Functor&& f, ListTag, Args&&... args)
|
2014-03-31 21:28:09 +00:00
|
|
|
{
|
2014-10-22 16:35:56 +00:00
|
|
|
VTKM_IS_LIST_TAG(ListTag);
|
vtkm::ListForEach can handle passing any number of extra arguments
Rather than requiring all the arguments to be placed as member variables to
the functor you can now pass extra arguments that will be added to the functor
call signature.
So for example:
vtkm::ForEach(functor, vtkm::TypeListTagCommon(), double{42.0}, int{42});
will be converted into:
functor(vtkm::Int32, double, int)
functor(vtkm::Int64, double, int)
functor(vtkm::Float32, double, int)
functor(vtkm::Float64, double, int)
...
2017-11-06 22:26:20 +00:00
|
|
|
detail::ListForEachImpl(
|
|
|
|
std::forward<Functor>(f), typename ListTag::list{}, std::forward<Args>(args)...);
|
2014-03-31 21:28:09 +00:00
|
|
|
}
|
|
|
|
|
2017-11-06 15:12:49 +00:00
|
|
|
/// Generate a tag that is the cross product of two other tags. The resulting
|
2017-12-11 18:31:56 +00:00
|
|
|
// a tag has the form of Tag< brigand::list<A1,B1>, brigand::list<A1,B2> .... >
|
2017-11-06 15:12:49 +00:00
|
|
|
///
|
|
|
|
template <typename ListTag1, typename ListTag2>
|
|
|
|
struct ListCrossProduct : detail::ListRoot
|
|
|
|
{
|
|
|
|
using list =
|
|
|
|
typename detail::ListCrossProductImpl<typename ListTag1::list, typename ListTag2::list>::type;
|
|
|
|
};
|
|
|
|
|
2014-10-22 16:35:56 +00:00
|
|
|
/// Checks to see if the given \c Type is in the list pointed to by \c ListTag.
|
|
|
|
/// There is a static boolean named \c value that is set to true if the type is
|
|
|
|
/// contained in the list and false otherwise.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ListTag, typename Type>
|
2014-10-22 16:35:56 +00:00
|
|
|
struct ListContains
|
|
|
|
{
|
|
|
|
VTKM_IS_LIST_TAG(ListTag);
|
2017-05-18 14:29:41 +00:00
|
|
|
static VTKM_CONSTEXPR bool value = detail::ListContainsImpl<Type, typename ListTag::list>::value;
|
2014-10-22 16:35:56 +00:00
|
|
|
};
|
|
|
|
|
2014-03-31 21:28:09 +00:00
|
|
|
} // namespace vtkm
|
|
|
|
|
|
|
|
#endif //vtk_m_ListTag_h
|