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 /// Angle in radians. One turn is equal to 2π (or τ) radians.
33 float radians;
34
35 /// Angle in degrees. One turn is equal to 360 degrees.
36 float degrees;
37
38 AngleData() {
39 std::memset(reinterpret_cast<void*>(this), 0, sizeof(AngleData));
40 }
41
42 ~AngleData() {}
43
44 void swap(AngleData& other) noexcept {
45 // This bitwise swap would fail for self-referential types, but we don't have any of those.
46 char temp[sizeof(AngleData)];
47 void* otherbytes = reinterpret_cast<void*>(&other);
48 void* thisbytes = reinterpret_cast<void*>(this);
49 std::memcpy(temp, thisbytes, sizeof(AngleData));
50 std::memcpy(thisbytes, otherbytes, sizeof(AngleData));
51 std::memcpy(otherbytes, temp, sizeof(AngleData));
52 }
53 };
54 } // namespace detail
55
56 /// **Datatype**: Angle in either radians or degrees.
57 struct Angle {
58 Angle() : _tag(detail::AngleTag::None) {}
59
60 /// Copy constructor
61 Angle(const Angle& other) : _tag(other._tag) {
62 const void* otherbytes = reinterpret_cast<const void*>(&other._data);
63 void* thisbytes = reinterpret_cast<void*>(&this->_data);
64 std::memcpy(thisbytes, otherbytes, sizeof(detail::AngleData));
65 }
66
67 Angle& operator=(const Angle& other) noexcept {
68 Angle tmp(other);
69 this->swap(tmp);
70 return *this;
71 }
72
73 Angle(Angle&& other) noexcept : Angle() {
74 this->swap(other);
75 }
76
77 Angle& operator=(Angle&& other) noexcept {
78 this->swap(other);
79 return *this;
80 }
81
82 void swap(Angle& other) noexcept {
83 std::swap(this->_tag, other._tag);
84 this->_data.swap(other._data);
85 }
86
87 /// Angle in radians. One turn is equal to 2π (or τ) radians.
88 static Angle radians(float radians) {
89 Angle self;
90 self._tag = detail::AngleTag::Radians;
91 new (&self._data.radians) float(std::move(radians));
92 return self;
93 }
94
95 /// Angle in degrees. One turn is equal to 360 degrees.
96 static Angle degrees(float degrees) {
97 Angle self;
98 self._tag = detail::AngleTag::Degrees;
99 new (&self._data.degrees) float(std::move(degrees));
100 return self;
101 }
102
103 /// Return a pointer to radians if the union is in that state, otherwise `nullptr`.
104 const float* get_radians() const {
105 if (_tag == detail::AngleTag::Radians) {
106 return &_data.radians;
107 } else {
108 return nullptr;
109 }
110 }
111
112 /// Return a pointer to degrees if the union is in that state, otherwise `nullptr`.
113 const float* get_degrees() const {
114 if (_tag == detail::AngleTag::Degrees) {
115 return &_data.degrees;
116 } else {
117 return nullptr;
118 }
119 }
120
121 /// \private
122 const detail::AngleData& get_union_data() const {
123 return _data;
124 }
125
126 /// \private
127 detail::AngleTag get_union_tag() const {
128 return _tag;
129 }
130
131 private:
132 detail::AngleTag _tag;
133 detail::AngleData _data;
134 };
135} // namespace rerun::datatypes
136
137namespace rerun {
138 template <typename T>
139 struct Loggable;
140
141 /// \private
142 template <>
143 struct Loggable<datatypes::Angle> {
144 static constexpr const char Name[] = "rerun.datatypes.Angle";
145
146 /// Returns the arrow data type this type corresponds to.
147 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
148
149 /// Serializes an array of `rerun::datatypes::Angle` into an arrow array.
150 static Result<std::shared_ptr<arrow::Array>> to_arrow(
151 const datatypes::Angle* instances, size_t num_instances
152 );
153
154 /// Fills an arrow array builder with an array of this type.
155 static rerun::Error fill_arrow_array_builder(
156 arrow::DenseUnionBuilder* builder, const datatypes::Angle* elements, size_t num_elements
157 );
158 };
159} // namespace rerun
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:89
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:21
Datatype: Angle in either radians or degrees.
Definition angle.hpp:57
Angle(const Angle &other)
Copy constructor.
Definition angle.hpp:61
static Angle radians(float radians)
Angle in radians. One turn is equal to 2π (or τ) radians.
Definition angle.hpp:88
static Angle degrees(float degrees)
Angle in degrees. One turn is equal to 360 degrees.
Definition angle.hpp:96
const float * get_radians() const
Return a pointer to radians if the union is in that state, otherwise nullptr.
Definition angle.hpp:104
const float * get_degrees() const
Return a pointer to degrees if the union is in that state, otherwise nullptr.
Definition angle.hpp:113