An optional base for classes which need to supply ownership to cycle_member_ptr.
More...
#include <cycle_ptr.h>
|
template<typename > |
class | cycle_member_ptr |
|
template<typename > |
class | cycle_allocator |
|
|
(Note that these are not member functions.)
|
template<typename T , typename Alloc , typename... Args> |
auto | allocate_cycle (Alloc alloc, Args &&... args) -> cycle_gptr< T > |
| Allocate a new instance of T , using the specificied allocator. More...
|
|
template<typename T , typename... Args> |
auto | make_cycle (Args &&... args) -> cycle_gptr< T > |
| Allocate a new instance of T , using the default allocator. More...
|
|
An optional base for classes which need to supply ownership to cycle_member_ptr.
The cycle_base keeps track of the control block of the object participating in the cycle_ptr graph, as well as providing a shared from this utility.
You are not required to inherit from cycle_base, for the cycle_ptr graph to function correctly.
◆ cycle_base() [1/3]
cycle_ptr::cycle_base::cycle_base |
( |
| ) |
|
|
inlineprotected |
Default constructor acquires its control block from context.
Uses publisher logic to look up the control block for its range. Those ranges are published by cycle_allocator, make_cycle, and allocate_cycle.
- Exceptions
-
std::runtime_error | if no range was published. |
◆ cycle_base() [2/3]
cycle_ptr::cycle_base::cycle_base |
( |
[[maybe_unused] ] unowned_cycle_t |
unowned_tag | ) |
|
|
inlineprotected |
Specialized constructor that signifies *this
will not be pointed at by a cycle_ptr.
- Exceptions
-
std::bad_alloc | If there is not enough memory to create the required control block. |
◆ cycle_base() [3/3]
cycle_ptr::cycle_base::cycle_base |
( |
const cycle_base & |
| ) |
|
|
inlineprotectednoexcept |
Copy constructor.
Provided so that you don't lose the default copy constructor semantics, but keep in mind that this constructor simply invokes the default constructor.
- Note
- A copy has a different, automatically deduced, control block.
- Exceptions
-
std::runtime_error | if no range was published. |
◆ operator=()
Copy assignment.
A noop, provided so you don't lose default assignment in derived classes.
◆ shared_from_this()
template<typename T >
auto cycle_ptr::cycle_base::shared_from_this |
( |
T * |
this_ptr | ) |
const -> cycle_gptr<T> |
|
inlineprotected |
Create a cycle_gptr (equivalent of std::shared_ptr) from this.
The returned smart pointer uses the control block of this.
Instead of using this->shared_from_this(this)
, you could use this to create pointers directly from member variables, by invocing this->shared_from_this(&this->member_variable)
.
- Exceptions
-
std::bad_weak_ptr | If the smart pointer can not be created. This occurs when invoked during constructor of derived type, or during its destruction. Note that if unowned_cycle is used to construct the base, this method will always throw std::bad_weak_ptr . |
◆ allocate_cycle()
template<typename T , typename Alloc , typename... Args>
auto allocate_cycle |
( |
Alloc |
alloc, |
|
|
Args &&... |
args |
|
) |
| -> cycle_gptr<T> |
|
related |
Allocate a new instance of T
, using the specificied allocator.
Ensures the type T
is instantiated correctly, with its control block.
- Template Parameters
-
T | The type of object to instantiate. |
- Parameters
-
alloc | The allocator to use for allocating the control block. |
args | The arguments passed to the constructor of type T . |
- Returns
- A cycle_gptr to the new instance of
T
.
- Exceptions
-
std::bad_alloc | if allocating a generation fails. |
◆ make_cycle()
template<typename T , typename... Args>
auto make_cycle |
( |
Args &&... |
args | ) |
-> cycle_gptr<T> |
|
related |
Allocate a new instance of T
, using the default allocator.
Ensures the type T
is instantiated correctly, with its control block.
Equivalent to calling allocate_cycle<T>(std::allocator<T>(), args...)
.
- Template Parameters
-
T | The type of object to instantiate. |
- Parameters
-
args | The arguments passed to the constructor of type T . |
- Returns
- A cycle_gptr to the new instance of
T
.
- Exceptions
-
std::bad_alloc | if allocating a generation fails. |
The documentation for this class was generated from the following file: