Rerun C++ SDK
Loading...
Searching...
No Matches
component_descriptor.hpp
1#pragma once
2
3#include <cstdint>
4#include <optional>
5#include <string_view>
6
7namespace rerun {
8 /// See `ComponentDescriptor::hashed`.
9 using ComponentDescriptorHash = uint64_t;
10
11 /// A `ComponentDescriptor` fully describes the semantics of a column of data.
12 ///
13 /// Every component at a given entity path is uniquely identified by the
14 /// `component` field of the descriptor. The `archetype` and `component_type`
15 /// fields provide additional information about the semantics of the data.
17 /// Optional name of the `Archetype` associated with this data.
18 ///
19 /// `None` if the data wasn't logged through an archetype.
20 ///
21 /// Example: `rerun.archetypes.Points3D`.
22 std::optional<std::string_view> archetype;
23
24 /// Uniquely identifies of the component associated with this data.
25 ///
26 /// Example: `Points3D:positions`.
27 std::string_view component;
28
29 /// Optional type information for this component.
30 ///
31 /// Can be used to inform applications on how to interpret the data.
32 ///
33 /// Example: `rerun.components.Position3D`.
34 std::optional<std::string_view> component_type;
35
36 constexpr ComponentDescriptor(
37 std::optional<std::string_view> archetype_, std::string_view component_,
38 std::optional<std::string_view> component_type_
39 )
40 : archetype(archetype_), component(component_), component_type(component_type_) {}
41
42 constexpr ComponentDescriptor(
43 const char* archetype_, const char* component_, const char* component_type_
44 )
45 : archetype(archetype_), component(component_), component_type(component_type_) {}
46
47 constexpr ComponentDescriptor(std::string_view component_) : component(component_) {}
48
49 constexpr ComponentDescriptor(const char* component_) : component(component_) {}
50
51 ComponentDescriptorHash hashed() const {
52 std::size_t archetype_h = std::hash<std::optional<std::string_view>>{}(this->archetype);
53 std::size_t component_type_h =
54 std::hash<std::optional<std::string_view>>{}(this->component_type);
55 std::size_t component_h = std::hash<std::string_view>{}(this->component);
56 return archetype_h ^ component_type_h ^ component_h;
57 }
58
59 /// Unconditionally sets `archetype` to the given one.
60 ComponentDescriptor with_archetype(std::optional<std::string_view> archetype_) const {
61 ComponentDescriptor descriptor = *this;
62 descriptor.archetype = archetype_;
63 return descriptor;
64 }
65
66 /// Unconditionally sets `archetype` to the given one.
67 ComponentDescriptor with_archetype(const char* archetype_) const {
68 ComponentDescriptor descriptor = *this;
69 descriptor.archetype = archetype_;
70 return descriptor;
71 }
72
73 /// Unconditionally sets `component_type` to the given one.
74 ComponentDescriptor with_component_type(std::optional<std::string_view> component_type_
75 ) const {
76 ComponentDescriptor descriptor = *this;
77 descriptor.component_type = component_type_;
78 return descriptor;
79 }
80
81 /// Unconditionally sets `component_type` to the given one.
82 ComponentDescriptor with_component_type(const char* component_type_) const {
83 ComponentDescriptor descriptor = *this;
84 descriptor.component_type = component_type_;
85 return descriptor;
86 }
87
88 /// Sets `archetype` to the given one iff it's not already set.
89 ComponentDescriptor or_with_archetype(std::optional<std::string_view> archetype_) const {
90 if (this->archetype.has_value()) {
91 return *this;
92 }
93 ComponentDescriptor descriptor = *this;
94 descriptor.archetype = archetype_;
95 return descriptor;
96 }
97
98 /// Sets `archetype` to the given one iff it's not already set.
99 ComponentDescriptor or_with_archetype(const char* archetype_) const {
100 if (this->archetype.has_value()) {
101 return *this;
102 }
103 ComponentDescriptor descriptor = *this;
104 descriptor.archetype = archetype_;
105 return descriptor;
106 }
107
108 /// Sets `component_type` to the given one iff it's not already set.
109 ComponentDescriptor or_with_component_type(std::optional<std::string_view> component_type_
110 ) const {
111 if (this->component_type.has_value()) {
112 return *this;
113 }
114 ComponentDescriptor descriptor = *this;
115 descriptor.component_type = component_type_;
116 return descriptor;
117 }
118
119 /// Sets `component_type` to the given one iff it's not already set.
120 ComponentDescriptor or_with_component_type(const char* component_type_) const {
121 if (this->component_type.has_value()) {
122 return *this;
123 }
124 ComponentDescriptor descriptor = *this;
125 descriptor.component_type = component_type_;
126 return descriptor;
127 }
128 };
129} // namespace rerun
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
uint64_t ComponentDescriptorHash
See ComponentDescriptor::hashed.
Definition component_descriptor.hpp:9
A ComponentDescriptor fully describes the semantics of a column of data.
Definition component_descriptor.hpp:16
ComponentDescriptor or_with_component_type(std::optional< std::string_view > component_type_) const
Sets component_type to the given one iff it's not already set.
Definition component_descriptor.hpp:109
ComponentDescriptor with_component_type(const char *component_type_) const
Unconditionally sets component_type to the given one.
Definition component_descriptor.hpp:82
ComponentDescriptor with_component_type(std::optional< std::string_view > component_type_) const
Unconditionally sets component_type to the given one.
Definition component_descriptor.hpp:74
ComponentDescriptor or_with_archetype(std::optional< std::string_view > archetype_) const
Sets archetype to the given one iff it's not already set.
Definition component_descriptor.hpp:89
ComponentDescriptor or_with_archetype(const char *archetype_) const
Sets archetype to the given one iff it's not already set.
Definition component_descriptor.hpp:99
std::optional< std::string_view > component_type
Optional type information for this component.
Definition component_descriptor.hpp:34
std::optional< std::string_view > archetype
Optional name of the Archetype associated with this data.
Definition component_descriptor.hpp:22
ComponentDescriptor with_archetype(const char *archetype_) const
Unconditionally sets archetype to the given one.
Definition component_descriptor.hpp:67
ComponentDescriptor or_with_component_type(const char *component_type_) const
Sets component_type to the given one iff it's not already set.
Definition component_descriptor.hpp:120
std::string_view component
Uniquely identifies of the component associated with this data.
Definition component_descriptor.hpp:27
ComponentDescriptor with_archetype(std::optional< std::string_view > archetype_) const
Unconditionally sets archetype to the given one.
Definition component_descriptor.hpp:60