Rerun C++ SDK
Loading...
Searching...
No Matches
component_descriptor.hpp
1#pragma once
2
3#include <optional>
4#include <string_view>
5
6namespace rerun {
7 /// See `ComponentDescriptor::hashed`.
8 using ComponentDescriptorHash = uint64_t;
9
10 /// A `ComponentDescriptor` fully describes the semantics of a column of data.
11 ///
12 /// Every component is uniquely identified by its `ComponentDescriptor`.
14 /// Optional name of the `Archetype` associated with this data.
15 ///
16 /// `None` if the data wasn't logged through an archetype.
17 ///
18 /// Example: `rerun.archetypes.Points3D`.
19 std::optional<std::string_view> archetype_name;
20
21 /// Optional name of the field within `Archetype` associated with this data.
22 ///
23 /// `None` if the data wasn't logged through an archetype.
24 ///
25 /// Example: `positions`.
26 std::optional<std::string_view> archetype_field_name;
27
28 /// Semantic name associated with this data.
29 ///
30 /// This is fully implied by `archetype_name` and `archetype_field`, but
31 /// included for semantic convenience.
32 ///
33 /// Example: `rerun.components.Position3D`.
34 std::string_view component_name;
35
36 constexpr ComponentDescriptor(
37 std::optional<std::string_view> archetype_name_,
38 std::optional<std::string_view> archetype_field_name_, std::string_view component_name_
39 )
40 : archetype_name(archetype_name_),
41 archetype_field_name(archetype_field_name_),
42 component_name(component_name_) {}
43
44 constexpr ComponentDescriptor(
45 const char* archetype_name_, const char* archetype_field_name_,
46 const char* component_name_
47 )
48 : archetype_name(archetype_name_),
49 archetype_field_name(archetype_field_name_),
50 component_name(component_name_) {}
51
52 constexpr ComponentDescriptor(std::string_view component_name_)
53 : component_name(component_name_) {}
54
55 constexpr ComponentDescriptor(const char* component_name_)
56 : component_name(component_name_) {}
57
58 ComponentDescriptorHash hashed() const {
59 std::size_t archetype_name_h =
60 std::hash<std::optional<std::string_view>>{}(this->archetype_name);
61 std::size_t component_name_h = std::hash<std::string_view>{}(this->component_name);
62 std::size_t archetype_field_name_h =
63 std::hash<std::optional<std::string_view>>{}(this->archetype_field_name);
64 return archetype_name_h ^ component_name_h ^ archetype_field_name_h;
65 }
66
67 /// Unconditionally sets `archetype_name` to the given one.
68 ComponentDescriptor with_archetype_name(std::optional<std::string_view> archetype_name_
69 ) const {
70 ComponentDescriptor descriptor = *this;
71 descriptor.archetype_name = archetype_name_;
72 return descriptor;
73 }
74
75 /// Unconditionally sets `archetype_name` to the given one.
76 ComponentDescriptor with_archetype_name(const char* archetype_name_) const {
77 ComponentDescriptor descriptor = *this;
78 descriptor.archetype_name = archetype_name_;
79 return descriptor;
80 }
81
82 /// Unconditionally sets `archetype_field_name` to the given one.
84 std::optional<std::string_view> archetype_field_name_
85 ) const {
86 ComponentDescriptor descriptor = *this;
87 descriptor.archetype_field_name = archetype_field_name_;
88 return descriptor;
89 }
90
91 /// Unconditionally sets `archetype_field_name` to the given one.
92 ComponentDescriptor with_archetype_field_name(const char* archetype_field_name_) const {
93 ComponentDescriptor descriptor = *this;
94 descriptor.archetype_field_name = archetype_field_name_;
95 return descriptor;
96 }
97
98 /// Sets `archetype_name` to the given one iff it's not already set.
99 ComponentDescriptor or_with_archetype_name(std::optional<std::string_view> archetype_name_
100 ) const {
101 if (this->archetype_field_name.has_value()) {
102 return *this;
103 }
104 ComponentDescriptor descriptor = *this;
105 descriptor.archetype_name = archetype_name_;
106 return descriptor;
107 }
108
109 /// Sets `archetype_name` to the given one iff it's not already set.
110 ComponentDescriptor or_with_archetype_name(const char* archetype_name_) const {
111 if (this->archetype_field_name.has_value()) {
112 return *this;
113 }
114 ComponentDescriptor descriptor = *this;
115 descriptor.archetype_name = archetype_name_;
116 return descriptor;
117 }
118
119 /// Sets `archetype_field_name` to the given one iff it's not already set.
121 std::optional<std::string_view> archetype_field_name_
122 ) const {
123 if (this->archetype_field_name.has_value()) {
124 return *this;
125 }
126 ComponentDescriptor descriptor = *this;
127 descriptor.archetype_field_name = archetype_field_name_;
128 return descriptor;
129 }
130
131 /// Sets `archetype_field_name` to the given one iff it's not already set.
132 ComponentDescriptor or_with_archetype_field_name(const char* archetype_field_name_) const {
133 if (this->archetype_field_name.has_value()) {
134 return *this;
135 }
136 ComponentDescriptor descriptor = *this;
137 descriptor.archetype_field_name = archetype_field_name_;
138 return descriptor;
139 }
140 };
141} // 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:8
A ComponentDescriptor fully describes the semantics of a column of data.
Definition component_descriptor.hpp:13
ComponentDescriptor with_archetype_field_name(const char *archetype_field_name_) const
Unconditionally sets archetype_field_name to the given one.
Definition component_descriptor.hpp:92
ComponentDescriptor or_with_archetype_field_name(std::optional< std::string_view > archetype_field_name_) const
Sets archetype_field_name to the given one iff it's not already set.
Definition component_descriptor.hpp:120
std::optional< std::string_view > archetype_field_name
Optional name of the field within Archetype associated with this data.
Definition component_descriptor.hpp:26
std::optional< std::string_view > archetype_name
Optional name of the Archetype associated with this data.
Definition component_descriptor.hpp:19
ComponentDescriptor with_archetype_field_name(std::optional< std::string_view > archetype_field_name_) const
Unconditionally sets archetype_field_name to the given one.
Definition component_descriptor.hpp:83
std::string_view component_name
Semantic name associated with this data.
Definition component_descriptor.hpp:34
ComponentDescriptor with_archetype_name(std::optional< std::string_view > archetype_name_) const
Unconditionally sets archetype_name to the given one.
Definition component_descriptor.hpp:68
ComponentDescriptor or_with_archetype_field_name(const char *archetype_field_name_) const
Sets archetype_field_name to the given one iff it's not already set.
Definition component_descriptor.hpp:132
ComponentDescriptor or_with_archetype_name(const char *archetype_name_) const
Sets archetype_name to the given one iff it's not already set.
Definition component_descriptor.hpp:110
ComponentDescriptor or_with_archetype_name(std::optional< std::string_view > archetype_name_) const
Sets archetype_name to the given one iff it's not already set.
Definition component_descriptor.hpp:99
ComponentDescriptor with_archetype_name(const char *archetype_name_) const
Unconditionally sets archetype_name to the given one.
Definition component_descriptor.hpp:76