Bifrost SDK
Bifrost SDK documentation
Owner.h
Go to the documentation of this file.
1//-
2// ================================================================================================
3// Copyright 2025 Autodesk, Inc. All rights reserved.
4//
5// Use of this software is subject to the terms of the Autodesk license agreement provided
6// at the time of installation or download, or which otherwise accompanies this software in
7// either electronic or hard copy form.
8// ================================================================================================
9//+
10
16
17#ifndef BIFROSTGRAPH_EXECUTOR_OWNER_H
18#define BIFROSTGRAPH_EXECUTOR_OWNER_H
19
20#include <BifrostGraph/Executor/internal/OwnerRep.h>
21#include <BifrostGraph/Executor/internal/PointeeTraits.h>
22
23#include <type_traits>
24#include <utility>
25
26namespace BifrostGraph {
27namespace Executor {
28
30
37template <typename T>
38class Owner : private Internal::OwnerRep<T> {
39private:
44 template <typename P>
45 using if_convertible_from =
46 typename std::enable_if<std::is_convertible<P*, T*>::value>::type;
47
52 template <typename P>
53 using if_compliant_and_convertible_from =
54 typename std::enable_if<std::is_convertible<P*, T*>::value &&
55 Internal::PointeeTraits::is_compliant<P>::value>::type;
56
58 using OwnerRep = Internal::OwnerRep<T>;
59
60public:
61 // Requirements
62 static_assert(Internal::PointeeTraits::is_compliant<T>::value,
63 "Owner class template requires an object type T, "
64 "and T cannot be a pointer or a reference or an array (e.g. int[]), "
65 "and T must not include `const` nor `volatile` qualifiers.");
66
68 Owner() noexcept : OwnerRep() {}
69
86 template <typename P, typename = if_compliant_and_convertible_from<P>>
87 Owner(P* p) noexcept {
88 OwnerRep::template init<P>(p);
89 }
90
95 template <typename P>
96 using DeleterFunc = void (*)(P* p);
97
119 template <typename P, typename = if_compliant_and_convertible_from<P>>
120 Owner(P* p, DeleterFunc<P> d) noexcept {
121 OwnerRep::template init<P>(p, d);
122 }
123
128 ~Owner() noexcept = default;
129
134 Owner(Owner&& rhs) noexcept = default;
135
142 template <typename P, typename = if_convertible_from<P>>
143 Owner(Owner<P>&& rhs) noexcept : OwnerRep(std::move(rhs)) {}
144
151 Owner& operator=(Owner&& rhs) noexcept = default;
152
155 explicit constexpr operator bool() const noexcept { return OwnerRep::operator bool(); }
156
160 const T& operator*() const noexcept { return OwnerRep::operator*(); }
161
165 T& operator*() noexcept { return OwnerRep::operator*(); }
166
170 const T* operator->() const noexcept { return OwnerRep::operator->(); }
171
175 T* operator->() noexcept { return OwnerRep::operator->(); }
176
179 const T* get() const noexcept { return OwnerRep::get(); }
180
183 T* get() noexcept { return OwnerRep::get(); }
184
189 Owner& reset() noexcept {
190 OwnerRep::reset();
191 return *this;
192 }
193
198 void swap(Owner& other) noexcept { OwnerRep::swap(other); }
199
200private:
203 Owner(const Owner&) = delete;
204 Owner& operator=(const Owner&) = delete;
206
208 template <class P>
209 friend class Owner;
210};
211
212} // namespace Executor
213} // namespace BifrostGraph
214
215#endif // BIFROSTGRAPH_EXECUTOR_OWNER_H
void swap(Any &lhs, Any &rhs) noexcept
Swap the payloads of two instances of Any.
Definition: Any.h:358
Definition: Ptr.h:2080
The Owner<T> class template represents ownership of an object pointer. It indicates that the pointed ...
Definition: Owner.h:38
Owner & operator=(Owner &&rhs) noexcept=default
Move assignment operator Move assign the Owner rhs to *this.
Owner(P *p, DeleterFunc< P > d) noexcept
Construct an Owner that owns the object pointed by p, with a custom pointer deleter set to d....
Definition: Owner.h:120
T & operator*() noexcept
Indirection operator.
Definition: Owner.h:165
friend class Owner
Friendship to allow conversion between Owners of different types.
Definition: Owner.h:209
Owner & reset() noexcept
Reset this Owner object to its uninitialized state, deleting the currently owned object (if any).
Definition: Owner.h:189
T * operator->() noexcept
Indirection operator.
Definition: Owner.h:175
Owner() noexcept
Construct an empty Owner.
Definition: Owner.h:68
void swap(Owner &other) noexcept
Swap the content of this Owner with another one.
Definition: Owner.h:198
Owner(P *p) noexcept
Construct an Owner that owns the object pointed by p. The owned object will be destructed using the e...
Definition: Owner.h:87
void(*)(P *p) DeleterFunc
The signature for the custom pointer deleter of a pointee p. This is the custom deleter type to use w...
Definition: Owner.h:96
const T & operator*() const noexcept
Indirection operator.
Definition: Owner.h:160
T * get() noexcept
Accessor.
Definition: Owner.h:183
~Owner() noexcept=default
Destruct this Owner. If no custom deleter was provided, the owned object is disposed using a delete p...
const T * operator->() const noexcept
Indirection operator.
Definition: Owner.h:170
const T * get() const noexcept
Accessor.
Definition: Owner.h:179