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