Rerun C++ SDK
Loading...
Searching...
No Matches
text_log.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/text_log.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/color.hpp"
11#include "../components/text.hpp"
12#include "../components/text_log_level.hpp"
13#include "../result.hpp"
14
15#include <cstdint>
16#include <optional>
17#include <utility>
18#include <vector>
19
20namespace rerun::archetypes {
21 /// **Archetype**: A log entry in a text log, comprised of a text body and its log level.
22 ///
23 /// ## Example
24 ///
25 /// ### text_log_integration:
26 /// ![image](https://static.rerun.io/text_log_integration/9737d0c986325802a9885499d6fcc773b1736488/full.png)
27 ///
28 /// ```cpp
29 /// #include <loguru.hpp>
30 /// #include <rerun.hpp>
31 ///
32 /// void loguru_to_rerun(void* user_data, const loguru::Message& message) {
33 /// // NOTE: `rerun::RecordingStream` is thread-safe.
34 /// const rerun::RecordingStream* rec =
35 /// reinterpret_cast<const rerun::RecordingStream*>(user_data);
36 ///
37 /// rerun::TextLogLevel level;
38 /// if (message.verbosity == loguru::Verbosity_FATAL) {
39 /// level = rerun::TextLogLevel::Critical;
40 /// } else if (message.verbosity == loguru::Verbosity_ERROR) {
41 /// level = rerun::TextLogLevel::Error;
42 /// } else if (message.verbosity == loguru::Verbosity_WARNING) {
43 /// level = rerun::TextLogLevel::Warning;
44 /// } else if (message.verbosity == loguru::Verbosity_INFO) {
45 /// level = rerun::TextLogLevel::Info;
46 /// } else if (message.verbosity == loguru::Verbosity_1) {
47 /// level = rerun::TextLogLevel::Debug;
48 /// } else if (message.verbosity == loguru::Verbosity_2) {
49 /// level = rerun::TextLogLevel::Trace;
50 /// } else {
51 /// level = rerun::TextLogLevel(std::to_string(message.verbosity));
52 /// }
53 ///
54 /// rec->log(
55 /// "logs/handler/text_log_integration",
56 /// rerun::TextLog(message.message).with_level(level)
57 /// );
58 /// }
59 ///
60 /// int main(int argc, char* argv[]) {
61 /// const auto rec =
62 /// rerun::RecordingStream("rerun_example_text_log_integration");
63 /// rec.spawn().exit_on_failure();
64 ///
65 /// // Log a text entry directly:
66 /// rec.log(
67 /// "logs",
68 /// rerun::TextLog("this entry has loglevel TRACE")
69 /// .with_level(rerun::TextLogLevel::Trace)
70 /// );
71 ///
72 /// loguru::add_callback(
73 /// "rerun",
74 /// loguru_to_rerun,
75 /// const_cast<void*>(reinterpret_cast<const void*>(&rec)),
76 /// loguru::Verbosity_INFO
77 /// );
78 ///
79 /// LOG_F(
80 /// INFO,
81 /// "This INFO log got added through the standard logging interface"
82 /// );
83 ///
84 /// // we need to do this before `rec` goes out of scope:
85 /// loguru::remove_callback("rerun");
86 /// }
87 /// ```
88 struct TextLog {
89 /// The body of the message.
90 std::optional<ComponentBatch> text;
91
92 /// The verbosity level of the message.
93 ///
94 /// This can be used to filter the log messages in the Rerun Viewer.
95 std::optional<ComponentBatch> level;
96
97 /// Optional color to use for the log line in the Rerun Viewer.
98 std::optional<ComponentBatch> color;
99
100 public:
101 /// The name of the archetype as used in `ComponentDescriptor`s.
102 static constexpr const char ArchetypeName[] = "rerun.archetypes.TextLog";
103
104 /// `ComponentDescriptor` for the `text` field.
105 static constexpr auto Descriptor_text = ComponentDescriptor(
107 );
108 /// `ComponentDescriptor` for the `level` field.
109 static constexpr auto Descriptor_level = ComponentDescriptor(
111 );
112 /// `ComponentDescriptor` for the `color` field.
113 static constexpr auto Descriptor_color = ComponentDescriptor(
115 );
116
117 public:
118 TextLog() = default;
119 TextLog(TextLog&& other) = default;
120 TextLog(const TextLog& other) = default;
121 TextLog& operator=(const TextLog& other) = default;
122 TextLog& operator=(TextLog&& other) = default;
123
124 explicit TextLog(rerun::components::Text _text)
125 : text(ComponentBatch::from_loggable(std::move(_text), Descriptor_text).value_or_throw()
126 ) {}
127
128 /// Update only some specific fields of a `TextLog`.
130 return TextLog();
131 }
132
133 /// Clear all the fields of a `TextLog`.
135
136 /// The body of the message.
138 text = ComponentBatch::from_loggable(_text, Descriptor_text).value_or_throw();
139 return std::move(*this);
140 }
141
142 /// This method makes it possible to pack multiple `text` in a single component batch.
143 ///
144 /// This only makes sense when used in conjunction with `columns`. `with_text` should
145 /// be used when logging a single row's worth of data.
147 text = ComponentBatch::from_loggable(_text, Descriptor_text).value_or_throw();
148 return std::move(*this);
149 }
150
151 /// The verbosity level of the message.
152 ///
153 /// This can be used to filter the log messages in the Rerun Viewer.
155 level = ComponentBatch::from_loggable(_level, Descriptor_level).value_or_throw();
156 return std::move(*this);
157 }
158
159 /// This method makes it possible to pack multiple `level` in a single component batch.
160 ///
161 /// This only makes sense when used in conjunction with `columns`. `with_level` should
162 /// be used when logging a single row's worth of data.
164 level = ComponentBatch::from_loggable(_level, Descriptor_level).value_or_throw();
165 return std::move(*this);
166 }
167
168 /// Optional color to use for the log line in the Rerun Viewer.
170 color = ComponentBatch::from_loggable(_color, Descriptor_color).value_or_throw();
171 return std::move(*this);
172 }
173
174 /// This method makes it possible to pack multiple `color` in a single component batch.
175 ///
176 /// This only makes sense when used in conjunction with `columns`. `with_color` should
177 /// be used when logging a single row's worth of data.
179 color = ComponentBatch::from_loggable(_color, Descriptor_color).value_or_throw();
180 return std::move(*this);
181 }
182
183 /// Partitions the component data into multiple sub-batches.
184 ///
185 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
186 /// instead, via `ComponentBatch::partitioned`.
187 ///
188 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
189 ///
190 /// The specified `lengths` must sum to the total length of the component batch.
192 return detail::partition_batches({&text, &level, &color}, lengths_).value_or_throw();
193 }
194
195 /// Partitions the component data into unit-length sub-batches.
196 ///
197 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
198 /// where `n` is automatically guessed.
200 return detail::partition_batches_of_unit_length({&text, &level, &color})
201 .value_or_throw();
202 }
203 };
204
205} // namespace rerun::archetypes
206
207namespace rerun {
208 /// \private
209 template <typename T>
210 struct AsComponents;
211
212 /// \private
213 template <>
214 struct AsComponents<archetypes::TextLog> {
215 /// Serialize all set component batches.
216 static Result<Collection<ComponentBatch>> as_batches(const archetypes::TextLog& archetype) {
217 return detail::collect_batches({&archetype.text, &archetype.level, &archetype.color});
218 }
219 };
220} // 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
Arrow-encoded data of a single batch of components together with a component descriptor.
Definition component_batch.hpp:28
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 log entry in a text log, comprised of a text body and its log level.
Definition text_log.hpp:88
std::optional< ComponentBatch > color
Optional color to use for the log line in the Rerun Viewer.
Definition text_log.hpp:98
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition text_log.hpp:102
static constexpr auto Descriptor_text
ComponentDescriptor for the text field.
Definition text_log.hpp:105
TextLog with_many_level(const Collection< rerun::components::TextLogLevel > &_level) &&
This method makes it possible to pack multiple level in a single component batch.
Definition text_log.hpp:163
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Definition text_log.hpp:191
TextLog with_color(const rerun::components::Color &_color) &&
Optional color to use for the log line in the Rerun Viewer.
Definition text_log.hpp:169
static constexpr auto Descriptor_color
ComponentDescriptor for the color field.
Definition text_log.hpp:113
static TextLog update_fields()
Update only some specific fields of a TextLog.
Definition text_log.hpp:129
TextLog with_text(const rerun::components::Text &_text) &&
The body of the message.
Definition text_log.hpp:137
static TextLog clear_fields()
Clear all the fields of a TextLog.
TextLog with_level(const rerun::components::TextLogLevel &_level) &&
The verbosity level of the message.
Definition text_log.hpp:154
std::optional< ComponentBatch > level
The verbosity level of the message.
Definition text_log.hpp:95
static constexpr auto Descriptor_level
ComponentDescriptor for the level field.
Definition text_log.hpp:109
std::optional< ComponentBatch > text
The body of the message.
Definition text_log.hpp:90
TextLog with_many_color(const Collection< rerun::components::Color > &_color) &&
This method makes it possible to pack multiple color in a single component batch.
Definition text_log.hpp:178
TextLog with_many_text(const Collection< rerun::components::Text > &_text) &&
This method makes it possible to pack multiple text in a single component batch.
Definition text_log.hpp:146
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Definition text_log.hpp:199
Component: An RGBA color with unmultiplied/separate alpha, in sRGB gamma space with linear alpha.
Definition color.hpp:17
Component: The severity level of a text log message.
Definition text_log_level.hpp:25
Component: A string of text, e.g. for labels and text documents.
Definition text.hpp:16