2014-09-04 17:56:15 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2014-09-04 17:56:15 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtk_m_cont_ArrayPortalToIterators_h
|
|
|
|
#define vtk_m_cont_ArrayPortalToIterators_h
|
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayPortal.h>
|
|
|
|
#include <vtkm/cont/internal/IteratorFromArrayPortal.h>
|
|
|
|
|
2020-01-27 23:02:13 +00:00
|
|
|
#include <vtkm/internal/ArrayPortalHelpers.h>
|
|
|
|
|
2020-02-25 23:45:03 +00:00
|
|
|
#include <vtkmstd/void_t.h>
|
2019-12-13 19:19:27 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
2014-09-04 17:56:15 +00:00
|
|
|
|
2020-01-27 23:02:13 +00:00
|
|
|
template <typename PortalType,
|
|
|
|
typename CustomIterators = vtkm::internal::PortalSupportsIterators<PortalType>>
|
|
|
|
class ArrayPortalToIterators;
|
|
|
|
|
2014-09-04 17:56:15 +00:00
|
|
|
/// \brief Convert an \c ArrayPortal to STL iterators.
|
|
|
|
///
|
|
|
|
/// \c ArrayPortalToIterators is a class that holds an \c ArrayPortal and
|
|
|
|
/// builds iterators that access the data in the \c ArrayPortal. The point of
|
|
|
|
/// this class is to use an \c ArrayPortal with generic functions that expect
|
|
|
|
/// STL iterators such as STL algorithms or Thrust operations.
|
|
|
|
///
|
|
|
|
/// The default template implementation constructs iterators that provide
|
2020-01-27 23:02:13 +00:00
|
|
|
/// values through the \c ArrayPortal itself. However, if the \c ArrayPortal
|
|
|
|
/// contains its own iterators (by defining \c GetIteratorBegin and
|
|
|
|
/// \c GetIteratorEnd), then those iterators are used.
|
2014-09-04 17:56:15 +00:00
|
|
|
///
|
2020-01-27 23:02:13 +00:00
|
|
|
template <typename PortalType>
|
|
|
|
class ArrayPortalToIterators<PortalType, std::false_type>
|
2014-09-04 17:56:15 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// \c ArrayPortaltoIterators should be constructed with an instance of
|
|
|
|
/// the array portal.
|
|
|
|
///
|
2016-03-31 13:13:54 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2019-12-13 19:19:27 +00:00
|
|
|
explicit ArrayPortalToIterators(const PortalType& portal)
|
2017-05-18 14:29:41 +00:00
|
|
|
: Portal(portal)
|
|
|
|
{
|
|
|
|
}
|
2014-09-04 17:56:15 +00:00
|
|
|
|
2020-02-25 18:38:29 +00:00
|
|
|
// These are the same as the default implementation, but explicitly created to prevent warnings
|
|
|
|
// from the CUDA compiler where it tries to compile for the device when the underlying portal
|
|
|
|
// only works for the host.
|
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
|
|
|
ArrayPortalToIterators(const ArrayPortalToIterators& src)
|
|
|
|
: Portal(src.Portal)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
|
|
|
ArrayPortalToIterators(ArrayPortalToIterators&& rhs)
|
|
|
|
: Portal(std::move(rhs.Portal))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
|
|
|
~ArrayPortalToIterators() {}
|
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
|
|
|
ArrayPortalToIterators& operator=(const ArrayPortalToIterators& src)
|
|
|
|
{
|
|
|
|
this->Portal = src.Portal;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
|
|
|
ArrayPortalToIterators& operator=(ArrayPortalToIterators&& rhs)
|
|
|
|
{
|
|
|
|
this->Portal = std::move(rhs.Portal);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-09-04 17:56:15 +00:00
|
|
|
/// The type of the iterator.
|
|
|
|
///
|
2017-06-23 18:50:34 +00:00
|
|
|
using IteratorType = vtkm::cont::internal::IteratorFromArrayPortal<PortalType>;
|
2014-09-04 17:56:15 +00:00
|
|
|
|
|
|
|
/// Returns an iterator pointing to the beginning of the ArrayPortal.
|
|
|
|
///
|
2016-03-31 13:13:54 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
IteratorType GetBegin() const { return vtkm::cont::internal::make_IteratorBegin(this->Portal); }
|
2014-09-04 17:56:15 +00:00
|
|
|
|
|
|
|
/// Returns an iterator pointing to one past the end of the ArrayPortal.
|
|
|
|
///
|
2016-03-31 13:13:54 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
IteratorType GetEnd() const { return vtkm::cont::internal::make_IteratorEnd(this->Portal); }
|
2014-09-04 17:56:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
PortalType Portal;
|
|
|
|
};
|
|
|
|
|
2019-12-13 19:19:27 +00:00
|
|
|
// Specialize for custom iterator types:
|
|
|
|
template <typename PortalType>
|
2020-01-27 23:02:13 +00:00
|
|
|
class ArrayPortalToIterators<PortalType, std::true_type>
|
2019-12-13 19:19:27 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-01-27 23:02:13 +00:00
|
|
|
using IteratorType = decltype(std::declval<PortalType>().GetIteratorBegin());
|
2019-12-13 19:19:27 +00:00
|
|
|
|
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
|
|
|
explicit ArrayPortalToIterators(const PortalType& portal)
|
|
|
|
: Begin(portal.GetIteratorBegin())
|
|
|
|
, End(portal.GetIteratorEnd())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
|
|
|
IteratorType GetBegin() const { return this->Begin; }
|
|
|
|
|
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
|
|
|
IteratorType GetEnd() const { return this->End; }
|
|
|
|
|
2020-02-25 18:38:29 +00:00
|
|
|
// These are the same as the default implementation, but explicitly created to prevent warnings
|
|
|
|
// from the CUDA compiler where it tries to compile for the device when the underlying portal
|
|
|
|
// only works for the host.
|
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
|
|
|
ArrayPortalToIterators(const ArrayPortalToIterators& src)
|
|
|
|
: Begin(src.Begin)
|
|
|
|
, End(src.End)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
|
|
|
ArrayPortalToIterators(ArrayPortalToIterators&& rhs)
|
|
|
|
: Begin(std::move(rhs.Begin))
|
|
|
|
, End(std::move(rhs.End))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
|
|
|
~ArrayPortalToIterators() {}
|
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
|
|
|
ArrayPortalToIterators& operator=(const ArrayPortalToIterators& src)
|
|
|
|
{
|
|
|
|
this->Begin = src.Begin;
|
|
|
|
this->End = src.End;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
|
|
VTKM_EXEC_CONT
|
|
|
|
ArrayPortalToIterators& operator=(ArrayPortalToIterators&& rhs)
|
|
|
|
{
|
|
|
|
this->Begin = std::move(rhs.Begin);
|
|
|
|
this->End = std::move(rhs.End);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-12-13 19:19:27 +00:00
|
|
|
private:
|
|
|
|
IteratorType Begin;
|
|
|
|
IteratorType End;
|
|
|
|
};
|
|
|
|
|
2018-01-30 00:24:31 +00:00
|
|
|
/// Convenience function for converting an ArrayPortal to a begin iterator.
|
2014-09-04 17:56:15 +00:00
|
|
|
///
|
2016-03-31 13:13:54 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename PortalType>
|
|
|
|
VTKM_EXEC_CONT typename vtkm::cont::ArrayPortalToIterators<PortalType>::IteratorType
|
|
|
|
ArrayPortalToIteratorBegin(const PortalType& portal)
|
2014-09-04 17:56:15 +00:00
|
|
|
{
|
|
|
|
vtkm::cont::ArrayPortalToIterators<PortalType> iterators(portal);
|
|
|
|
return iterators.GetBegin();
|
|
|
|
}
|
|
|
|
|
2018-01-30 00:24:31 +00:00
|
|
|
/// Convenience function for converting an ArrayPortal to an end iterator.
|
2014-09-04 17:56:15 +00:00
|
|
|
///
|
2016-03-31 13:13:54 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename PortalType>
|
|
|
|
VTKM_EXEC_CONT typename vtkm::cont::ArrayPortalToIterators<PortalType>::IteratorType
|
|
|
|
ArrayPortalToIteratorEnd(const PortalType& portal)
|
2014-09-04 17:56:15 +00:00
|
|
|
{
|
|
|
|
vtkm::cont::ArrayPortalToIterators<PortalType> iterators(portal);
|
|
|
|
return iterators.GetEnd();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::cont
|
|
|
|
|
|
|
|
#endif //vtk_m_cont_ArrayPortalToIterators_h
|