Rerun C++ SDK
Loading...
Searching...
No Matches
scale3d.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/scale3d.fbs".
3
4#pragma once
5
6#include "../result.hpp"
7#include "vec3d.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 Scale3DTag : 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 ThreeD,
28 Uniform,
29 };
30
31 /// \private
32 union Scale3DData {
33 /// Individual scaling factors for each axis, distorting the original object.
35
36 /// Uniform scaling factor along all axis.
37 float uniform;
38
39 Scale3DData() {
40 std::memset(reinterpret_cast<void*>(this), 0, sizeof(Scale3DData));
41 }
42
43 ~Scale3DData() {}
44
45 void swap(Scale3DData& other) noexcept {
46 // This bitwise swap would fail for self-referential types, but we don't have any of those.
47 char temp[sizeof(Scale3DData)];
48 void* otherbytes = reinterpret_cast<void*>(&other);
49 void* thisbytes = reinterpret_cast<void*>(this);
50 std::memcpy(temp, thisbytes, sizeof(Scale3DData));
51 std::memcpy(thisbytes, otherbytes, sizeof(Scale3DData));
52 std::memcpy(otherbytes, temp, sizeof(Scale3DData));
53 }
54 };
55 } // namespace detail
56
57 /// **Datatype**: 3D scaling factor, part of a transform representation.
58 struct Scale3D {
59 Scale3D() : _tag(detail::Scale3DTag::None) {}
60
61 /// Copy constructor
62 Scale3D(const Scale3D& other) : _tag(other._tag) {
63 const void* otherbytes = reinterpret_cast<const void*>(&other._data);
64 void* thisbytes = reinterpret_cast<void*>(&this->_data);
65 std::memcpy(thisbytes, otherbytes, sizeof(detail::Scale3DData));
66 }
67
68 Scale3D& operator=(const Scale3D& other) noexcept {
69 Scale3D tmp(other);
70 this->swap(tmp);
71 return *this;
72 }
73
74 Scale3D(Scale3D&& other) noexcept : Scale3D() {
75 this->swap(other);
76 }
77
78 Scale3D& operator=(Scale3D&& other) noexcept {
79 this->swap(other);
80 return *this;
81 }
82
83 void swap(Scale3D& other) noexcept {
84 std::swap(this->_tag, other._tag);
85 this->_data.swap(other._data);
86 }
87
88 /// Individual scaling factors for each axis, distorting the original object.
90 *this = Scale3D::three_d(std::move(three_d));
91 }
92
93 /// Uniform scaling factor along all axis.
94 Scale3D(float uniform) : Scale3D() {
95 *this = Scale3D::uniform(std::move(uniform));
96 }
97
98 /// Individual scaling factors for each axis, distorting the original object.
100 Scale3D self;
101 self._tag = detail::Scale3DTag::ThreeD;
102 new (&self._data.three_d) rerun::datatypes::Vec3D(std::move(three_d));
103 return self;
104 }
105
106 /// Uniform scaling factor along all axis.
107 static Scale3D uniform(float uniform) {
108 Scale3D self;
109 self._tag = detail::Scale3DTag::Uniform;
110 new (&self._data.uniform) float(std::move(uniform));
111 return self;
112 }
113
114 /// Return a pointer to three_d if the union is in that state, otherwise `nullptr`.
116 if (_tag == detail::Scale3DTag::ThreeD) {
117 return &_data.three_d;
118 } else {
119 return nullptr;
120 }
121 }
122
123 /// Return a pointer to uniform if the union is in that state, otherwise `nullptr`.
124 const float* get_uniform() const {
125 if (_tag == detail::Scale3DTag::Uniform) {
126 return &_data.uniform;
127 } else {
128 return nullptr;
129 }
130 }
131
132 /// \private
133 const detail::Scale3DData& get_union_data() const {
134 return _data;
135 }
136
137 /// \private
138 detail::Scale3DTag get_union_tag() const {
139 return _tag;
140 }
141
142 private:
143 detail::Scale3DTag _tag;
144 detail::Scale3DData _data;
145 };
146} // namespace rerun::datatypes
147
148namespace rerun {
149 template <typename T>
150 struct Loggable;
151
152 /// \private
153 template <>
154 struct Loggable<datatypes::Scale3D> {
155 static constexpr const char Name[] = "rerun.datatypes.Scale3D";
156
157 /// Returns the arrow data type this type corresponds to.
158 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
159
160 /// Fills an arrow array builder with an array of this type.
161 static rerun::Error fill_arrow_array_builder(
162 arrow::DenseUnionBuilder* builder, const datatypes::Scale3D* elements,
163 size_t num_elements
164 );
165
166 /// Serializes an array of `rerun::datatypes::Scale3D` into an arrow array.
167 static Result<std::shared_ptr<arrow::Array>> to_arrow(
168 const datatypes::Scale3D* instances, size_t num_instances
169 );
170 };
171} // 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: 3D scaling factor, part of a transform representation.
Definition scale3d.hpp:58
const float * get_uniform() const
Return a pointer to uniform if the union is in that state, otherwise nullptr.
Definition scale3d.hpp:124
static Scale3D uniform(float uniform)
Uniform scaling factor along all axis.
Definition scale3d.hpp:107
static Scale3D three_d(rerun::datatypes::Vec3D three_d)
Individual scaling factors for each axis, distorting the original object.
Definition scale3d.hpp:99
Scale3D(rerun::datatypes::Vec3D three_d)
Individual scaling factors for each axis, distorting the original object.
Definition scale3d.hpp:89
Scale3D(const Scale3D &other)
Copy constructor.
Definition scale3d.hpp:62
const rerun::datatypes::Vec3D * get_three_d() const
Return a pointer to three_d if the union is in that state, otherwise nullptr.
Definition scale3d.hpp:115
Scale3D(float uniform)
Uniform scaling factor along all axis.
Definition scale3d.hpp:94
Datatype: A vector in 3D space.
Definition vec3d.hpp:20