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/build/re_type_definitions/rerun/archetypes/state_change.def.rs".
3
4#pragma once
5
6#include "../archetype_utils.hpp"
7#include "../collection.hpp"
8#include "../component_batch.hpp"
9#include "../component_column.hpp"
10#include "../components/text.hpp"
11#include "../result.hpp"
12
13#include <cstdint>
14#include <optional>
15#include <utility>
16#include <vector>
17
18namespace rerun::archetypes {
19 /// **Archetype**: A state change, representing a transition of an entity into a new state.
20 ///
21 /// Useful for representing discrete state machines, mode transitions, or
22 /// state changes over time. Each logged `archetypes::StateChange` marks a new state
23 /// at the given time. A `null` state resets the state, showing a gap in the state timeline view.
24 ///
25 /// The state timeline view displays these as horizontal colored lanes over time.
26 ///
27 /// ## Example
28 ///
29 /// ### State changes over time
30 /// ![image](https://static.rerun.io/state_change/6654a13e984702b96547750469c368ce6e900c0f/full.png)
31 ///
32 /// ```cpp
33 /// #include <rerun.hpp>
34 ///
35 /// int main(int argc, char* argv[]) {
36 /// const auto rec = rerun::RecordingStream("rerun_example_state_change");
37 /// rec.spawn().exit_on_failure();
38 ///
39 /// rec.set_time_sequence("step", 0);
40 /// rec.log("door", rerun::StateChange().with_state({"open"}));
41 ///
42 /// rec.set_time_sequence("step", 1);
43 /// rec.log("door", rerun::StateChange().with_state({"closed"}));
44 ///
45 /// rec.set_time_sequence("step", 2);
46 /// rec.log("door", rerun::StateChange().with_state({"open"}));
47 /// }
48 /// ```
49 struct StateChange {
50 /// The new state values; each instance gets its own lane in the state timeline view.
51 ///
52 /// A reset ends the previous state and shows a gap in the state timeline view until the
53 /// next state. An empty string, a null array entry, and an empty state array (e.g. from
54 /// clearing the field) all act as resets.
55 ///
56 /// The length of the state array should not change over time.
57 std::optional<ComponentBatch> state;
58
59 public:
60 /// The name of the archetype as used in `ComponentDescriptor`s.
61 static constexpr const char ArchetypeName[] = "rerun.archetypes.StateChange";
62
63 /// `ComponentDescriptor` for the `state` field.
64 static constexpr auto Descriptor_state = ComponentDescriptor(
66 );
67
68 public:
69 StateChange() = default;
70 StateChange(StateChange&& other) = default;
71 StateChange(const StateChange& other) = default;
72 StateChange& operator=(const StateChange& other) = default;
73 StateChange& operator=(StateChange&& other) = default;
74
75 /// Update only some specific fields of a `StateChange`.
77 return StateChange();
78 }
79
80 /// Clear all the fields of a `StateChange`.
82
83 /// The new state values; each instance gets its own lane in the state timeline view.
84 ///
85 /// A reset ends the previous state and shows a gap in the state timeline view until the
86 /// next state. An empty string, a null array entry, and an empty state array (e.g. from
87 /// clearing the field) all act as resets.
88 ///
89 /// The length of the state array should not change over time.
91 state = ComponentBatch::from_loggable(_state, Descriptor_state).value_or_throw();
92 return std::move(*this);
93 }
94
95 /// Partitions the component data into multiple sub-batches.
96 ///
97 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
98 /// instead, via `ComponentBatch::partitioned`.
99 ///
100 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
101 ///
102 /// The specified `lengths` must sum to the total length of the component batch.
104 return detail::partition_batches({&state}, lengths_).value_or_throw();
105 }
106
107 /// Partitions the component data into unit-length sub-batches.
108 ///
109 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
110 /// where `n` is automatically guessed.
112 return detail::partition_batches_of_unit_length({&state}).value_or_throw();
113 }
114 };
115
116} // namespace rerun::archetypes
117
118namespace rerun {
119 /// \private
120 template <typename T>
121 struct AsComponents;
122
123 /// \private
124 template <>
125 struct AsComponents<archetypes::StateChange> {
126 /// Serialize all set component batches.
127 static Result<Collection<ComponentBatch>> as_batches(
128 const archetypes::StateChange& archetype
129 ) {
130 return detail::collect_batches({&archetype.state});
131 }
132 };
133} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:90
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:26
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:49
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.
Definition state_change.hpp:103
static StateChange update_fields()
Update only some specific fields of a StateChange.
Definition state_change.hpp:76
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:90
static constexpr auto Descriptor_state
ComponentDescriptor for the state field.
Definition state_change.hpp:64
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition state_change.hpp:61
std::optional< ComponentBatch > state
The new state values; each instance gets its own lane in the state timeline view.
Definition state_change.hpp:57
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Definition state_change.hpp:111