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 "../indicator_component.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 = reinterpret_cast<const rerun::RecordingStream*>(user_data);
35 ///
36 /// rerun::TextLogLevel level;
37 /// if (message.verbosity == loguru::Verbosity_FATAL) {
38 /// level = rerun::TextLogLevel::Critical;
39 /// } else if (message.verbosity == loguru::Verbosity_ERROR) {
40 /// level = rerun::TextLogLevel::Error;
41 /// } else if (message.verbosity == loguru::Verbosity_WARNING) {
42 /// level = rerun::TextLogLevel::Warning;
43 /// } else if (message.verbosity == loguru::Verbosity_INFO) {
44 /// level = rerun::TextLogLevel::Info;
45 /// } else if (message.verbosity == loguru::Verbosity_1) {
46 /// level = rerun::TextLogLevel::Debug;
47 /// } else if (message.verbosity == loguru::Verbosity_2) {
48 /// level = rerun::TextLogLevel::Trace;
49 /// } else {
50 /// level = rerun::TextLogLevel(std::to_string(message.verbosity));
51 /// }
52 ///
53 /// rec->log(
54 /// "logs/handler/text_log_integration",
55 /// rerun::TextLog(message.message).with_level(level)
56 /// );
57 /// }
58 ///
59 /// int main() {
60 /// const auto rec = rerun::RecordingStream("rerun_example_text_log_integration");
61 /// rec.spawn().exit_on_failure();
62 ///
63 /// // Log a text entry directly:
64 /// rec.log(
65 /// "logs",
66 /// rerun::TextLog("this entry has loglevel TRACE").with_level(rerun::TextLogLevel::Trace)
67 /// );
68 ///
69 /// loguru::add_callback(
70 /// "rerun",
71 /// loguru_to_rerun,
72 /// const_cast<void*>(reinterpret_cast<const void*>(&rec)),
73 /// loguru::Verbosity_INFO
74 /// );
75 ///
76 /// LOG_F(INFO, "This INFO log got added through the standard logging interface");
77 ///
78 /// loguru::remove_callback("rerun"); // we need to do this before `rec` goes out of scope
79 /// }
80 /// ```
81 struct TextLog {
82 /// The body of the message.
83 std::optional<ComponentBatch> text;
84
85 /// The verbosity level of the message.
86 ///
87 /// This can be used to filter the log messages in the Rerun Viewer.
88 std::optional<ComponentBatch> level;
89
90 /// Optional color to use for the log line in the Rerun Viewer.
91 std::optional<ComponentBatch> color;
92
93 public:
94 static constexpr const char IndicatorComponentName[] = "rerun.components.TextLogIndicator";
95
96 /// Indicator component, used to identify the archetype when converting to a list of components.
98 /// The name of the archetype as used in `ComponentDescriptor`s.
99 static constexpr const char ArchetypeName[] = "rerun.archetypes.TextLog";
100
101 /// `ComponentDescriptor` for the `text` field.
102 static constexpr auto Descriptor_text = ComponentDescriptor(
104 );
105 /// `ComponentDescriptor` for the `level` field.
106 static constexpr auto Descriptor_level = ComponentDescriptor(
107 ArchetypeName, "level",
109 );
110 /// `ComponentDescriptor` for the `color` field.
111 static constexpr auto Descriptor_color = ComponentDescriptor(
113 );
114
115 public:
116 TextLog() = default;
117 TextLog(TextLog&& other) = default;
118 TextLog(const TextLog& other) = default;
119 TextLog& operator=(const TextLog& other) = default;
120 TextLog& operator=(TextLog&& other) = default;
121
122 explicit TextLog(rerun::components::Text _text)
123 : text(ComponentBatch::from_loggable(std::move(_text), Descriptor_text).value_or_throw()
124 ) {}
125
126 /// Update only some specific fields of a `TextLog`.
128 return TextLog();
129 }
130
131 /// Clear all the fields of a `TextLog`.
133
134 /// The body of the message.
136 text = ComponentBatch::from_loggable(_text, Descriptor_text).value_or_throw();
137 return std::move(*this);
138 }
139
140 /// This method makes it possible to pack multiple `text` in a single component batch.
141 ///
142 /// This only makes sense when used in conjunction with `columns`. `with_text` should
143 /// be used when logging a single row's worth of data.
145 text = ComponentBatch::from_loggable(_text, Descriptor_text).value_or_throw();
146 return std::move(*this);
147 }
148
149 /// The verbosity level of the message.
150 ///
151 /// This can be used to filter the log messages in the Rerun Viewer.
153 level = ComponentBatch::from_loggable(_level, Descriptor_level).value_or_throw();
154 return std::move(*this);
155 }
156
157 /// This method makes it possible to pack multiple `level` in a single component batch.
158 ///
159 /// This only makes sense when used in conjunction with `columns`. `with_level` should
160 /// be used when logging a single row's worth of data.
162 level = ComponentBatch::from_loggable(_level, Descriptor_level).value_or_throw();
163 return std::move(*this);
164 }
165
166 /// Optional color to use for the log line in the Rerun Viewer.
168 color = ComponentBatch::from_loggable(_color, Descriptor_color).value_or_throw();
169 return std::move(*this);
170 }
171
172 /// This method makes it possible to pack multiple `color` in a single component batch.
173 ///
174 /// This only makes sense when used in conjunction with `columns`. `with_color` should
175 /// be used when logging a single row's worth of data.
177 color = ComponentBatch::from_loggable(_color, Descriptor_color).value_or_throw();
178 return std::move(*this);
179 }
180
181 /// Partitions the component data into multiple sub-batches.
182 ///
183 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
184 /// instead, via `ComponentBatch::partitioned`.
185 ///
186 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
187 ///
188 /// The specified `lengths` must sum to the total length of the component batch.
190
191 /// Partitions the component data into unit-length sub-batches.
192 ///
193 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
194 /// where `n` is automatically guessed.
196 };
197
198} // namespace rerun::archetypes
199
200namespace rerun {
201 /// \private
202 template <typename T>
203 struct AsComponents;
204
205 /// \private
206 template <>
207 struct AsComponents<archetypes::TextLog> {
208 /// Serialize all set component batches.
209 static Result<Collection<ComponentBatch>> as_batches(const archetypes::TextLog& archetype);
210 };
211} // 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=rerun::Loggable< T >::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:14
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:81
std::optional< ComponentBatch > color
Optional color to use for the log line in the Rerun Viewer.
Definition text_log.hpp:91
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition text_log.hpp:99
static constexpr auto Descriptor_text
ComponentDescriptor for the text field.
Definition text_log.hpp:102
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:161
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:167
static constexpr auto Descriptor_color
ComponentDescriptor for the color field.
Definition text_log.hpp:111
static TextLog update_fields()
Update only some specific fields of a TextLog.
Definition text_log.hpp:127
TextLog with_text(const rerun::components::Text &_text) &&
The body of the message.
Definition text_log.hpp:135
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:152
std::optional< ComponentBatch > level
The verbosity level of the message.
Definition text_log.hpp:88
static constexpr auto Descriptor_level
ComponentDescriptor for the level field.
Definition text_log.hpp:106
std::optional< ComponentBatch > text
The body of the message.
Definition text_log.hpp:83
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:176
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:144
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:18
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:32
Component: The severity level of a text log message.
Definition text_log_level.hpp:26
Component: A string of text, e.g. for labels and text documents.
Definition text.hpp:17