Rerun C++ SDK
Loading...
Searching...
No Matches
time_range_boundary.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/datatypes/visible_time_range.fbs".
3
4#pragma once
5
6#include "../component_descriptor.hpp"
7#include "../result.hpp"
8#include "time_int.hpp"
9
10#include <cstdint>
11#include <cstring>
12#include <memory>
13#include <new>
14#include <utility>
15
16namespace arrow {
17 class Array;
18 class DataType;
19 class DenseUnionBuilder;
20} // namespace arrow
21
22namespace rerun::datatypes {
23 namespace detail {
24 /// \private
25 enum class TimeRangeBoundaryTag : uint8_t {
26 /// Having a special empty state makes it possible to implement move-semantics. We need to be able to leave the object in a state which we can run the destructor on.
27 None = 0,
28 CursorRelative,
29 Absolute,
30 Infinite,
31 };
32
33 /// \private
34 union TimeRangeBoundaryData {
35 /// Boundary is a value relative to the time cursor.
36 rerun::datatypes::TimeInt cursor_relative;
37
38 /// Boundary is an absolute value.
40
41 TimeRangeBoundaryData() {
42 std::memset(reinterpret_cast<void*>(this), 0, sizeof(TimeRangeBoundaryData));
43 }
44
45 ~TimeRangeBoundaryData() {}
46
47 void swap(TimeRangeBoundaryData& other) noexcept {
48 // This bitwise swap would fail for self-referential types, but we don't have any of those.
49 char temp[sizeof(TimeRangeBoundaryData)];
50 void* otherbytes = reinterpret_cast<void*>(&other);
51 void* thisbytes = reinterpret_cast<void*>(this);
52 std::memcpy(temp, thisbytes, sizeof(TimeRangeBoundaryData));
53 std::memcpy(thisbytes, otherbytes, sizeof(TimeRangeBoundaryData));
54 std::memcpy(otherbytes, temp, sizeof(TimeRangeBoundaryData));
55 }
56 };
57 } // namespace detail
58
59 /// **Datatype**: Left or right boundary of a time range.
61 TimeRangeBoundary() : _tag(detail::TimeRangeBoundaryTag::None) {}
62
63 /// Copy constructor
64 TimeRangeBoundary(const TimeRangeBoundary& other) : _tag(other._tag) {
65 const void* otherbytes = reinterpret_cast<const void*>(&other._data);
66 void* thisbytes = reinterpret_cast<void*>(&this->_data);
67 std::memcpy(thisbytes, otherbytes, sizeof(detail::TimeRangeBoundaryData));
68 }
69
70 TimeRangeBoundary& operator=(const TimeRangeBoundary& other) noexcept {
71 TimeRangeBoundary tmp(other);
72 this->swap(tmp);
73 return *this;
74 }
75
76 TimeRangeBoundary(TimeRangeBoundary&& other) noexcept : TimeRangeBoundary() {
77 this->swap(other);
78 }
79
80 TimeRangeBoundary& operator=(TimeRangeBoundary&& other) noexcept {
81 this->swap(other);
82 return *this;
83 }
84
85 void swap(TimeRangeBoundary& other) noexcept {
86 std::swap(this->_tag, other._tag);
87 this->_data.swap(other._data);
88 }
89
90 /// Boundary is a value relative to the time cursor.
93 self._tag = detail::TimeRangeBoundaryTag::CursorRelative;
94 new (&self._data.cursor_relative) rerun::datatypes::TimeInt(std::move(cursor_relative));
95 return self;
96 }
97
98 /// Boundary is an absolute value.
101 self._tag = detail::TimeRangeBoundaryTag::Absolute;
102 new (&self._data.absolute) rerun::datatypes::TimeInt(std::move(absolute));
103 return self;
104 }
105
106 /// The boundary extends to infinity.
109 self._tag = detail::TimeRangeBoundaryTag::Infinite;
110 return self;
111 }
112
113 /// Return a pointer to cursor_relative if the union is in that state, otherwise `nullptr`.
115 if (_tag == detail::TimeRangeBoundaryTag::CursorRelative) {
116 return &_data.cursor_relative;
117 } else {
118 return nullptr;
119 }
120 }
121
122 /// Return a pointer to absolute if the union is in that state, otherwise `nullptr`.
124 if (_tag == detail::TimeRangeBoundaryTag::Absolute) {
125 return &_data.absolute;
126 } else {
127 return nullptr;
128 }
129 }
130
131 /// Returns true if the union is in the infinite state.
132 bool is_infinite() const {
133 return _tag == detail::TimeRangeBoundaryTag::Infinite;
134 }
135
136 /// \private
137 const detail::TimeRangeBoundaryData& get_union_data() const {
138 return _data;
139 }
140
141 /// \private
142 detail::TimeRangeBoundaryTag get_union_tag() const {
143 return _tag;
144 }
145
146 private:
147 detail::TimeRangeBoundaryTag _tag;
148 detail::TimeRangeBoundaryData _data;
149 };
150} // namespace rerun::datatypes
151
152namespace rerun {
153 template <typename T>
154 struct Loggable;
155
156 /// \private
157 template <>
158 struct Loggable<datatypes::TimeRangeBoundary> {
159 static constexpr ComponentDescriptor Descriptor = "rerun.datatypes.TimeRangeBoundary";
160
161 /// Returns the arrow data type this type corresponds to.
162 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
163
164 /// Serializes an array of `rerun::datatypes::TimeRangeBoundary` into an arrow array.
165 static Result<std::shared_ptr<arrow::Array>> to_arrow(
166 const datatypes::TimeRangeBoundary* instances, size_t num_instances
167 );
168
169 /// Fills an arrow array builder with an array of this type.
170 static rerun::Error fill_arrow_array_builder(
171 arrow::DenseUnionBuilder* builder, const datatypes::TimeRangeBoundary* elements,
172 size_t num_elements
173 );
174 };
175} // namespace rerun
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:96
All built-in datatypes. See Types in the Rerun manual.
Definition rerun.hpp:82
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
Datatype: A 64-bit number describing either nanoseconds OR sequence numbers.
Definition time_int.hpp:25
Datatype: Left or right boundary of a time range.
Definition time_range_boundary.hpp:60
static TimeRangeBoundary cursor_relative(rerun::datatypes::TimeInt cursor_relative)
Boundary is a value relative to the time cursor.
Definition time_range_boundary.hpp:91
const rerun::datatypes::TimeInt * get_absolute() const
Return a pointer to absolute if the union is in that state, otherwise nullptr.
Definition time_range_boundary.hpp:123
TimeRangeBoundary(const TimeRangeBoundary &other)
Copy constructor.
Definition time_range_boundary.hpp:64
static TimeRangeBoundary infinite()
The boundary extends to infinity.
Definition time_range_boundary.hpp:107
const rerun::datatypes::TimeInt * get_cursor_relative() const
Return a pointer to cursor_relative if the union is in that state, otherwise nullptr.
Definition time_range_boundary.hpp:114
static TimeRangeBoundary absolute(rerun::datatypes::TimeInt absolute)
Boundary is an absolute value.
Definition time_range_boundary.hpp:99
bool is_infinite() const
Returns true if the union is in the infinite state.
Definition time_range_boundary.hpp:132