Rerun C++ SDK
Loading...
Searching...
No Matches
angle.hpp
1// DO NOT EDIT! This file was auto-generated by crates/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/re_types/definitions/rerun/datatypes/angle.fbs".
3
4#pragma once
5
6#include "../result.hpp"
7
8#include <cstdint>
9#include <cstring>
10#include <memory>
11#include <new>
12#include <utility>
13
14namespace arrow {
15 class Array;
16 class DataType;
17 class DenseUnionBuilder;
18} // namespace arrow
19
20namespace rerun::datatypes {
21 namespace detail {
22 /// \private
23 enum class AngleTag : uint8_t {
24 /// 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.
25 None = 0,
26 Radians,
27 Degrees,
28 };
29
30 /// \private
31 union AngleData {
32 float radians;
33
34 float degrees;
35
36 AngleData() {
37 std::memset(reinterpret_cast<void*>(this), 0, sizeof(AngleData));
38 }
39
40 ~AngleData() {}
41
42 void swap(AngleData& other) noexcept {
43 // This bitwise swap would fail for self-referential types, but we don't have any of those.
44 char temp[sizeof(AngleData)];
45 void* otherbytes = reinterpret_cast<void*>(&other);
46 void* thisbytes = reinterpret_cast<void*>(this);
47 std::memcpy(temp, thisbytes, sizeof(AngleData));
48 std::memcpy(thisbytes, otherbytes, sizeof(AngleData));
49 std::memcpy(otherbytes, temp, sizeof(AngleData));
50 }
51 };
52 } // namespace detail
53
54 /// **Datatype**: Angle in either radians or degrees.
55 struct Angle {
56 Angle() : _tag(detail::AngleTag::None) {}
57
58 /// Copy constructor
59 Angle(const Angle& other) : _tag(other._tag) {
60 const void* otherbytes = reinterpret_cast<const void*>(&other._data);
61 void* thisbytes = reinterpret_cast<void*>(&this->_data);
62 std::memcpy(thisbytes, otherbytes, sizeof(detail::AngleData));
63 }
64
65 Angle& operator=(const Angle& other) noexcept {
66 Angle tmp(other);
67 this->swap(tmp);
68 return *this;
69 }
70
71 Angle(Angle&& other) noexcept : Angle() {
72 this->swap(other);
73 }
74
75 Angle& operator=(Angle&& other) noexcept {
76 this->swap(other);
77 return *this;
78 }
79
80 void swap(Angle& other) noexcept {
81 std::swap(this->_tag, other._tag);
82 this->_data.swap(other._data);
83 }
84
85 static Angle radians(float radians) {
86 Angle self;
87 self._tag = detail::AngleTag::Radians;
88 new (&self._data.radians) float(std::move(radians));
89 return self;
90 }
91
92 static Angle degrees(float degrees) {
93 Angle self;
94 self._tag = detail::AngleTag::Degrees;
95 new (&self._data.degrees) float(std::move(degrees));
96 return self;
97 }
98
99 /// Return a pointer to radians if the union is in that state, otherwise `nullptr`.
100 const float* get_radians() const {
101 if (_tag == detail::AngleTag::Radians) {
102 return &_data.radians;
103 } else {
104 return nullptr;
105 }
106 }
107
108 /// Return a pointer to degrees if the union is in that state, otherwise `nullptr`.
109 const float* get_degrees() const {
110 if (_tag == detail::AngleTag::Degrees) {
111 return &_data.degrees;
112 } else {
113 return nullptr;
114 }
115 }
116
117 /// \private
118 const detail::AngleData& get_union_data() const {
119 return _data;
120 }
121
122 /// \private
123 detail::AngleTag get_union_tag() const {
124 return _tag;
125 }
126
127 private:
128 detail::AngleTag _tag;
129 detail::AngleData _data;
130 };
131} // namespace rerun::datatypes
132
133namespace rerun {
134 template <typename T>
135 struct Loggable;
136
137 /// \private
138 template <>
139 struct Loggable<datatypes::Angle> {
140 static constexpr const char Name[] = "rerun.datatypes.Angle";
141
142 /// Returns the arrow data type this type corresponds to.
143 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
144
145 /// Fills an arrow array builder with an array of this type.
146 static rerun::Error fill_arrow_array_builder(
147 arrow::DenseUnionBuilder* builder, const datatypes::Angle* elements, size_t num_elements
148 );
149
150 /// Serializes an array of `rerun::datatypes::Angle` into an arrow array.
151 static Result<std::shared_ptr<arrow::Array>> to_arrow(
152 const datatypes::Angle* instances, size_t num_instances
153 );
154 };
155} // namespace rerun
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:87
All built-in datatypes. See Types in the Rerun manual.
Definition rerun.hpp:72
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:20
Datatype: Angle in either radians or degrees.
Definition angle.hpp:55
Angle(const Angle &other)
Copy constructor.
Definition angle.hpp:59
const float * get_radians() const
Return a pointer to radians if the union is in that state, otherwise nullptr.
Definition angle.hpp:100
const float * get_degrees() const
Return a pointer to degrees if the union is in that state, otherwise nullptr.
Definition angle.hpp:109