gusimplewhiteboard
RMSLevels.hpp
Go to the documentation of this file.
1/*
2 * file RMSLevels.hpp
3 *
4 * This file was generated by classgenerator from RMS_levels.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Rene Hexel. 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 Rene Hexel.
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_RMSLevels_h
61#define guWhiteboard_RMSLevels_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_r_m_s_levels.h"
71
72#undef guWhiteboard_RMSLevels_DEFINED
73#define guWhiteboard_RMSLevels_DEFINED
74
75#undef RMSLevels_DEFINED
76#define RMSLevels_DEFINED
77
78namespace guWhiteboard {
79
83 class RMSLevels: public wb_r_m_s_levels {
84
85 private:
86
90 void init(int16_t t_rear_left = 0, int16_t t_rear_right = 0, int16_t t_front_left = 0, int16_t t_front_right = 0) {
91 set_rear_left(t_rear_left);
92 set_rear_right(t_rear_right);
93 set_front_left(t_front_left);
94 set_front_right(t_front_right);
95 }
96
97 public:
98
102 RMSLevels(int16_t t_rear_left = 0, int16_t t_rear_right = 0, int16_t t_front_left = 0, int16_t t_front_right = 0) {
103 this->init(t_rear_left, t_rear_right, t_front_left, t_front_right);
104 }
105
110 this->init(t_other.rear_left(), t_other.rear_right(), t_other.front_left(), t_other.front_right());
111 }
112
116 RMSLevels(const struct wb_r_m_s_levels &t_other): wb_r_m_s_levels() {
117 this->init(t_other.rear_left, t_other.rear_right, t_other.front_left, t_other.front_right);
118 }
119
123 RMSLevels &operator = (const RMSLevels &t_other) {
124 this->init(t_other.rear_left(), t_other.rear_right(), t_other.front_left(), t_other.front_right());
125 return *this;
126 }
127
131 RMSLevels &operator = (const struct wb_r_m_s_levels &t_other) {
132 this->init(t_other.rear_left, t_other.rear_right, t_other.front_left, t_other.front_right);
133 return *this;
134 }
135
136 bool operator ==(const RMSLevels &t_other) const
137 {
138 return rear_left() == t_other.rear_left()
139 && rear_right() == t_other.rear_right()
140 && front_left() == t_other.front_left()
141 && front_right() == t_other.front_right();
142 }
143
144 bool operator !=(const RMSLevels &t_other) const
145 {
146 return !(*this == t_other);
147 }
148
149 bool operator ==(const wb_r_m_s_levels &t_other) const
150 {
151 return *this == RMSLevels(t_other);
152 }
153
154 bool operator !=(const wb_r_m_s_levels &t_other) const
155 {
156 return !(*this == t_other);
157 }
158
159 int16_t & rear_left()
160 {
162 }
163
164 const int16_t & rear_left() const
165 {
167 }
168
169 void set_rear_left(const int16_t &t_newValue)
170 {
171 wb_r_m_s_levels::rear_left = t_newValue;
172 }
173
174 int16_t & rear_right()
175 {
177 }
178
179 const int16_t & rear_right() const
180 {
182 }
183
184 void set_rear_right(const int16_t &t_newValue)
185 {
186 wb_r_m_s_levels::rear_right = t_newValue;
187 }
188
189 int16_t & front_left()
190 {
192 }
193
194 const int16_t & front_left() const
195 {
197 }
198
199 void set_front_left(const int16_t &t_newValue)
200 {
201 wb_r_m_s_levels::front_left = t_newValue;
202 }
203
204 int16_t & front_right()
205 {
207 }
208
209 const int16_t & front_right() const
210 {
212 }
213
214 void set_front_right(const int16_t &t_newValue)
215 {
216 wb_r_m_s_levels::front_right = t_newValue;
217 }
218
219#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
223 RMSLevels(const std::string &t_str) {
224 this->init();
225 this->from_string(t_str);
226 }
227
228 std::string description() {
229#ifdef USE_WB_R_M_S_LEVELS_C_CONVERSION
230 char buffer[RMS_LEVELS_DESC_BUFFER_SIZE];
231 wb_r_m_s_levels_description(this, buffer, sizeof(buffer));
232 std::string descr = buffer;
233 return descr;
234#else
235 std::ostringstream ss;
236 ss << "rear_left=" << static_cast<signed>(this->rear_left());
237 ss << ", ";
238 ss << "rear_right=" << static_cast<signed>(this->rear_right());
239 ss << ", ";
240 ss << "front_left=" << static_cast<signed>(this->front_left());
241 ss << ", ";
242 ss << "front_right=" << static_cast<signed>(this->front_right());
243 return ss.str();
244#endif
245 }
246
247 std::string to_string() {
248#ifdef USE_WB_R_M_S_LEVELS_C_CONVERSION
250 wb_r_m_s_levels_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->rear_left());
256 ss << ", ";
257 ss << static_cast<signed>(this->rear_right());
258 ss << ", ";
259 ss << static_cast<signed>(this->front_left());
260 ss << ", ";
261 ss << static_cast<signed>(this->front_right());
262 return ss.str();
263#endif
264 }
265
266#ifdef USE_WB_R_M_S_LEVELS_C_CONVERSION
267 void from_string(const std::string &t_str) {
268 wb_r_m_s_levels_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 > RMS_LEVELS_DESC_BUFFER_SIZE) {
275 return;
276 }
277 char var_str_buffer[RMS_LEVELS_DESC_BUFFER_SIZE + 1];
278 char* var_str = &var_str_buffer[0];
279 char key_buffer[12];
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("rear_left", key)) {
341 varIndex = 0;
342 } else if (0 == strcmp("rear_right", key)) {
343 varIndex = 1;
344 } else if (0 == strcmp("front_left", key)) {
345 varIndex = 2;
346 } else if (0 == strcmp("front_right", 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_rear_left(static_cast<int16_t>(atoi(var_str)));
357 break;
358 }
359 case 1:
360 {
361 this->set_rear_right(static_cast<int16_t>(atoi(var_str)));
362 break;
363 }
364 case 2:
365 {
366 this->set_front_left(static_cast<int16_t>(atoi(var_str)));
367 break;
368 }
369 case 3:
370 {
371 this->set_front_right(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_r_m_s_levels.
Definition: RMSLevels.hpp:83
void set_rear_left(const int16_t &t_newValue)
Definition: RMSLevels.hpp:169
const int16_t & rear_right() const
Definition: RMSLevels.hpp:179
RMSLevels(const RMSLevels &t_other)
Copy Constructor.
Definition: RMSLevels.hpp:109
RMSLevels & operator=(const RMSLevels &t_other)
Copy Assignment Operator.
Definition: RMSLevels.hpp:123
std::string to_string()
Definition: RMSLevels.hpp:247
const int16_t & front_left() const
Definition: RMSLevels.hpp:194
void set_rear_right(const int16_t &t_newValue)
Definition: RMSLevels.hpp:184
const int16_t & rear_left() const
Definition: RMSLevels.hpp:164
std::string description()
Definition: RMSLevels.hpp:228
void set_front_left(const int16_t &t_newValue)
Definition: RMSLevels.hpp:199
bool operator!=(const RMSLevels &t_other) const
Definition: RMSLevels.hpp:144
bool operator==(const RMSLevels &t_other) const
Definition: RMSLevels.hpp:136
RMSLevels(const struct wb_r_m_s_levels &t_other)
Copy Constructor.
Definition: RMSLevels.hpp:116
RMSLevels(const std::string &t_str)
String Constructor.
Definition: RMSLevels.hpp:223
const int16_t & front_right() const
Definition: RMSLevels.hpp:209
void set_front_right(const int16_t &t_newValue)
Definition: RMSLevels.hpp:214
void from_string(const std::string &t_str)
Definition: RMSLevels.hpp:270
RMSLevels(int16_t t_rear_left=0, int16_t t_rear_right=0, int16_t t_front_left=0, int16_t t_front_right=0)
Create a new RMSLevels.
Definition: RMSLevels.hpp:102
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
int16_t rear_left
rear left RMS level
int16_t front_right
front left RMS level
int16_t front_left
front left RMS level
int16_t rear_right
rear right RMS level
const char * wb_r_m_s_levels_to_string(const struct wb_r_m_s_levels *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_r_m_s_levels * wb_r_m_s_levels_from_string(struct wb_r_m_s_levels *self, const char *str)
Convert from a string.
const char * wb_r_m_s_levels_description(const struct wb_r_m_s_levels *self, char *descString, size_t bufferSize)
Convert to a description string.
#define RMS_LEVELS_DESC_BUFFER_SIZE
#define RMS_LEVELS_TO_STRING_BUFFER_SIZE