Rerun C++ SDK
Loading...
Searching...
No Matches
state_change.hpp
1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/store/re_sdk_types/definitions/rerun/archetypes/state_change.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_batch.hpp"
8#include "../component_column.hpp"
9#include "../components/text.hpp"
10#include "../result.hpp"
11
12#include <cstdint>
13#include <optional>
14#include <utility>
15#include <vector>
16
17namespace rerun::archetypes {
18 /// **Archetype**: A state change, representing a transition of an entity into a new state.
19 ///
20 /// Useful for representing discrete state machines, mode transitions, or
21 /// state changes over time. Each logged `archetypes::StateChange` marks a new state
22 /// at the given time. A `null` state is ignored by the state timeline view.
23 ///
24 /// The state timeline view displays these as horizontal colored lanes over time.
25 ///
26 /// ## Example
27 ///
28 /// ### State changes over time
29 /// ![image](https://static.rerun.io/state_change/6654a13e984702b96547750469c368ce6e900c0f/full.png)
30 ///
31 /// ```cpp
32 /// #include <rerun.hpp>
33 ///
34 /// int main(int argc, char* argv[]) {
35 /// const auto rec = rerun::RecordingStream("rerun_example_state_change");
36 /// rec.spawn().exit_on_failure();
37 ///
38 /// rec.set_time_sequence("step", 0);
39 /// rec.log("door", rerun::StateChange().with_state("open"));
40 ///
41 /// rec.set_time_sequence("step", 1);
42 /// rec.log("door", rerun::StateChange().with_state("closed"));
43 ///
44 /// rec.set_time_sequence("step", 2);
45 /// rec.log("door", rerun::StateChange().with_state("open"));
46 /// }
47 /// ```
48 ///
49 /// ⚠ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
50 ///
51 struct StateChange {
52 /// The new state value.
53 ///
54 /// A `null` state is ignored, it can be used to partially update a multi-instance state array.
55 /// An empty string is treated as state reset, and a gap is shown in the state timeline view.
56 std::optional<ComponentBatch> state;
57
58 public:
59 /// The name of the archetype as used in `ComponentDescriptor`s.
60 static constexpr const char ArchetypeName[] = "rerun.archetypes.StateChange";
61
62 /// `ComponentDescriptor` for the `state` field.
63 static constexpr auto Descriptor_state = ComponentDescriptor(
65 );
66
67 public:
68 StateChange() = default;
69 StateChange(StateChange&& other) = default;
70 StateChange(const StateChange& other) = default;
71 StateChange& operator=(const StateChange& other) = default;
72 StateChange& operator=(StateChange&& other) = default;
73
74 /// Update only some specific fields of a `StateChange`.
76 return StateChange();
77 }
78
79 /// Clear all the fields of a `StateChange`.
81
82 /// The new state value.
83 ///
84 /// A `null` state is ignored, it can be used to partially update a multi-instance state array.
85 /// An empty string is treated as state reset, and a gap is shown in the state timeline view.
87 state = ComponentBatch::from_loggable(_state, Descriptor_state).value_or_throw();
88 return std::move(*this);
89 }
90
91 /// This method makes it possible to pack multiple `state` in a single component batch.
92 ///
93 /// This only makes sense when used in conjunction with `columns`. `with_state` should
94 /// be used when logging a single row's worth of data.
96 state = ComponentBatch::from_loggable(_state, Descriptor_state).value_or_throw();
97 return std::move(*this);
98 }
99
100 /// Partitions the component data into multiple sub-batches.
101 ///
102 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
103 /// instead, via `ComponentBatch::partitioned`.
104 ///
105 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
106 ///
107 /// The specified `lengths` must sum to the total length of the component batch.
109
110 /// Partitions the component data into unit-length sub-batches.
111 ///
112 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
113 /// where `n` is automatically guessed.
115 };
116
117} // namespace rerun::archetypes
118
119namespace rerun {
120 /// \private
121 template <typename T>
122 struct AsComponents;
123
124 /// \private
125 template <>
126 struct AsComponents<archetypes::StateChange> {
127 /// Serialize all set component batches.
128 static Result<Collection<ComponentBatch>> as_batches(
129 const archetypes::StateChange& archetype
130 );
131 };
132} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
A class for representing either a usable value, or an error.
Definition result.hpp:14
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:87
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
static Result< ComponentBatch > from_loggable(const rerun::Collection< T > &components, const ComponentDescriptor &descriptor)
Creates a new component batch from a collection of component instances.
Definition component_batch.hpp:46
A ComponentDescriptor fully describes the semantics of a column of data.
Definition component_descriptor.hpp:16
The Loggable trait is used by all built-in implementation of rerun::AsComponents to serialize a colle...
Definition loggable.hpp:11
Archetype: A state change, representing a transition of an entity into a new state.
Definition state_change.hpp:51
static StateChange clear_fields()
Clear all the fields of a StateChange.
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
StateChange with_state(const rerun::components::Text &_state) &&
The new state value.
Definition state_change.hpp:86
static StateChange update_fields()
Update only some specific fields of a StateChange.
Definition state_change.hpp:75
StateChange with_many_state(const Collection< rerun::components::Text > &_state) &&
This method makes it possible to pack multiple state in a single component batch.
Definition state_change.hpp:95
static constexpr auto Descriptor_state
ComponentDescriptor for the state field.
Definition state_change.hpp:63
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition state_change.hpp:60
std::optional< ComponentBatch > state
The new state value.
Definition state_change.hpp:56
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Component: A string of text, e.g. for labels and text documents.
Definition text.hpp:16