StorageBasic.hxx 3.57 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 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 11 12
//  Copyright 2014 UT-Battelle, LLC.
//  Copyright 2014 Los Alamos National Security.
//
13
//  Under the terms of Contract DE-NA0003525 with NTESS,
14 15 16 17 18 19 20
//  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.
//============================================================================

21 22 23 24
#include <vtkm/cont/StorageBasic.h>

#include <limits>

25 26 27 28 29 30 31
namespace vtkm
{
namespace cont
{
namespace internal
{

32

33 34
template <typename T>
Storage<T, vtkm::cont::StorageTagBasic>::Storage()
35
  : StorageBasicBase()
36 37 38
{
}

39 40 41 42 43 44 45 46 47 48 49 50
template <typename T>
Storage<T, vtkm::cont::StorageTagBasic>::Storage(const Storage<T, vtkm::cont::StorageTagBasic>& src)
  : StorageBasicBase(src)
{
}

template <typename T>
Storage<T, vtkm::cont::StorageTagBasic>::Storage(
  Storage<T, vtkm::cont::StorageTagBasic>&& src) noexcept : StorageBasicBase(std::move(src))
{
}

51 52
template <typename T>
Storage<T, vtkm::cont::StorageTagBasic>::Storage(const T* array, vtkm::Id numberOfValues)
53
  : StorageBasicBase(const_cast<T*>(array), numberOfValues, sizeof(T))
54 55 56
{
}

57 58 59 60 61 62 63 64
template <typename T>
Storage<T, vtkm::cont::StorageTagBasic>::Storage(const T* array,
                                                 vtkm::Id numberOfValues,
                                                 void (*deleteFunction)(void*))
  : StorageBasicBase(const_cast<T*>(array), numberOfValues, sizeof(T), deleteFunction)
{
}

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
template <typename T>
Storage<T, vtkm::cont::StorageTagBasic>& Storage<T, vtkm::cont::StorageTagBasic>::Storage::
operator=(const Storage<T, vtkm::cont::StorageTagBasic>& src)
{
  return static_cast<Storage<T, vtkm::cont::StorageTagBasic>&>(StorageBasicBase::operator=(src));
}

template <typename T>
Storage<T, vtkm::cont::StorageTagBasic>& Storage<T, vtkm::cont::StorageTagBasic>::Storage::
operator=(Storage<T, vtkm::cont::StorageTagBasic>&& src)
{
  return static_cast<Storage<T, vtkm::cont::StorageTagBasic>&>(
    StorageBasicBase::operator=(std::move(src)));
}


81
template <typename T>
82
void Storage<T, vtkm::cont::StorageTagBasic>::Allocate(vtkm::Id numberOfValues)
83
{
84
  this->AllocateValues(numberOfValues, sizeof(T));
85 86
}

87
template <typename T>
88 89
typename Storage<T, vtkm::cont::StorageTagBasic>::PortalType
Storage<T, vtkm::cont::StorageTagBasic>::GetPortal()
90
{
91 92
  auto v = static_cast<T*>(this->Array);
  return PortalType(v, v + this->NumberOfValues);
93 94 95
}

template <typename T>
96 97
typename Storage<T, vtkm::cont::StorageTagBasic>::PortalConstType
Storage<T, vtkm::cont::StorageTagBasic>::GetPortalConst() const
98
{
99 100
  auto v = static_cast<T*>(this->Array);
  return PortalConstType(v, v + this->NumberOfValues);
101 102
}

103
template <typename T>
104
T* Storage<T, vtkm::cont::StorageTagBasic>::GetArray()
105
{
106
  return static_cast<T*>(this->Array);
107 108 109
}

template <typename T>
110
const T* Storage<T, vtkm::cont::StorageTagBasic>::GetArray() const
111
{
112
  return static_cast<T*>(this->Array);
113 114
}

115
template <typename T>
116 117
T* Storage<T, vtkm::cont::StorageTagBasic>::StealArray()
{
118
  this->DeleteFunction = nullptr;
119
  return static_cast<T*>(this->Array);
120 121 122 123 124
}

} // namespace internal
}
} // namespace vtkm::cont