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