A borrowed view of a message value. More...
#include <xronos/sdk/value.hh>
Public Member Functions | |
| constexpr | ValueView () noexcept=default |
| Constructs an absent view that refers to nothing. | |
| auto | as_shared_ptr () const -> std::shared_ptr< const T > |
| Retrieve the viewed value as a std::shared_ptr. | |
| auto | get () const noexcept -> const T * |
| Retrieve a pointer to the viewed value, or nullptr if the view is absent. | |
| operator bool () const noexcept | |
| Check whether the view refers to a value. | |
| auto | operator* () const noexcept -> const T & |
| Access the viewed value. | |
| auto | operator-> () const noexcept -> const T * |
| Access members of the viewed value. | |
Friends | |
| auto | operator== (const ValueView &view, std::nullptr_t) noexcept -> bool |
| Check whether the view is absent (view == nullptr is equivalent to !view). | |
A borrowed view of a message value.
A ValueView does not own the value it refers to: it forwards to a value stored by the runtime, which remains valid for the duration of the current reaction handler. Reading through a view performs no copy.
Views cannot be copied or moved: a view is a scope-bound borrow, and retaining one beyond the reaction handler it was obtained in would leave it dangling. Initializing a local from a fresh view (auto view = input.get();) works – that is guaranteed copy elision, not a copy. To keep the viewed value, copy the view into a Value :
A default-constructed (or absent) view refers to nothing; this is what Trigger::get() returns when no event is present.
| T | The type of the viewed value. |
|
nodiscard |
Retrieve the viewed value as a std::shared_ptr.
Unlike the view itself, the returned pointer keeps the value alive beyond the current reaction handler, which makes it suitable for handing a received value 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 the stored value, while small trivially copyable payloads are stored by value and are copied into a fresh allocation on every call.
|
nodiscardnoexcept |
Retrieve a pointer to the viewed value, or nullptr if the view is absent.
The pointer is only valid for the duration of the current reaction handler.
|
explicitnoexcept |
Check whether the view refers to a value.
For a view returned by a trigger, this indicates whether an event with a value is currently present.
|
noexcept |
Access the viewed value.
The behavior is undefined if the view is absent (asserted in debug builds).
|
noexcept |
Access members of the viewed value.
The behavior is undefined if the view is absent (asserted in debug builds).