RC
#include <sbio/util/rc.hh>template<typename T, class Allocator = void, class Deleter = void>struct RCDefined in src/lib/sbio/util/rc.hh:124
A simple reference counted container for an object.
The RC class provides shared_ptr like semantics for a wrapped object. It is provided as fully-device-friendly reference counted container which is not necessarily guaranteed if using the STL shared_ptr. If you are positive that your wrapped object will only ever be used from the host, you should use the STL instead!
By default the RC will allocate with new and free with delete. A custom allocator and deleter may be provided as needed for the specific use-case. Generally allocation and freeing will occur on the host-only, although the object may be moved later onto device - this is dependent on the provided allocator and deleter though.
Copies of an RC container lead to increases in the reference count, while moves do not. The moved-from object will be NULL’d.
When a reference count reaches zero, on destruction of the final RC, the wrapped object will be destructed.
Template Parameters
Section titled “Template Parameters”-
TThe type of the wrapped object to be reference counted. -
AllocatorThe type of the custom allocator if provided. -
DeleterThe type of the custom deleter if provided.
List of all members
Section titled “List of all members”| Name | Kind | Owner |
|---|---|---|
RC |
function |
Declared here |
RC |
function |
Declared here |
~RC |
function |
Declared here |
RC |
function |
Declared here |
operator= |
function |
Declared here |
RC |
function |
Declared here |
operator= |
function |
Declared here |
set_count |
function |
Declared here |
inc_reference |
function |
Declared here |
dec_reference |
function |
Declared here |
operator* |
function |
Declared here |
operator* |
function |
Declared here |
operator& |
function |
Declared here |
operator& |
function |
Declared here |
make_rc |
function |
Declared here |
make_rc |
function |
Declared here |
make_rc |
function |
Declared here |
make_rc |
function |
Declared here |
m_obj |
variable |
Declared here |
Public Methods
Section titled “Public Methods”| Return | Name | Description |
|---|---|---|
SBIO_HD |
RC |
An RC can be default constructed and filled in (e.g. by a static func.) |
SBIO_HD |
RC inline explicit |
Explicitly construct an RC from a prepared RCObject control struct. |
SBIO_HD |
~RC inline |
Destruct the RC wrapper. |
SBIO_HD |
RC inline |
Copy an RC-wrapped object, incrementing the reference count. |
SBIO_HDRC & |
operator= inline |
Copy an RC-wrapped object, incrementing the reference count. |
SBIO_HD |
RC inline noexcept |
Move an RC-wrapped object without incrementing the reference count. |
SBIO_HDRC & |
operator= inline noexcept |
Move an RC-wrapped object without incrementing the reference count. |
SBIO_HD void |
set_count inline |
Set the wrapped object’s reference count to a specific value. |
SBIO_HD void |
inc_reference inline |
Increment the wrapped object’s reference count. |
SBIO_HD void |
dec_reference inline |
Decrement the wrapped object’s reference count. |
SBIO_HD T & |
operator* inline |
Overloaded dereference operator returns the wrapped object. |
SBIO_HD const T & |
operator* const inline |
Overloaded dereference operator returns the wrapped object. |
SBIO_HD T * |
operator& inline |
Overloaded addressof operator returns a pointer to the wrapped object. |
SBIO_HD const T * |
operator& const inline |
Overloaded addressof operator returns a pointer to the wrapped object. |
SBIO_HD RC() = defaultDefined in src/lib/sbio/util/rc.hh:152
An RC can be default constructed and filled in (e.g. by a static func.)
inline explicit
inline explicit SBIO_HD RC(RCObject * obj)Defined in src/lib/sbio/util/rc.hh:159
Explicitly construct an RC from a prepared RCObject control struct.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
obj |
[RCObject](api-sbio-RC-RCObject.md#rcobject) * |
The control struct with wrapped object and ref count. |
inline
inline SBIO_HD ~RC()Defined in src/lib/sbio/util/rc.hh:171
Destruct the RC wrapper.
If the RC contains an object, it will decrement the reference count to that object. If the count reaches 0, then either the custom deleter will be used on the wrapped object, or if one was not provided, then the standard delete will be called.
inline
inline SBIO_HD RC(const RC & other)Defined in src/lib/sbio/util/rc.hh:196
Copy an RC-wrapped object, incrementing the reference count.
operator=
Section titled “operator=”inline
inline SBIO_HDRC & operator=(const RC & other)Defined in src/lib/sbio/util/rc.hh:210
Copy an RC-wrapped object, incrementing the reference count.
inline noexcept
inline SBIO_HD RC(RC && other) noexceptDefined in src/lib/sbio/util/rc.hh:227
Move an RC-wrapped object without incrementing the reference count.
operator=
Section titled “operator=”inline noexcept
inline SBIO_HDRC & operator=(RC && other) noexceptDefined in src/lib/sbio/util/rc.hh:236
Move an RC-wrapped object without incrementing the reference count.
set_count
Section titled “set_count”inline
inline SBIO_HD void set_count(std::size_t count)Defined in src/lib/sbio/util/rc.hh:254
Set the wrapped object’s reference count to a specific value.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
count |
std::size_t |
The new reference count to use. |
inc_reference
Section titled “inc_reference”inline
inline SBIO_HD void inc_reference()Defined in src/lib/sbio/util/rc.hh:260
Increment the wrapped object’s reference count.
dec_reference
Section titled “dec_reference”inline
inline SBIO_HD void dec_reference()Defined in src/lib/sbio/util/rc.hh:266
Decrement the wrapped object’s reference count.
operator*
Section titled “operator*”inline
inline SBIO_HD T & operator*()Defined in src/lib/sbio/util/rc.hh:275
Overloaded dereference operator returns the wrapped object.
Returns
Section titled “Returns”A reference to the wrapped object.
operator*
Section titled “operator*”const inline
inline SBIO_HD const T & operator*() constDefined in src/lib/sbio/util/rc.hh:281
Overloaded dereference operator returns the wrapped object.
Returns
Section titled “Returns”A const reference to the wrapped object.
operator&
Section titled “operator&”inline
inline SBIO_HD T * operator&()Defined in src/lib/sbio/util/rc.hh:287
Overloaded addressof operator returns a pointer to the wrapped object.
Returns
Section titled “Returns”Pointer to the wrapped object.
operator&
Section titled “operator&”const inline
inline SBIO_HD const T * operator&() constDefined in src/lib/sbio/util/rc.hh:293
Overloaded addressof operator returns a pointer to the wrapped object.
Returns
Section titled “Returns”Const pointer to the wrapped object.
Public Static Methods
Section titled “Public Static Methods”| Return | Name | Description |
|---|---|---|
SBIO_HDRC< T, Allocator, Deleter > |
make_rc static inline |
Create a new RC without custom allocator or deleter. |
SBIO_HDRC< T, Alloc, Deleter > |
make_rc static inline requires RCAllocator<Alloc, T, Args...> |
Create a new RC with a custom allocator but not deleter. |
SBIO_HDRC< T, Allocator, Del > |
make_rc static inline requires RCDeleter<Del, T> |
Create a new RC with a custom deleter but not allocator. |
SBIO_HDRC< T, Alloc, Del > |
make_rc static inline requires RCAllocator<Alloc, T, Args...> && RCDeleter<Del, T> |
Create a new RC with a custom allocator and deleter. |
make_rc
Section titled “make_rc”static inline
template<typename... Args> static inline SBIO_HDRC< T, Allocator, Deleter > make_rc(Args &&... args)Defined in src/lib/sbio/util/rc.hh:303
Create a new RC without custom allocator or deleter.
Returns
Section titled “Returns”A new reference counted RC wrapper.
make_rc
Section titled “make_rc”static inline requires RCAllocator<Alloc, T, Args...>
template<typename Alloc, typename... Args> static inline SBIO_HDRC< T, Alloc, Deleter > make_rc(use_rc_alloc_t, Alloc alloc, Args &&... args) requires RCAllocator<Alloc, T, Args...>Defined in src/lib/sbio/util/rc.hh:324
Create a new RC with a custom allocator but not deleter.
Returns
Section titled “Returns”A new reference counted RC wrapper.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
alloc |
Alloc |
The custom allocator. |
make_rc
Section titled “make_rc”static inline requires RCDeleter<Del, T>
template<typename Del, typename... Args> static inline SBIO_HDRC< T, Allocator, Del > make_rc(use_rc_del_t, Del del, Args &&... args) requires RCDeleter<Del, T>Defined in src/lib/sbio/util/rc.hh:356
Create a new RC with a custom deleter but not allocator.
Returns
Section titled “Returns”A new reference counted RC wrapper.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
del |
Del |
The custom deleter. |
make_rc
Section titled “make_rc”static inline requires RCAllocator<Alloc, T, Args...> && RCDeleter<Del, T>
template<typename Alloc, typename Del, typename... Args> static inline SBIO_HDRC< T, Alloc, Del > make_rc(use_rc_alloc_del_t, Alloc alloc, Del del, Args &&... args) requires RCAllocator<Alloc, T, Args...> && RCDeleter<Del, T>Defined in src/lib/sbio/util/rc.hh:383
Create a new RC with a custom allocator and deleter.
Returns
Section titled “Returns”A new reference counted RC wrapper.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
alloc |
Alloc |
The custom allocator. |
del |
Del |
The custom deleter. |
Private Attributes
Section titled “Private Attributes”| Return | Name | Description |
|---|---|---|
RCObject * |
m_obj |
Wrapped container for the ref count and object. |
RCObject * m_obj { nullptr }Defined in src/lib/sbio/util/rc.hh:407
Wrapped container for the ref count and object.