An owned, shareable message value. More...
#include <xronos/sdk/value.hh>
Public Member Functions | |
| constexpr | Value () noexcept=default |
| Constructs an empty Value that holds nothing. | |
| Value (const T &value) | |
Constructs a Value holding a copy of value. | |
| Value (const ValueView< T > &view) | |
| Constructs a Value from a ValueView, retaining the viewed value. | |
| Value (T &&value) | |
Constructs a Value holding a value move-constructed from value. | |
| auto | as_shared_ptr () const -> std::shared_ptr< const T > |
| Retrieve the held value as a std::shared_ptr. | |
| auto | get () const noexcept -> const T * |
| Retrieve a pointer to the held value, or nullptr if this Value is empty. | |
| operator bool () const noexcept | |
| Check whether this Value holds a value. | |
| auto | operator* () const noexcept -> const T & |
| Access the held value. | |
| auto | operator-> () const noexcept -> const T * |
| Access members of the held value. | |
Static Public Member Functions | |
| static auto | from_shared_ptr (std::shared_ptr< const T > pointer) -> Value |
| Constructs a Value that shares ownership of an externally managed value instead of copying it. | |
| template<class Deleter> | |
| static auto | from_unique_ptr (std::unique_ptr< T, Deleter > pointer) -> Value |
| Constructs a Value that takes over exclusive ownership of an externally allocated value, without copying it. | |
| template<class... Args> | |
| static auto | make (Args &&... args) -> Value |
Constructs a Value holding a value constructed in place from args. | |
Friends | |
| auto | operator== (const Value &value, std::nullptr_t) noexcept -> bool |
| Check whether this Value is empty (value == nullptr is equivalent to !value). | |
An owned, shareable message value.
The held value remains valid for as long as the Value object itself (or any copy of it) is alive. Copying a Value is cheap: values are immutable while shared, so copies share the underlying storage instead of duplicating it.
Use a Value to keep a value received in a reaction beyond the reaction's execution (by copying the ValueView returned from Trigger::get() into a Value), to share a value between reactors without copying it, or to send the same value to multiple effects Reaction effect classes. without boxing it again.
A default-constructed Value is empty and holds nothing.
| T | The type of the held value. |
|
explicit |
|
nodiscard |
Retrieve the held value as a std::shared_ptr.
The returned pointer keeps the value alive independently of this Value, which makes it suitable for handing values to another framework (for example, publishing to ROS 2). Note that pointer identity is not necessarily carried through: for payload types in shared storage the returned pointer shares ownership with this Value, while small trivially copyable payloads are stored by value and are copied into a fresh allocation on every call.
|
staticnodiscard |
Constructs a Value that shares ownership of an externally managed value instead of copying it.
Use this to pass values owned by another framework (for example, messages received from a ROS 2 subscription) into the reactor program without copying the payload. The value must not be modified through any other reference for as long as it is shared – the same contract that sharing a std::shared_ptr<const T> implies everywhere else. To hand over exclusive ownership of a value instead, use from_unique_ptr().
A null pointer yields an empty Value.
|
staticnodiscard |
Constructs a Value that takes over exclusive ownership of an externally allocated value, without copying it.
Unlike from_shared_ptr(), no other reference to the value can remain, so no immutability promise from the caller is needed. Custom deleters are preserved and invoked when the last Value sharing the storage is destroyed (for example, the message deleters used by ROS 2 subscriptions taking std::unique_ptr messages).
A null pointer yields an empty Value.
|
nodiscardnoexcept |
|
staticnodiscard |
Constructs a Value holding a value constructed in place from args.
This is analogous to std::make_shared().
|
noexcept |
Access the held value.
The behavior is undefined if this Value is empty (asserted in debug builds).
|
noexcept |
Access members of the held value.
The behavior is undefined if this Value is empty (asserted in debug builds).