2014-02-10 19:53:03 +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 19:53:03 +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_cont_internal_ArrayPortalShrink_h
|
|
|
|
#define vtk_m_cont_internal_ArrayPortalShrink_h
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2016-04-20 21:41:14 +00:00
|
|
|
#include <vtkm/Assert.h>
|
2014-02-10 19:53:03 +00:00
|
|
|
#include <vtkm/Types.h>
|
|
|
|
#include <vtkm/cont/ArrayPortal.h>
|
2014-09-08 20:59:11 +00:00
|
|
|
#include <vtkm/cont/ArrayPortalToIterators.h>
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2014-09-08 20:59:11 +00:00
|
|
|
#include <iterator>
|
|
|
|
|
2014-02-10 19:53:03 +00:00
|
|
|
namespace vtkm {
|
|
|
|
namespace cont {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
/// This ArrayPortal adapter is a utility that allows you to shrink the
|
|
|
|
/// (reported) array size without actually modifying the underlying allocation.
|
|
|
|
///
|
|
|
|
template<class PortalT>
|
|
|
|
class ArrayPortalShrink
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef PortalT DelegatePortalType;
|
|
|
|
|
|
|
|
typedef typename DelegatePortalType::ValueType ValueType;
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT ArrayPortalShrink() : NumberOfValues(0) { }
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT ArrayPortalShrink(const DelegatePortalType &delegatePortal)
|
2014-02-10 19:53:03 +00:00
|
|
|
: DelegatePortal(delegatePortal),
|
|
|
|
NumberOfValues(delegatePortal.GetNumberOfValues())
|
|
|
|
{ }
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT ArrayPortalShrink(const DelegatePortalType &delegatePortal,
|
2014-02-11 21:20:30 +00:00
|
|
|
vtkm::Id numberOfValues)
|
2014-02-10 19:53:03 +00:00
|
|
|
: DelegatePortal(delegatePortal), NumberOfValues(numberOfValues)
|
|
|
|
{
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(numberOfValues <= delegatePortal.GetNumberOfValues());
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Copy constructor for any other ArrayPortalShrink with a delegate type
|
|
|
|
/// that can be copied to this type. This allows us to do any type casting
|
|
|
|
/// the delegates can do (like the non-const to const cast).
|
|
|
|
///
|
|
|
|
template<class OtherDelegateType>
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2014-02-10 19:53:03 +00:00
|
|
|
ArrayPortalShrink(const ArrayPortalShrink<OtherDelegateType> &src)
|
|
|
|
: DelegatePortal(src.GetDelegatePortal()),
|
|
|
|
NumberOfValues(src.GetNumberOfValues())
|
|
|
|
{ }
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2014-02-10 19:53:03 +00:00
|
|
|
vtkm::Id GetNumberOfValues() const { return this->NumberOfValues; }
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2014-02-11 21:20:30 +00:00
|
|
|
ValueType Get(vtkm::Id index) const
|
|
|
|
{
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(index >= 0);
|
|
|
|
VTKM_ASSERT(index < this->GetNumberOfValues());
|
2014-02-10 19:53:03 +00:00
|
|
|
return this->DelegatePortal.Get(index);
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2014-05-19 17:20:02 +00:00
|
|
|
void Set(vtkm::Id index, const ValueType& value) const
|
2014-02-11 21:20:30 +00:00
|
|
|
{
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(index >= 0);
|
|
|
|
VTKM_ASSERT(index < this->GetNumberOfValues());
|
2014-02-10 19:53:03 +00:00
|
|
|
this->DelegatePortal.Set(index, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Special method in this ArrayPortal that allows you to shrink the
|
|
|
|
/// (exposed) array.
|
|
|
|
///
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2014-02-11 21:20:30 +00:00
|
|
|
void Shrink(vtkm::Id numberOfValues)
|
|
|
|
{
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(numberOfValues < this->GetNumberOfValues());
|
2014-02-10 19:53:03 +00:00
|
|
|
this->NumberOfValues = numberOfValues;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get a copy of the delegate portal. Although safe, this is probably only
|
|
|
|
/// useful internally. (It is exposed as public for the templated copy
|
|
|
|
/// constructor.)
|
|
|
|
///
|
|
|
|
DelegatePortalType GetDelegatePortal() const { return this->DelegatePortal; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
DelegatePortalType DelegatePortal;
|
|
|
|
vtkm::Id NumberOfValues;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::cont::internal
|
|
|
|
|
2014-09-08 20:59:11 +00:00
|
|
|
namespace vtkm {
|
|
|
|
namespace cont {
|
|
|
|
|
|
|
|
template<typename DelegatePortalType>
|
|
|
|
class ArrayPortalToIterators<
|
|
|
|
vtkm::cont::internal::ArrayPortalShrink<DelegatePortalType> >
|
|
|
|
{
|
|
|
|
typedef vtkm::cont::internal::ArrayPortalShrink<DelegatePortalType>
|
|
|
|
PortalType;
|
|
|
|
typedef vtkm::cont::ArrayPortalToIterators<DelegatePortalType>
|
|
|
|
DelegateArrayPortalToIterators;
|
|
|
|
|
|
|
|
public:
|
2016-03-31 13:13:54 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2014-09-08 20:59:11 +00:00
|
|
|
ArrayPortalToIterators(const PortalType &portal)
|
|
|
|
: DelegateIterators(portal.GetDelegatePortal()),
|
|
|
|
NumberOfValues(portal.GetNumberOfValues())
|
|
|
|
{ }
|
|
|
|
|
|
|
|
typedef typename DelegateArrayPortalToIterators::IteratorType IteratorType;
|
|
|
|
|
2016-03-31 13:13:54 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2014-09-08 20:59:11 +00:00
|
|
|
IteratorType GetBegin() const {
|
|
|
|
return this->DelegateIterators.GetBegin();
|
|
|
|
}
|
|
|
|
|
2016-03-31 13:13:54 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2014-09-08 20:59:11 +00:00
|
|
|
IteratorType GetEnd() const {
|
|
|
|
IteratorType iterator = this->GetBegin();
|
|
|
|
std::advance(iterator, this->NumberOfValues);
|
|
|
|
return iterator;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
DelegateArrayPortalToIterators DelegateIterators;
|
|
|
|
vtkm::Id NumberOfValues;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
} // namespace vtkm::cont
|
|
|
|
|
2014-06-11 16:43:36 +00:00
|
|
|
#endif //vtk_m_cont_internal_ArrayPortalShrink_h
|