gusimplewhiteboard
ParticleOutputMap.hpp
Go to the documentation of this file.
1/*
2 * file ParticleOutputMap.hpp
3 *
4 * This file was generated by classgenerator from particle_output_map.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Callum McColl. 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 Callum McColl.
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_ParticleOutputMap_h
61#define guWhiteboard_ParticleOutputMap_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_ParticleOutputMap_DEFINED
73#define guWhiteboard_ParticleOutputMap_DEFINED
74
75#undef ParticleOutputMap_DEFINED
76#define ParticleOutputMap_DEFINED
77
78namespace guWhiteboard {
79
84
85 private:
86
90 void init(uint8_t t_fileId = 0, std::string t_filePath = "") {
91 set_fileId(t_fileId);
92 gu_strlcpy(const_cast<char *>(this->filePath()), t_filePath.c_str(), 64);
93 }
94
95 public:
96
100 ParticleOutputMap(uint8_t t_fileId = 0, std::string t_filePath = "") {
101 this->init(t_fileId, t_filePath);
102 }
103
108 this->init(t_other.fileId(), t_other.filePath());
109 }
110
115 this->init(t_other.fileId, t_other.filePath);
116 }
117
122 this->init(t_other.fileId(), t_other.filePath());
123 return *this;
124 }
125
130 this->init(t_other.fileId, t_other.filePath);
131 return *this;
132 }
133
134 bool operator ==(const ParticleOutputMap &t_other) const
135 {
136 return fileId() == t_other.fileId()
137 && 0 == strncmp(filePath(), t_other.filePath(), 64);
138 }
139
140 bool operator !=(const ParticleOutputMap &t_other) const
141 {
142 return !(*this == t_other);
143 }
144
145 bool operator ==(const wb_particle_output_map &t_other) const
146 {
147 return *this == ParticleOutputMap(t_other);
148 }
149
150 bool operator !=(const wb_particle_output_map &t_other) const
151 {
152 return !(*this == t_other);
153 }
154
155 uint8_t & fileId()
156 {
158 }
159
160 const uint8_t & fileId() const
161 {
163 }
164
165 void set_fileId(const uint8_t &t_newValue)
166 {
168 }
169
170 const char * filePath() const
171 {
173 }
174
175 size_t filePath_size() const
176 {
177 return 64;
178 }
179
180 char & filePath(int t_i)
181 {
183 }
184
185 const char & filePath(int t_i) const
186 {
188 }
189
190 void set_filePath(const char *t_newValue)
191 {
192 strncpy(wb_particle_output_map::filePath, t_newValue, 64);
193 }
194
195#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
199 ParticleOutputMap(const std::string &t_str) {
200 this->init();
201 this->from_string(t_str);
202 }
203
204 std::string description() {
205#ifdef USE_WB_PARTICLE_OUTPUT_MAP_C_CONVERSION
207 wb_particle_output_map_description(this, buffer, sizeof(buffer));
208 std::string descr = buffer;
209 return descr;
210#else
211 std::ostringstream ss;
212 ss << "fileId=" << static_cast<unsigned>(this->fileId());
213 ss << ", ";
214 if (0 == strncmp("", this->filePath(), 1)) {
215 ss << "filePath=" << "";
216 } else {
217 ss << "filePath=" << this->filePath();
218 }
219 return ss.str();
220#endif
221 }
222
223 std::string to_string() {
224#ifdef USE_WB_PARTICLE_OUTPUT_MAP_C_CONVERSION
226 wb_particle_output_map_to_string(this, buffer, sizeof(buffer));
227 std::string toString = buffer;
228 return toString;
229#else
230 std::ostringstream ss;
231 ss << static_cast<unsigned>(this->fileId());
232 ss << ", ";
233 if (0 == strncmp("", this->filePath(), 1)) {
234 ss << "";
235 } else {
236 ss << this->filePath();
237 }
238 return ss.str();
239#endif
240 }
241
242#ifdef USE_WB_PARTICLE_OUTPUT_MAP_C_CONVERSION
243 void from_string(const std::string &t_str) {
244 wb_particle_output_map_from_string(this, t_str.c_str());
245#else
246 void from_string(const std::string &t_str) {
247 char * str_cstr = const_cast<char *>(t_str.c_str());
248 size_t temp_length = strlen(str_cstr);
249 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
250 if (length < 1 || length > PARTICLE_OUTPUT_MAP_DESC_BUFFER_SIZE) {
251 return;
252 }
253 char var_str_buffer[PARTICLE_OUTPUT_MAP_DESC_BUFFER_SIZE + 1];
254 char* var_str = &var_str_buffer[0];
255 char key_buffer[9];
256 char* key = &key_buffer[0];
257 int bracecount = 0;
258 int startVar = 0;
259 int index = 0;
260 int startKey = 0;
261 int endKey = -1;
262 int varIndex = 0;
263 if (index == 0 && str_cstr[0] == '{') {
264 index = 1;
265 }
266 startVar = index;
267 startKey = startVar;
268 do {
269 for (int i = index; i < length; i++) {
270 index = i + 1;
271 if (bracecount == 0 && str_cstr[i] == '=') {
272 endKey = i - 1;
273 startVar = index;
274 continue;
275 }
276 if (bracecount == 0 && isspace(str_cstr[i])) {
277 startVar = index;
278 if (endKey == -1) {
279 startKey = index;
280 }
281 continue;
282 }
283 if (bracecount == 0 && str_cstr[i] == ',') {
284 index = i - 1;
285 break;
286 }
287 if (str_cstr[i] == '{') {
288 bracecount++;
289 continue;
290 }
291 if (str_cstr[i] == '}') {
292 bracecount--;
293 if (bracecount < 0) {
294 index = i - 1;
295 break;
296 }
297 }
298 if (i == length - 1) {
299 index = i;
300 }
301 }
302 if (endKey >= startKey && endKey - startKey < length) {
303 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
304 key[(endKey - startKey) + 1] = 0;
305 } else {
306 key[0] = 0;
307 }
308 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
309 var_str[(index - startVar) + 1] = 0;
310 bracecount = 0;
311 index += 2;
312 startVar = index;
313 startKey = startVar;
314 endKey = -1;
315 if (strlen(key) > 0) {
316 if (0 == strcmp("fileId", key)) {
317 varIndex = 0;
318 } else if (0 == strcmp("filePath", key)) {
319 varIndex = 1;
320 } else {
321 varIndex = -1;
322 }
323 }
324 switch (varIndex) {
325 case -1: { break; }
326 case 0:
327 {
328 this->set_fileId(static_cast<uint8_t>(atoi(var_str)));
329 break;
330 }
331 case 1:
332 {
333 strncpy(wb_particle_output_map::filePath, var_str, 64);
334 break;
335 }
336 }
337 if (varIndex >= 0) {
338 varIndex++;
339 }
340 } while(index < length);
341#endif
342 }
343#endif
344 };
345
346}
347
348#endif
Provides a C++ wrapper around wb_particle_output_map.
void from_string(const std::string &t_str)
ParticleOutputMap(const std::string &t_str)
String Constructor.
ParticleOutputMap(const struct wb_particle_output_map &t_other)
Copy Constructor.
ParticleOutputMap & operator=(const ParticleOutputMap &t_other)
Copy Assignment Operator.
bool operator==(const ParticleOutputMap &t_other) const
void set_filePath(const char *t_newValue)
bool operator!=(const ParticleOutputMap &t_other) const
void set_fileId(const uint8_t &t_newValue)
const char & filePath(int t_i) const
ParticleOutputMap(const ParticleOutputMap &t_other)
Copy Constructor.
ParticleOutputMap(uint8_t t_fileId=0, std::string t_filePath="")
Create a new ParticleOutputMap.
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
uint8_t fileId
The id of the file.
char filePath[64]
The path to the file containing the list of particles.
const char * wb_particle_output_map_description(const struct wb_particle_output_map *self, char *descString, size_t bufferSize)
Convert to a description string.
struct wb_particle_output_map * wb_particle_output_map_from_string(struct wb_particle_output_map *self, const char *str)
Convert from a string.
const char * wb_particle_output_map_to_string(const struct wb_particle_output_map *self, char *toString, size_t bufferSize)
Convert to a string.
#define PARTICLE_OUTPUT_MAP_TO_STRING_BUFFER_SIZE
#define PARTICLE_OUTPUT_MAP_DESC_BUFFER_SIZE