gusimplewhiteboard
TopParticles.hpp
Go to the documentation of this file.
1/*
2 * file TopParticles.hpp
3 *
4 * This file was generated by classgenerator from TopParticles.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_TopParticles_h
61#define guWhiteboard_TopParticles_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_top_particles.h"
71
72#undef guWhiteboard_TopParticles_DEFINED
73#define guWhiteboard_TopParticles_DEFINED
74
75#undef TopParticles_DEFINED
76#define TopParticles_DEFINED
77
78#define TOPPARTICLES_PARTICLES_ARRAY_SIZE 4
79
80#include "ParticlePosition.h"
81
82namespace guWhiteboard {
83
88
89 private:
90
94 void init(const struct wb_particle_position t_particles[4] = NULLPTR) {
95 if (t_particles != NULLPTR) {
97 } else {
99 std::memcpy(wb_top_particles::particles, particles_temp, TOPPARTICLES_PARTICLES_ARRAY_SIZE * sizeof (struct wb_particle_position));
100 }
101 }
102
103 public:
104
108 TopParticles(const struct wb_particle_position t_particles[4] = NULLPTR) {
109 this->init(t_particles);
110 }
111
116 this->init(t_other.particles());
117 }
118
123 this->init(t_other.particles);
124 }
125
130 this->init(t_other.particles());
131 return *this;
132 }
133
137 TopParticles &operator = (const struct wb_top_particles &t_other) {
138 this->init(t_other.particles);
139 return *this;
140 }
141
142 bool operator ==(const TopParticles &t_other) const
143 {
144 for (int particles_0_index = 0; particles_0_index < 4; particles_0_index++)
145 {
146 if (!(ParticlePosition(particles(particles_0_index)) == ParticlePosition(t_other.particles(particles_0_index)))) return false;
147 }
148 return true;
149 }
150
151 bool operator !=(const TopParticles &t_other) const
152 {
153 return !(*this == t_other);
154 }
155
156 bool operator ==(const wb_top_particles &t_other) const
157 {
158 return *this == TopParticles(t_other);
159 }
160
161 bool operator !=(const wb_top_particles &t_other) const
162 {
163 return !(*this == t_other);
164 }
165
167 {
168 return static_cast<const ParticlePosition *>(&(wb_top_particles::particles[0]));
169 }
170
171 size_t particles_size() const
172 {
174 }
175
177 {
178 return const_cast<ParticlePosition &>(static_cast<const ParticlePosition &>(wb_top_particles::particles[t_i]));
179 }
180
181 const ParticlePosition & particles(int t_i) const
182 {
183 return static_cast<const ParticlePosition &>(wb_top_particles::particles[t_i]);
184 }
185
186 void set_particles(const ParticlePosition *t_newValue)
187 {
188 memcpy(wb_top_particles::particles, static_cast<const struct wb_particle_position *>(t_newValue), TOPPARTICLES_PARTICLES_ARRAY_SIZE * (sizeof (struct wb_particle_position)));
189 }
190
191 void set_particles(const ParticlePosition &t_newValue, int t_i)
192 {
193 wb_top_particles::particles[t_i] = static_cast<wb_particle_position>(t_newValue);
194 }
195
196#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
200 TopParticles(const std::string &t_str) {
201 this->init();
202 this->from_string(t_str);
203 }
204
205 std::string description() {
206#ifdef USE_WB_TOP_PARTICLES_C_CONVERSION
208 wb_top_particles_description(this, buffer, sizeof(buffer));
209 std::string descr = buffer;
210 return descr;
211#else
212 std::ostringstream ss;
213 bool particles_first = true;
214 ss << "particles={";
215 for (int i = 0; i < TOPPARTICLES_PARTICLES_ARRAY_SIZE; i++) {
216 ss << (particles_first ? "" : ", ") << "{" << ParticlePosition(this->particles(i)).description() << "}";
217 particles_first = false;
218 }
219 ss << "}";
220 return ss.str();
221#endif
222 }
223
224 std::string to_string() {
225#ifdef USE_WB_TOP_PARTICLES_C_CONVERSION
227 wb_top_particles_to_string(this, buffer, sizeof(buffer));
228 std::string toString = buffer;
229 return toString;
230#else
231 std::ostringstream ss;
232 bool particles_first = true;
233 ss << "{";
234 for (int i = 0; i < TOPPARTICLES_PARTICLES_ARRAY_SIZE; i++) {
235 ss << (particles_first ? "" : ", ") << "{" << ParticlePosition(this->particles(i)).to_string() << "}";
236 particles_first = false;
237 }
238 ss << "}";
239 return ss.str();
240#endif
241 }
242
243#ifdef USE_WB_TOP_PARTICLES_C_CONVERSION
244 void from_string(const std::string &t_str) {
245 wb_top_particles_from_string(this, t_str.c_str());
246#else
247 void from_string(const std::string &t_str) {
248 char * str_cstr = const_cast<char *>(t_str.c_str());
249 size_t temp_length = strlen(str_cstr);
250 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
251 if (length < 1 || length > TOPPARTICLES_DESC_BUFFER_SIZE) {
252 return;
253 }
254 char var_str_buffer[TOPPARTICLES_DESC_BUFFER_SIZE + 1];
255 char* var_str = &var_str_buffer[0];
256 char key_buffer[10];
257 char* key = &key_buffer[0];
258 int bracecount = 0;
259 int lastBrace = -1;
260 int startVar = 0;
261 int index = 0;
262 int startKey = 0;
263 int endKey = -1;
264 int varIndex = 0;
265 if (index == 0 && str_cstr[0] == '{') {
266 index = 1;
267 }
268 startVar = index;
269 startKey = startVar;
270 do {
271 for (int i = index; i < length; i++) {
272 index = i + 1;
273 if (bracecount == 0 && str_cstr[i] == '=') {
274 endKey = i - 1;
275 startVar = index;
276 continue;
277 }
278 if (bracecount == 0 && isspace(str_cstr[i])) {
279 startVar = index;
280 if (endKey == -1) {
281 startKey = index;
282 }
283 continue;
284 }
285 if (bracecount == 0 && str_cstr[i] == ',') {
286 index = i - 1;
287 break;
288 }
289 if (str_cstr[i] == '{') {
290 bracecount++;
291 if (bracecount == 1) {
292 lastBrace = i;
293 }
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("particles", key)) {
322 varIndex = 0;
323 } else {
324 varIndex = -1;
325 }
326 }
327 switch (varIndex) {
328 case -1: { break; }
329 case 0:
330 {
331 int restartIndex = index;
332 index = lastBrace + 1;
333 startVar = index;
334 startKey = startVar;
335 endKey = -1;
336 bracecount = 0;
337 for (int particles_0_index = 0; particles_0_index < TOPPARTICLES_PARTICLES_ARRAY_SIZE; particles_0_index++) {
338 for (int i = index; i < length; i++) {
339 index = i + 1;
340 if (bracecount == 0 && str_cstr[i] == '=') {
341 endKey = i - 1;
342 startVar = index;
343 continue;
344 }
345 if (bracecount == 0 && isspace(str_cstr[i])) {
346 startVar = index;
347 if (endKey == -1) {
348 startKey = index;
349 }
350 continue;
351 }
352 if (bracecount == 0 && str_cstr[i] == ',') {
353 index = i - 1;
354 break;
355 }
356 if (str_cstr[i] == '{') {
357 bracecount++;
358 continue;
359 }
360 if (str_cstr[i] == '}') {
361 bracecount--;
362 if (bracecount < 0) {
363 index = i - 1;
364 break;
365 }
366 }
367 if (i == length - 1) {
368 index = i;
369 }
370 }
371 if (endKey >= startKey && endKey - startKey < length) {
372 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
373 key[(endKey - startKey) + 1] = 0;
374 } else {
375 key[0] = 0;
376 }
377 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
378 var_str[(index - startVar) + 1] = 0;
379 bracecount = 0;
380 index += 2;
381 startVar = index;
382 startKey = startVar;
383 endKey = -1;
384 ParticlePosition particles_0_temp = ParticlePosition();
385 particles_0_temp.from_string(var_str);
386 struct wb_particle_position particles_0 = particles_0_temp;
387 this->set_particles(particles_0, particles_0_index);
388 }
389 index = restartIndex;
390 break;
391 }
392 }
393 if (varIndex >= 0) {
394 varIndex++;
395 }
396 } while(index < length);
397#endif
398 }
399#endif
400
402 return this->particles(0);
403 }
404 };
405
406}
407
408#endif
#define TOPPARTICLES_PARTICLES_ARRAY_SIZE
Provides a C++ wrapper around wb_particle_position.
void from_string(const std::string &t_str)
Provides a C++ wrapper around wb_top_particles.
const ParticlePosition * particles() const
void set_particles(const ParticlePosition &t_newValue, int t_i)
bool operator==(const TopParticles &t_other) const
ParticlePosition & particles(int t_i)
TopParticles(const struct wb_particle_position t_particles[4]=NULLPTR)
Create a new TopParticles.
const ParticlePosition topParticle()
WHITEBOARD_POSTER_STRING_CONVERSION.
bool operator!=(const TopParticles &t_other) const
TopParticles & operator=(const TopParticles &t_other)
Copy Assignment Operator.
TopParticles(const struct wb_top_particles &t_other)
Copy Constructor.
TopParticles(const std::string &t_str)
String Constructor.
void from_string(const std::string &t_str)
TopParticles(const TopParticles &t_other)
Copy Constructor.
void set_particles(const ParticlePosition *t_newValue)
const ParticlePosition & particles(int t_i) const
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
The class of the top particles in a Localization Filter.
struct wb_particle_position particles[4]
these 4 should be the constant NUM_TOP_PARTICLES
struct wb_top_particles * wb_top_particles_from_string(struct wb_top_particles *self, const char *str)
Convert from a string.
const char * wb_top_particles_description(const struct wb_top_particles *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_top_particles_to_string(const struct wb_top_particles *self, char *toString, size_t bufferSize)
Convert to a string.
#define TOPPARTICLES_TO_STRING_BUFFER_SIZE
#define TOPPARTICLES_DESC_BUFFER_SIZE