gusimplewhiteboard
NaoObstacleDirection.hpp
Go to the documentation of this file.
1/*
2 * file NaoObstacleDirection.hpp
3 *
4 * This file was generated by classgenerator from nao_obstacle_direction.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Vlad Estivill-Castro. 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 Vlad Estivill-Castro.
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_NaoObstacleDirection_h
61#define guWhiteboard_NaoObstacleDirection_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>
71
72#undef guWhiteboard_NaoObstacleDirection_DEFINED
73#define guWhiteboard_NaoObstacleDirection_DEFINED
74
75#undef NaoObstacleDirection_DEFINED
76#define NaoObstacleDirection_DEFINED
77
78
79
80namespace guWhiteboard {
81
86
87 private:
88
92 void init(bool t_left = false, bool t_right = false, bool t_front = false) {
93 set_left(t_left);
94 set_right(t_right);
95 set_front(t_front);
96 }
97
98 public:
99
103 NaoObstacleDirection(bool t_left = false, bool t_right = false, bool t_front = false) {
104 this->init(t_left, t_right, t_front);
105 }
106
111 this->init(t_other.left(), t_other.right(), t_other.front());
112 }
113
118 this->init(t_other.left, t_other.right, t_other.front);
119 }
120
125 this->init(t_other.left(), t_other.right(), t_other.front());
126 return *this;
127 }
128
133 this->init(t_other.left, t_other.right, t_other.front);
134 return *this;
135 }
136
137 bool operator ==(const NaoObstacleDirection &t_other) const
138 {
139 return left() == t_other.left()
140 && right() == t_other.right()
141 && front() == t_other.front();
142 }
143
144 bool operator !=(const NaoObstacleDirection &t_other) const
145 {
146 return !(*this == t_other);
147 }
148
149 bool operator ==(const wb_nao_obstacle_direction &t_other) const
150 {
151 return *this == NaoObstacleDirection(t_other);
152 }
153
154 bool operator !=(const wb_nao_obstacle_direction &t_other) const
155 {
156 return !(*this == t_other);
157 }
158
159 bool & left()
160 {
162 }
163
164 const bool & left() const
165 {
167 }
168
169 void set_left(const bool &t_newValue)
170 {
172 }
173
174 bool & right()
175 {
177 }
178
179 const bool & right() const
180 {
182 }
183
184 void set_right(const bool &t_newValue)
185 {
187 }
188
189 bool & front()
190 {
192 }
193
194 const bool & front() const
195 {
197 }
198
199 void set_front(const bool &t_newValue)
200 {
202 }
203
204#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
208 NaoObstacleDirection(const std::string &t_str) {
209 this->init();
210 this->from_string(t_str);
211 }
212
213 std::string description() {
214#ifdef USE_WB_NAO_OBSTACLE_DIRECTION_C_CONVERSION
216 wb_nao_obstacle_direction_description(this, buffer, sizeof(buffer));
217 std::string descr = buffer;
218 return descr;
219#else
220 std::ostringstream ss;
221 ss << "left=" << (this->left() ? "true" : "false");
222 ss << ", ";
223 ss << "right=" << (this->right() ? "true" : "false");
224 ss << ", ";
225 ss << "front=" << (this->front() ? "true" : "false");
226 return ss.str();
227#endif
228 }
229
230 std::string to_string() {
231#ifdef USE_WB_NAO_OBSTACLE_DIRECTION_C_CONVERSION
233 wb_nao_obstacle_direction_to_string(this, buffer, sizeof(buffer));
234 std::string toString = buffer;
235 return toString;
236#else
237 std::ostringstream ss;
238 ss << (this->left() ? "true" : "false");
239 ss << ", ";
240 ss << (this->right() ? "true" : "false");
241 ss << ", ";
242 ss << (this->front() ? "true" : "false");
243 return ss.str();
244#endif
245 }
246
247#ifdef USE_WB_NAO_OBSTACLE_DIRECTION_C_CONVERSION
248 void from_string(const std::string &t_str) {
249 wb_nao_obstacle_direction_from_string(this, t_str.c_str());
250#else
251 void from_string(const std::string &t_str) {
252 char * str_cstr = const_cast<char *>(t_str.c_str());
253 size_t temp_length = strlen(str_cstr);
254 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
255 if (length < 1 || length > NAO_OBSTACLE_DIRECTION_DESC_BUFFER_SIZE) {
256 return;
257 }
258 char var_str_buffer[NAO_OBSTACLE_DIRECTION_DESC_BUFFER_SIZE + 1];
259 char* var_str = &var_str_buffer[0];
260 char key_buffer[6];
261 char* key = &key_buffer[0];
262 int bracecount = 0;
263 int startVar = 0;
264 int index = 0;
265 int startKey = 0;
266 int endKey = -1;
267 int varIndex = 0;
268 if (index == 0 && str_cstr[0] == '{') {
269 index = 1;
270 }
271 startVar = index;
272 startKey = startVar;
273 do {
274 for (int i = index; i < length; i++) {
275 index = i + 1;
276 if (bracecount == 0 && str_cstr[i] == '=') {
277 endKey = i - 1;
278 startVar = index;
279 continue;
280 }
281 if (bracecount == 0 && isspace(str_cstr[i])) {
282 startVar = index;
283 if (endKey == -1) {
284 startKey = index;
285 }
286 continue;
287 }
288 if (bracecount == 0 && str_cstr[i] == ',') {
289 index = i - 1;
290 break;
291 }
292 if (str_cstr[i] == '{') {
293 bracecount++;
294 continue;
295 }
296 if (str_cstr[i] == '}') {
297 bracecount--;
298 if (bracecount < 0) {
299 index = i - 1;
300 break;
301 }
302 }
303 if (i == length - 1) {
304 index = i;
305 }
306 }
307 if (endKey >= startKey && endKey - startKey < length) {
308 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
309 key[(endKey - startKey) + 1] = 0;
310 } else {
311 key[0] = 0;
312 }
313 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
314 var_str[(index - startVar) + 1] = 0;
315 bracecount = 0;
316 index += 2;
317 startVar = index;
318 startKey = startVar;
319 endKey = -1;
320 if (strlen(key) > 0) {
321 if (0 == strcmp("left", key)) {
322 varIndex = 0;
323 } else if (0 == strcmp("right", key)) {
324 varIndex = 1;
325 } else if (0 == strcmp("front", key)) {
326 varIndex = 2;
327 } else {
328 varIndex = -1;
329 }
330 }
331 switch (varIndex) {
332 case -1: { break; }
333 case 0:
334 {
335 this->set_left(strcmp(var_str, "true") == 0 || strcmp(var_str, "1") == 0);
336 break;
337 }
338 case 1:
339 {
340 this->set_right(strcmp(var_str, "true") == 0 || strcmp(var_str, "1") == 0);
341 break;
342 }
343 case 2:
344 {
345 this->set_front(strcmp(var_str, "true") == 0 || strcmp(var_str, "1") == 0);
346 break;
347 }
348 }
349 if (varIndex >= 0) {
350 varIndex++;
351 }
352 } while(index < length);
353#endif
354 }
355#endif
356
357 public:
358
361 static NaoObstacleDirection sonar_direction(bool _left, bool _front, bool _right) {
363 obstacles.set_left(_left);
364 obstacles.set_front(_front);
365 obstacles.set_right(_right);
366 return obstacles;
367 }
368 };
369
370}
371
372#endif
Provides a C++ wrapper around wb_nao_obstacle_direction.
void from_string(const std::string &t_str)
NaoObstacleDirection(const struct wb_nao_obstacle_direction &t_other)
Copy Constructor.
NaoObstacleDirection & operator=(const NaoObstacleDirection &t_other)
Copy Assignment Operator.
static NaoObstacleDirection sonar_direction(bool _left, bool _front, bool _right)
WHITEBOARD_POSTER_STRING_CONVERSION.
NaoObstacleDirection(const NaoObstacleDirection &t_other)
Copy Constructor.
NaoObstacleDirection(const std::string &t_str)
String Constructor.
NaoObstacleDirection(bool t_left=false, bool t_right=false, bool t_front=false)
Create a new NaoObstacleDirection.
void set_right(const bool &t_newValue)
void set_left(const bool &t_newValue)
bool operator==(const NaoObstacleDirection &t_other) const
void set_front(const bool &t_newValue)
bool operator!=(const NaoObstacleDirection &t_other) const
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
bool left
Do I have an obstacle 40 cm to my left (check SMSubsumption machine methods)
bool right
Do I have an obstacle 40 cm to my left (check SMSubsumption machine methods)
bool front
Do I have an obstacle 40 cm to my left (check SMSubsumption machine methods)
struct wb_nao_obstacle_direction * wb_nao_obstacle_direction_from_string(struct wb_nao_obstacle_direction *self, const char *str)
Convert from a string.
const char * wb_nao_obstacle_direction_to_string(const struct wb_nao_obstacle_direction *self, char *toString, size_t bufferSize)
Convert to a string.
const char * wb_nao_obstacle_direction_description(const struct wb_nao_obstacle_direction *self, char *descString, size_t bufferSize)
Convert to a description string.
#define NAO_OBSTACLE_DIRECTION_TO_STRING_BUFFER_SIZE
#define NAO_OBSTACLE_DIRECTION_DESC_BUFFER_SIZE