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.
|
|
|
|
//
|
|
|
|
// Copyright 2014 Sandia Corporation.
|
|
|
|
// 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
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
#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>
|
|
|
|
|
2015-08-12 19:08:45 +00:00
|
|
|
VTKM_THIRDPARTY_PRE_INCLUDE
|
2014-10-22 13:24:04 +00:00
|
|
|
#include <boost/type_traits/is_base_of.hpp>
|
2015-08-12 19:08:45 +00:00
|
|
|
VTKM_THIRDPARTY_POST_INCLUDE
|
2014-10-22 13:24:04 +00:00
|
|
|
|
2014-03-31 21:28:09 +00:00
|
|
|
namespace vtkm {
|
|
|
|
|
2014-10-22 13:24:04 +00:00
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
template<typename ListTag>
|
|
|
|
struct ListTagCheck
|
|
|
|
{
|
|
|
|
static const bool Valid =
|
|
|
|
boost::is_base_of<vtkm::detail::ListRoot,ListTag>::value;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // 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.)
|
|
|
|
///
|
|
|
|
#define VTKM_IS_LIST_TAG(tag) \
|
2015-09-17 19:45:35 +00:00
|
|
|
VTKM_STATIC_ASSERT_MSG( \
|
2015-12-15 17:29:53 +00:00
|
|
|
(::vtkm::internal::ListTagCheck<tag>::Valid), \
|
2015-09-17 19:45:35 +00:00
|
|
|
"Provided type is not a valid VTK-m list tag.")
|
2014-10-22 13:24:04 +00:00
|
|
|
|
2014-10-22 16:35:56 +00:00
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
template<typename ListTag1, typename ListTag2>
|
|
|
|
struct ListJoin { };
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
2014-05-14 21:05:38 +00:00
|
|
|
/// A special tag for an empty list.
|
|
|
|
///
|
2014-10-22 13:24:04 +00:00
|
|
|
struct ListTagEmpty : detail::ListRoot {
|
2014-10-08 18:53:01 +00:00
|
|
|
typedef detail::ListBase<void()> List;
|
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.
|
|
|
|
template<typename ListTag1, typename ListTag2>
|
2014-10-22 13:24:04 +00:00
|
|
|
struct ListTagJoin : detail::ListRoot {
|
2014-03-31 21:28:09 +00:00
|
|
|
typedef detail::ListJoin<ListTag1, ListTag2> List;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Functor, typename ListTag>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void ListForEach(Functor &f, ListTag);
|
|
|
|
|
|
|
|
template<typename Functor, typename ListTag>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void ListForEach(const Functor &f, ListTag);
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
template<typename Functor, typename ListTag1, typename ListTag2>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void ListForEachImpl(Functor &f, ListJoin<ListTag1, ListTag2>)
|
|
|
|
{
|
|
|
|
vtkm::ListForEach(f, ListTag1());
|
|
|
|
vtkm::ListForEach(f, ListTag2());
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Functor, typename ListTag1, typename ListTag2>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void ListForEachImpl(const Functor &f, ListJoin<ListTag1, ListTag2>)
|
|
|
|
{
|
|
|
|
vtkm::ListForEach(f, ListTag1());
|
|
|
|
vtkm::ListForEach(f, ListTag2());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
/// For each typename represented by the list tag, call the functor with a
|
|
|
|
/// default instance of that type.
|
|
|
|
///
|
|
|
|
template<typename Functor, typename ListTag>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void ListForEach(Functor &f, ListTag)
|
|
|
|
{
|
2014-10-22 16:35:56 +00:00
|
|
|
VTKM_IS_LIST_TAG(ListTag);
|
2014-03-31 21:28:09 +00:00
|
|
|
detail::ListForEachImpl(f, typename ListTag::List());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// For each typename represented by the list tag, call the functor with a
|
|
|
|
/// default instance of that type.
|
|
|
|
///
|
|
|
|
template<typename Functor, typename ListTag>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void ListForEach(const Functor &f, ListTag)
|
|
|
|
{
|
2014-10-22 16:35:56 +00:00
|
|
|
VTKM_IS_LIST_TAG(ListTag);
|
2014-03-31 21:28:09 +00:00
|
|
|
detail::ListForEachImpl(f, typename ListTag::List());
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
///
|
|
|
|
template<typename ListTag, typename Type>
|
|
|
|
struct ListContains
|
|
|
|
{
|
|
|
|
VTKM_IS_LIST_TAG(ListTag);
|
|
|
|
static const bool value =
|
|
|
|
detail::ListContainsImpl<typename ListTag::List,Type>::value;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
template<typename Type, typename ListTag1, typename ListTag2>
|
|
|
|
struct ListContainsImpl<ListJoin<ListTag1,ListTag2>, Type>
|
|
|
|
{
|
|
|
|
static const bool value = (vtkm::ListContains<ListTag1,Type>::value ||
|
|
|
|
vtkm::ListContains<ListTag2,Type>::value);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
2014-03-31 21:28:09 +00:00
|
|
|
} // namespace vtkm
|
|
|
|
|
|
|
|
#endif //vtk_m_ListTag_h
|