xronos-sdk 0.2.0
Xronos C++ SDK
 
Loading...
Searching...
No Matches
value_ptr.hh File Reference

Smart pointers used by the runtime to protect memory safety and determinism. More...

#include "xronos/runtime/value_ptr.hh"

Typedefs

template<class T>
using xronos::sdk::MutableValuePtr = runtime::MutableValuePtr<T>
 Smart pointer to a mutable value.
 
template<class T>
using xronos::sdk::ImmutableValuePtr = runtime::ImmutableValuePtr<T>
 Smart pointer to an immutable value.
 

Functions

template<class T, class... Args>
auto xronos::sdk::make_mutable_value (Args &&... args) -> MutableValuePtr< T >
 Create an instance of MutableValuePtr.
 
template<class T, class... Args>
auto xronos::sdk::make_immutable_value (Args &&... args) -> ImmutableValuePtr< T >
 Create an instance of ImmutableValuePtr.
 

Detailed Description

Smart pointers used by the runtime to protect memory safety and determinism.

Typedef Documentation

◆ MutableValuePtr

template<class T>
using xronos::sdk::MutableValuePtr = runtime::MutableValuePtr<T>

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
TType of the value managed by this class.

◆ ImmutableValuePtr

template<class T>
using xronos::sdk::ImmutableValuePtr = runtime::ImmutableValuePtr<T>

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
TType of the value managed by this class.

Function Documentation

◆ 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
Ttype of the value to be created
Argstypes of T's constructor arguments. Usually, this does not need to be given explicitly and will be inferred automatically from the given args.
Parameters
argsArguments to be forwarded to T's constructor
Returns
A new mutable value pointer.

◆ make_immutable_value()

template<class T, class... Args>
auto xronos::sdk::make_immutable_value ( Args &&... args) -> ImmutableValuePtr<T>

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
Ttype of the value to be created
Argstypes of T's constructor arguments. Usually, this does not need to be given explicitly and will be inferred automatically from the given args.
Parameters
argsArguments to be forwarded to T's constructor
Returns
A new immutable value pointer.