Smart pointers used by the runtime to protect memory safety and determinism.
More...
#include "xronos/runtime/value_ptr.hh"
Smart pointers used by the runtime to protect memory safety and determinism.
◆ MutableValuePtr
Smart pointer to a mutable value.
Manages the lifetime of a value in conjunction with ImmutableValuePtr
. Implements ownership semantics and enforces unique ownership of a mutable value. MutableValuePtr
internally wraps around unique_ptr
. The unique ownership ensures that no other reactor can reference the value while it is allowed to change. In order to share the associated value, an instance of MutableValuePtr
needs to be converted to an ImmutableValuePtr
, making the associated value immutable.
- Template Parameters
-
T | Type of the value managed by this class. |
◆ ImmutableValuePtr
Smart pointer to an immutable value.
Manages the lifetime of a value in conjunction with MutableValuePtr
. Implements ownership semantics and allows shared ownership of an immutable value. ImmutableValuePtr
internally wraps around shared_ptr
. The shared ownership semantics enables multiple reactors to share a value, which is only safe if the value is immutable. In order to modify the associated value, an instance of ImmutableValuePtr
needs to be converted to an MutableValuePtr
, making the associated value mutable. This can be achieved by calling get_mutable_copy()
.
- Template Parameters
-
T | Type of the value managed by this class. |
◆ make_mutable_value()
template<class T, class... Args>
auto xronos::sdk::make_mutable_value |
( |
Args &&... | args | ) |
-> MutableValuePtr<T> |
Create an instance of MutableValuePtr
.
Creates and initializes a new instance of T
and returns a new MutableValuePtr
owning this value. This is analogous to std::make_unique
.
- Template Parameters
-
T | type of the value to be created |
Args | types of T 's constructor arguments. Usually, this does not need to be given explicitly and will be inferred automatically from the given args . |
- Parameters
-
args | Arguments to be forwarded to T 's constructor |
- Returns
- A new mutable value pointer.
◆ make_immutable_value()
template<class T, class... Args>
Create an instance of ImmutableValuePtr
.
Creates and initializes a new instance of T
and returns a new ImmutableValuePtr
owning this value. This is analogous to std::make_shared
.
- Template Parameters
-
T | type of the value to be created |
Args | types of T 's constructor arguments. Usually, this does not need to be given explicitly and will be inferred automatically from the given args . |
- Parameters
-
args | Arguments to be forwarded to T 's constructor |
- Returns
- A new immutable value pointer.