Rerun C++ SDK
Loading...
Searching...
No Matches
text_document.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_document.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/media_type.hpp"
11#include "../components/text.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 text element intended to be displayed in its own text box.
21 ///
22 /// Supports raw text and markdown.
23 ///
24 /// ## Example
25 ///
26 /// ### Markdown text document
27 /// ![image](https://static.rerun.io/textdocument/babda19558ee32ed8d730495b595aee7a5e2c174/full.png)
28 ///
29 /// ```cpp
30 /// #include <rerun.hpp>
31 ///
32 /// int main(int argc, char* argv[]) {
33 /// const auto rec = rerun::RecordingStream("rerun_example_text_document");
34 /// rec.spawn().exit_on_failure();
35 ///
36 /// rec.log("text_document", rerun::TextDocument("Hello, TextDocument!"));
37 ///
38 /// rec.log(
39 /// "markdown",
40 /// rerun::TextDocument(R"#(# Hello Markdown!
41 /// [Click here to see the raw text](recording://markdown:Text).
42 ///
43 /// Basic formatting:
44 ///
45 /// | **Feature** | **Alternative** |
46 /// | ----------------- | --------------- |
47 /// | Plain | |
48 /// | *italics* | _italics_ |
49 /// | **bold** | __bold__ |
50 /// | ~~strikethrough~~ | |
51 /// | `inline code` | |
52 ///
53 /// ----------------------------------
54 ///
55 /// ## Support
56 /// - [x] [Commonmark](https://commonmark.org/help/) support
57 /// - [x] GitHub-style strikethrough, tables, and checkboxes
58 /// - Basic syntax highlighting for:
59 /// - [x] C and C++
60 /// - [x] Python
61 /// - [x] Rust
62 /// - [ ] Other languages
63 ///
64 /// ## Links
65 /// You can link to [an entity](recording://markdown),
66 /// a [specific instance of an entity](recording://markdown[#0]),
67 /// or a [specific component](recording://markdown:Text).
68 ///
69 /// Of course you can also have [normal https links](https://github.com/rerun-io/rerun), e.g. <https://rerun.io>.
70 ///
71 /// ## Image
72 /// ![A random image](https://picsum.photos/640/480))#")
73 /// .with_media_type(rerun::MediaType::markdown())
74 /// );
75 /// }
76 /// ```
77 struct TextDocument {
78 /// Contents of the text document.
79 std::optional<ComponentBatch> text;
80
81 /// The Media Type of the text.
82 ///
83 /// For instance:
84 /// * `text/plain`
85 /// * `text/markdown`
86 ///
87 /// If omitted, `text/plain` is assumed.
88 std::optional<ComponentBatch> media_type;
89
90 public:
91 /// The name of the archetype as used in `ComponentDescriptor`s.
92 static constexpr const char ArchetypeName[] = "rerun.archetypes.TextDocument";
93
94 /// `ComponentDescriptor` for the `text` field.
95 static constexpr auto Descriptor_text = ComponentDescriptor(
97 );
98 /// `ComponentDescriptor` for the `media_type` field.
100 ArchetypeName, "TextDocument:media_type",
102 );
103
104 public:
105 TextDocument() = default;
106 TextDocument(TextDocument&& other) = default;
107 TextDocument(const TextDocument& other) = default;
108 TextDocument& operator=(const TextDocument& other) = default;
109 TextDocument& operator=(TextDocument&& other) = default;
110
112 : text(ComponentBatch::from_loggable(std::move(_text), Descriptor_text).value_or_throw()
113 ) {}
114
115 /// Update only some specific fields of a `TextDocument`.
117 return TextDocument();
118 }
119
120 /// Clear all the fields of a `TextDocument`.
122
123 /// Contents of the text document.
125 text = ComponentBatch::from_loggable(_text, Descriptor_text).value_or_throw();
126 return std::move(*this);
127 }
128
129 /// This method makes it possible to pack multiple `text` in a single component batch.
130 ///
131 /// This only makes sense when used in conjunction with `columns`. `with_text` should
132 /// be used when logging a single row's worth of data.
134 text = ComponentBatch::from_loggable(_text, Descriptor_text).value_or_throw();
135 return std::move(*this);
136 }
137
138 /// The Media Type of the text.
139 ///
140 /// For instance:
141 /// * `text/plain`
142 /// * `text/markdown`
143 ///
144 /// If omitted, `text/plain` is assumed.
146 media_type =
147 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
148 return std::move(*this);
149 }
150
151 /// This method makes it possible to pack multiple `media_type` in a single component batch.
152 ///
153 /// This only makes sense when used in conjunction with `columns`. `with_media_type` should
154 /// be used when logging a single row's worth of data.
157 ) && {
158 media_type =
159 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
160 return std::move(*this);
161 }
162
163 /// Partitions the component data into multiple sub-batches.
164 ///
165 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
166 /// instead, via `ComponentBatch::partitioned`.
167 ///
168 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
169 ///
170 /// The specified `lengths` must sum to the total length of the component batch.
172 return detail::partition_batches({&text, &media_type}, lengths_).value_or_throw();
173 }
174
175 /// Partitions the component data into unit-length sub-batches.
176 ///
177 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
178 /// where `n` is automatically guessed.
180 return detail::partition_batches_of_unit_length({&text, &media_type}).value_or_throw();
181 }
182 };
183
184} // namespace rerun::archetypes
185
186namespace rerun {
187 /// \private
188 template <typename T>
189 struct AsComponents;
190
191 /// \private
192 template <>
193 struct AsComponents<archetypes::TextDocument> {
194 /// Serialize all set component batches.
195 static Result<Collection<ComponentBatch>> as_batches(
196 const archetypes::TextDocument& archetype
197 ) {
198 return detail::collect_batches({&archetype.text, &archetype.media_type});
199 }
200 };
201} // 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 text element intended to be displayed in its own text box.
Definition text_document.hpp:77
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition text_document.hpp:92
static TextDocument update_fields()
Update only some specific fields of a TextDocument.
Definition text_document.hpp:116
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Definition text_document.hpp:179
std::optional< ComponentBatch > media_type
The Media Type of the text.
Definition text_document.hpp:88
static constexpr auto Descriptor_media_type
ComponentDescriptor for the media_type field.
Definition text_document.hpp:99
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Definition text_document.hpp:171
static constexpr auto Descriptor_text
ComponentDescriptor for the text field.
Definition text_document.hpp:95
TextDocument with_text(const rerun::components::Text &_text) &&
Contents of the text document.
Definition text_document.hpp:124
std::optional< ComponentBatch > text
Contents of the text document.
Definition text_document.hpp:79
TextDocument 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_document.hpp:133
TextDocument with_media_type(const rerun::components::MediaType &_media_type) &&
The Media Type of the text.
Definition text_document.hpp:145
static TextDocument clear_fields()
Clear all the fields of a TextDocument.
TextDocument with_many_media_type(const Collection< rerun::components::MediaType > &_media_type) &&
This method makes it possible to pack multiple media_type in a single component batch.
Definition text_document.hpp:155
Component: A standardized media type (RFC2046, formerly known as MIME types), encoded as a string.
Definition media_type.hpp:20
Component: A string of text, e.g. for labels and text documents.
Definition text.hpp:16