Rerun C++ SDK
Loading...
Searching...
No Matches
indicator_component.hpp
1#pragma once
2
3#include <memory> // std::shared_ptr
4#include <optional>
5#include "component_descriptor.hpp"
6#include "loggable.hpp"
7#include "result.hpp"
8
9namespace arrow {
10 class DataType;
11 class Array;
12} // namespace arrow
13
14namespace rerun::components {
15 /// Arrow data type shared by all instances of IndicatorComponent.
16 const std::shared_ptr<arrow::DataType>& indicator_arrow_datatype();
17
18 /// Returns an arrow array for a single indicator component.
19 ///
20 /// This allocates a shared pointer only on the first call and returns references to the static object afterwards.
21 const std::shared_ptr<arrow::Array>& indicator_arrow_array();
22
23 /// Returns an arrow array for a several indicator component.
24 ///
25 /// Unlike the parameterless version this allocates a new data type on every call.
26 std::shared_ptr<arrow::Array> indicator_arrow_array(size_t num_instances);
27
28 /// Indicator component used by archetypes when converting them to component lists.
29 ///
30 /// This is done in order to track how a collection of component was logged.
31 template <const char ComponentName[]>
33} // namespace rerun::components
34
35namespace rerun {
36 /// \private
37 template <const char ComponentName_[]>
38 struct Loggable<components::IndicatorComponent<ComponentName_>> {
39 /// Returns the name of this type.
40 static constexpr ComponentDescriptor Descriptor = ComponentDescriptor(ComponentName_);
41
42 /// Returns the arrow data type this type corresponds to.
43 static const std::shared_ptr<arrow::DataType>& arrow_datatype() {
45 }
46
47 /// Creates an arrow ComponentBatch from an array of IndicatorComponent components.
48 static Result<std::shared_ptr<arrow::Array>> to_arrow(
49 const components::IndicatorComponent<ComponentName_>*, size_t num_instances
50 ) {
51 // If possible, use the statically allocated shared pointer returned by the parameterless version.
52 if (num_instances == 1) {
54 } else {
55 return components::indicator_arrow_array(num_instances);
56 }
57 }
58 };
59} // namespace rerun
All built-in components. See Types in the Rerun manual.
Definition rerun.hpp:79
const std::shared_ptr< arrow::DataType > & indicator_arrow_datatype()
Arrow data type shared by all instances of IndicatorComponent.
const std::shared_ptr< arrow::Array > & indicator_arrow_array()
Returns an arrow array for a single indicator component.
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
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
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:32