20 #ifndef OPM_COPYABLE_PTR_HPP 21 #define OPM_COPYABLE_PTR_HPP 24 #include <type_traits> 26 #include <opm/common/utility/gpuDecorators.hpp> 37 template <
class T,
bool on_gpu = OPM_IS_INSIDE_DEVICE_FUNCTION>
40 template <
class U,
bool B>
43 using ptr_type = std::conditional_t<on_gpu, T*, std::unique_ptr<T>>;
48 static_assert(!std::is_polymorphic_v<T>,
49 "CopyablePtr does not support polymorphic types");
54 if constexpr (on_gpu) {
57 ptr_ = other ? std::make_unique<T>(*other.get()) :
nullptr;
62 if constexpr (on_gpu) {
66 ptr_ = std::move(other.ptr_);
73 if constexpr (on_gpu) {
76 ptr_ = other ? std::make_unique<T>(*other.get()) :
nullptr;
85 if constexpr (on_gpu) {
89 ptr_ = std::move(other.ptr_);
110 #if OPM_IS_INSIDE_DEVICE_FUNCTION 111 CopyablePtr& operator=(std::unique_ptr<T>&& uptr) {
112 if constexpr (on_gpu) {
113 ptr_ = uptr.release();
115 ptr_ = std::move(uptr);
123 ptr_ = std::move(uptr);
131 OPM_HOST_DEVICE
bool operator==(
const CopyablePtr& other)
const {
132 const T* lhs = deref_ptr();
133 const T* rhs = other.deref_ptr();
135 if ((lhs ==
nullptr) != (rhs ==
nullptr)) {
139 return (lhs ==
nullptr) || (*lhs == *rhs);
142 OPM_HOST_DEVICE
bool operator!=(
const CopyablePtr& other)
const {
143 return !(*
this == other);
147 template <
class Serializer>
149 if constexpr (!on_gpu) {
155 OPM_HOST_DEVICE T* operator->()
const {
return deref_ptr(); }
158 OPM_HOST_DEVICE
explicit operator bool()
const noexcept {
return deref_ptr() !=
nullptr; }
161 OPM_HOST_DEVICE T*
get()
const {
return deref_ptr(); }
164 OPM_HOST_DEVICE T* release() {
165 if constexpr (on_gpu) {
170 return ptr_.release();
180 explicit OPM_HOST_DEVICE
CopyablePtr(T* ptr) : ptr_(ptr) {}
182 OPM_HOST_DEVICE T* deref_ptr()
const {
183 if constexpr (on_gpu) {
Definition: CopyablePtr.hpp:38
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Class for (de-)serializing.
Definition: Serializer.hpp:95