gusimplewhiteboard
Input3D.hpp
Go to the documentation of this file.
1/*
2 * file Input3D.hpp
3 *
4 * This file was generated by classgenerator from Input3D.txt.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Carl Lusty. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials
19 * provided with the distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgement:
23 *
24 * This product includes software developed by Carl Lusty.
25 *
26 * 4. Neither the name of the author nor the names of contributors
27 * may be used to endorse or promote products derived from this
28 * software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
34 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
37 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * -----------------------------------------------------------------------
43 * This program is free software; you can redistribute it and/or
44 * modify it under the above terms or under the terms of the GNU
45 * General Public License as published by the Free Software Foundation;
46 * either version 2 of the License, or (at your option) any later version.
47 *
48 * This program is distributed in the hope that it will be useful,
49 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 * GNU General Public License for more details.
52 *
53 * You should have received a copy of the GNU General Public License
54 * along with this program; if not, see http://www.gnu.org/licenses/
55 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
56 * Fifth Floor, Boston, MA 02110-1301, USA.
57 *
58 */
59
60#ifndef guWhiteboard_Input3D_h
61#define guWhiteboard_Input3D_h
62
63#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
64#include <cstdlib>
65#include <string.h>
66#include <sstream>
67#endif
68
69#include <gu_util.h>
70#include "wb_input3d.h"
71
72#undef guWhiteboard_Input3D_DEFINED
73#define guWhiteboard_Input3D_DEFINED
74
75#undef Input3D_DEFINED
76#define Input3D_DEFINED
77
78namespace guWhiteboard {
79
83 class Input3D: public wb_input3d {
84
85 private:
86
90 void init(int16_t t_yaw = 0, int16_t t_pitch = 0, int16_t t_roll = 0, int16_t t_power = 0) {
91 set_yaw(t_yaw);
92 set_pitch(t_pitch);
93 set_roll(t_roll);
94 set_power(t_power);
95 }
96
97 public:
98
102 Input3D(int16_t t_yaw = 0, int16_t t_pitch = 0, int16_t t_roll = 0, int16_t t_power = 0) {
103 this->init(t_yaw, t_pitch, t_roll, t_power);
104 }
105
109 Input3D(const Input3D &t_other): wb_input3d() {
110 this->init(t_other.yaw(), t_other.pitch(), t_other.roll(), t_other.power());
111 }
112
116 Input3D(const struct wb_input3d &t_other): wb_input3d() {
117 this->init(t_other.yaw, t_other.pitch, t_other.roll, t_other.power);
118 }
119
123 Input3D &operator = (const Input3D &t_other) {
124 this->init(t_other.yaw(), t_other.pitch(), t_other.roll(), t_other.power());
125 return *this;
126 }
127
131 Input3D &operator = (const struct wb_input3d &t_other) {
132 this->init(t_other.yaw, t_other.pitch, t_other.roll, t_other.power);
133 return *this;
134 }
135
136 bool operator ==(const Input3D &t_other) const
137 {
138 return yaw() == t_other.yaw()
139 && pitch() == t_other.pitch()
140 && roll() == t_other.roll()
141 && power() == t_other.power();
142 }
143
144 bool operator !=(const Input3D &t_other) const
145 {
146 return !(*this == t_other);
147 }
148
149 bool operator ==(const wb_input3d &t_other) const
150 {
151 return *this == Input3D(t_other);
152 }
153
154 bool operator !=(const wb_input3d &t_other) const
155 {
156 return !(*this == t_other);
157 }
158
159 int16_t & yaw()
160 {
161 return wb_input3d::yaw;
162 }
163
164 const int16_t & yaw() const
165 {
166 return wb_input3d::yaw;
167 }
168
169 void set_yaw(const int16_t &t_newValue)
170 {
171 wb_input3d::yaw = t_newValue;
172 }
173
174 int16_t & pitch()
175 {
176 return wb_input3d::pitch;
177 }
178
179 const int16_t & pitch() const
180 {
181 return wb_input3d::pitch;
182 }
183
184 void set_pitch(const int16_t &t_newValue)
185 {
186 wb_input3d::pitch = t_newValue;
187 }
188
189 int16_t & roll()
190 {
191 return wb_input3d::roll;
192 }
193
194 const int16_t & roll() const
195 {
196 return wb_input3d::roll;
197 }
198
199 void set_roll(const int16_t &t_newValue)
200 {
201 wb_input3d::roll = t_newValue;
202 }
203
204 int16_t & power()
205 {
206 return wb_input3d::power;
207 }
208
209 const int16_t & power() const
210 {
211 return wb_input3d::power;
212 }
213
214 void set_power(const int16_t &t_newValue)
215 {
216 wb_input3d::power = t_newValue;
217 }
218
219#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
223 Input3D(const std::string &t_str) {
224 this->init();
225 this->from_string(t_str);
226 }
227
228 std::string description() {
229#ifdef USE_WB_INPUT3D_C_CONVERSION
230 char buffer[INPUT3D_DESC_BUFFER_SIZE];
231 wb_input3d_description(this, buffer, sizeof(buffer));
232 std::string descr = buffer;
233 return descr;
234#else
235 std::ostringstream ss;
236 ss << "yaw=" << static_cast<signed>(this->yaw());
237 ss << ", ";
238 ss << "pitch=" << static_cast<signed>(this->pitch());
239 ss << ", ";
240 ss << "roll=" << static_cast<signed>(this->roll());
241 ss << ", ";
242 ss << "power=" << static_cast<signed>(this->power());
243 return ss.str();
244#endif
245 }
246
247 std::string to_string() {
248#ifdef USE_WB_INPUT3D_C_CONVERSION
250 wb_input3d_to_string(this, buffer, sizeof(buffer));
251 std::string toString = buffer;
252 return toString;
253#else
254 std::ostringstream ss;
255 ss << static_cast<signed>(this->yaw());
256 ss << ", ";
257 ss << static_cast<signed>(this->pitch());
258 ss << ", ";
259 ss << static_cast<signed>(this->roll());
260 ss << ", ";
261 ss << static_cast<signed>(this->power());
262 return ss.str();
263#endif
264 }
265
266#ifdef USE_WB_INPUT3D_C_CONVERSION
267 void from_string(const std::string &t_str) {
268 wb_input3d_from_string(this, t_str.c_str());
269#else
270 void from_string(const std::string &t_str) {
271 char * str_cstr = const_cast<char *>(t_str.c_str());
272 size_t temp_length = strlen(str_cstr);
273 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
274 if (length < 1 || length > INPUT3D_DESC_BUFFER_SIZE) {
275 return;
276 }
277 char var_str_buffer[INPUT3D_DESC_BUFFER_SIZE + 1];
278 char* var_str = &var_str_buffer[0];
279 char key_buffer[6];
280 char* key = &key_buffer[0];
281 int bracecount = 0;
282 int startVar = 0;
283 int index = 0;
284 int startKey = 0;
285 int endKey = -1;
286 int varIndex = 0;
287 if (index == 0 && str_cstr[0] == '{') {
288 index = 1;
289 }
290 startVar = index;
291 startKey = startVar;
292 do {
293 for (int i = index; i < length; i++) {
294 index = i + 1;
295 if (bracecount == 0 && str_cstr[i] == '=') {
296 endKey = i - 1;
297 startVar = index;
298 continue;
299 }
300 if (bracecount == 0 && isspace(str_cstr[i])) {
301 startVar = index;
302 if (endKey == -1) {
303 startKey = index;
304 }
305 continue;
306 }
307 if (bracecount == 0 && str_cstr[i] == ',') {
308 index = i - 1;
309 break;
310 }
311 if (str_cstr[i] == '{') {
312 bracecount++;
313 continue;
314 }
315 if (str_cstr[i] == '}') {
316 bracecount--;
317 if (bracecount < 0) {
318 index = i - 1;
319 break;
320 }
321 }
322 if (i == length - 1) {
323 index = i;
324 }
325 }
326 if (endKey >= startKey && endKey - startKey < length) {
327 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
328 key[(endKey - startKey) + 1] = 0;
329 } else {
330 key[0] = 0;
331 }
332 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
333 var_str[(index - startVar) + 1] = 0;
334 bracecount = 0;
335 index += 2;
336 startVar = index;
337 startKey = startVar;
338 endKey = -1;
339 if (strlen(key) > 0) {
340 if (0 == strcmp("yaw", key)) {
341 varIndex = 0;
342 } else if (0 == strcmp("pitch", key)) {
343 varIndex = 1;
344 } else if (0 == strcmp("roll", key)) {
345 varIndex = 2;
346 } else if (0 == strcmp("power", key)) {
347 varIndex = 3;
348 } else {
349 varIndex = -1;
350 }
351 }
352 switch (varIndex) {
353 case -1: { break; }
354 case 0:
355 {
356 this->set_yaw(static_cast<int16_t>(atoi(var_str)));
357 break;
358 }
359 case 1:
360 {
361 this->set_pitch(static_cast<int16_t>(atoi(var_str)));
362 break;
363 }
364 case 2:
365 {
366 this->set_roll(static_cast<int16_t>(atoi(var_str)));
367 break;
368 }
369 case 3:
370 {
371 this->set_power(static_cast<int16_t>(atoi(var_str)));
372 break;
373 }
374 }
375 if (varIndex >= 0) {
376 varIndex++;
377 }
378 } while(index < length);
379#endif
380 }
381#endif
382 };
383
384}
385
386#endif
Provides a C++ wrapper around wb_input3d.
Definition: Input3D.hpp:83
bool operator==(const Input3D &t_other) const
Definition: Input3D.hpp:136
const int16_t & roll() const
Definition: Input3D.hpp:194
void from_string(const std::string &t_str)
Definition: Input3D.hpp:270
Input3D(const std::string &t_str)
String Constructor.
Definition: Input3D.hpp:223
std::string description()
Definition: Input3D.hpp:228
void set_roll(const int16_t &t_newValue)
Definition: Input3D.hpp:199
void set_pitch(const int16_t &t_newValue)
Definition: Input3D.hpp:184
const int16_t & power() const
Definition: Input3D.hpp:209
bool operator!=(const Input3D &t_other) const
Definition: Input3D.hpp:144
Input3D(int16_t t_yaw=0, int16_t t_pitch=0, int16_t t_roll=0, int16_t t_power=0)
Create a new Input3D.
Definition: Input3D.hpp:102
int16_t & roll()
Definition: Input3D.hpp:189
int16_t & pitch()
Definition: Input3D.hpp:174
Input3D(const Input3D &t_other)
Copy Constructor.
Definition: Input3D.hpp:109
int16_t & power()
Definition: Input3D.hpp:204
const int16_t & yaw() const
Definition: Input3D.hpp:164
Input3D & operator=(const Input3D &t_other)
Copy Assignment Operator.
Definition: Input3D.hpp:123
void set_power(const int16_t &t_newValue)
Definition: Input3D.hpp:214
std::string to_string()
Definition: Input3D.hpp:247
Input3D(const struct wb_input3d &t_other)
Copy Constructor.
Definition: Input3D.hpp:116
const int16_t & pitch() const
Definition: Input3D.hpp:179
void set_yaw(const int16_t &t_newValue)
Definition: Input3D.hpp:169
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
Definition: wb_input3d.h:105
int16_t yaw
yaw
Definition: wb_input3d.h:110
int16_t power
power value, ie.
Definition: wb_input3d.h:125
int16_t pitch
pitch
Definition: wb_input3d.h:115
int16_t roll
roll
Definition: wb_input3d.h:120
const char * wb_input3d_description(const struct wb_input3d *self, char *descString, size_t bufferSize)
Convert to a description string.
Definition: wb_input3d.c:125
const char * wb_input3d_to_string(const struct wb_input3d *self, char *toString, size_t bufferSize)
Convert to a string.
Definition: wb_input3d.c:165
struct wb_input3d * wb_input3d_from_string(struct wb_input3d *self, const char *str)
Convert from a string.
Definition: wb_input3d.c:205
#define INPUT3D_DESC_BUFFER_SIZE
Definition: wb_input3d.h:93
#define INPUT3D_TO_STRING_BUFFER_SIZE
Definition: wb_input3d.h:94