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 resets the state, showing a gap in 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 struct StateChange {
49 /// The new state values; each instance gets its own lane in the state timeline view.
50 ///
51 /// A reset ends the previous state and shows a gap in the state timeline view until the
52 /// next state. An empty string, a null array entry, and an empty state array (e.g. from
53 /// clearing the field) all act as resets.
54 ///
55 /// The length of the state array should not change over time.
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 values; each instance gets its own lane in the state timeline view.
83 ///
84 /// A reset ends the previous state and shows a gap in the state timeline view until the
85 /// next state. An empty string, a null array entry, and an empty state array (e.g. from
86 /// clearing the field) all act as resets.
87 ///
88 /// The length of the state array should not change over time.
90 state = ComponentBatch::from_loggable(_state, Descriptor_state).value_or_throw();
91 return std::move(*this);
92 }
93
94 /// Partitions the component data into multiple sub-batches.
95 ///
96 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
97 /// instead, via `ComponentBatch::partitioned`.
98 ///
99 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
100 ///
101 /// The specified `lengths` must sum to the total length of the component batch.
103
104 /// Partitions the component data into unit-length sub-batches.
105 ///
106 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
107 /// where `n` is automatically guessed.
109 };
110
111} // namespace rerun::archetypes
112
113namespace rerun {
114 /// \private
115 template <typename T>
116 struct AsComponents;
117
118 /// \private
119 template <>
120 struct AsComponents<archetypes::StateChange> {
121 /// Serialize all set component batches.
122 static Result<Collection<ComponentBatch>> as_batches(
123 const archetypes::StateChange& archetype
124 );
125 };
126} // 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:48
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.
static StateChange update_fields()
Update only some specific fields of a StateChange.
Definition state_change.hpp:75
StateChange with_state(const Collection< rerun::components::Text > &_state) &&
The new state values; each instance gets its own lane in the state timeline view.
Definition state_change.hpp:89
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 values; each instance gets its own lane in the state timeline view.
Definition state_change.hpp:56
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.