gusimplewhiteboard
MicrowaveStatus.hpp
Go to the documentation of this file.
1/*
2 * file MicrowaveStatus.hpp
3 *
4 * This file was generated by classgenerator from microwave_status.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_MicrowaveStatus_h
61#define guWhiteboard_MicrowaveStatus_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_microwave_status.h"
71
72#undef guWhiteboard_MicrowaveStatus_DEFINED
73#define guWhiteboard_MicrowaveStatus_DEFINED
74
75#undef MicrowaveStatus_DEFINED
76#define MicrowaveStatus_DEFINED
77
78namespace guWhiteboard {
79
84
85 private:
86
90 void init(bool t_timeLeft = true, bool t_doorOpen = true, bool t_buttonPushed = true) {
91 set_timeLeft(t_timeLeft);
92 set_doorOpen(t_doorOpen);
93 set_buttonPushed(t_buttonPushed);
94 }
95
96 public:
97
101 MicrowaveStatus(bool t_timeLeft = true, bool t_doorOpen = true, bool t_buttonPushed = true) {
102 this->init(t_timeLeft, t_doorOpen, t_buttonPushed);
103 }
104
109 this->init(t_other.timeLeft(), t_other.doorOpen(), t_other.buttonPushed());
110 }
111
116 this->init(t_other.timeLeft, t_other.doorOpen, t_other.buttonPushed);
117 }
118
123 this->init(t_other.timeLeft(), t_other.doorOpen(), t_other.buttonPushed());
124 return *this;
125 }
126
131 this->init(t_other.timeLeft, t_other.doorOpen, t_other.buttonPushed);
132 return *this;
133 }
134
135 bool operator ==(const MicrowaveStatus &t_other) const
136 {
137 return timeLeft() == t_other.timeLeft()
138 && doorOpen() == t_other.doorOpen()
139 && buttonPushed() == t_other.buttonPushed();
140 }
141
142 bool operator !=(const MicrowaveStatus &t_other) const
143 {
144 return !(*this == t_other);
145 }
146
147 bool operator ==(const wb_microwave_status &t_other) const
148 {
149 return *this == MicrowaveStatus(t_other);
150 }
151
152 bool operator !=(const wb_microwave_status &t_other) const
153 {
154 return !(*this == t_other);
155 }
156
157 bool & timeLeft()
158 {
160 }
161
162 const bool & timeLeft() const
163 {
165 }
166
167 void set_timeLeft(const bool &t_newValue)
168 {
170 }
171
172 bool & doorOpen()
173 {
175 }
176
177 const bool & doorOpen() const
178 {
180 }
181
182 void set_doorOpen(const bool &t_newValue)
183 {
185 }
186
188 {
190 }
191
192 const bool & buttonPushed() const
193 {
195 }
196
197 void set_buttonPushed(const bool &t_newValue)
198 {
200 }
201
202#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
206 MicrowaveStatus(const std::string &t_str) {
207 this->init();
208 this->from_string(t_str);
209 }
210
211 std::string description() {
212#ifdef USE_WB_MICROWAVE_STATUS_C_CONVERSION
214 wb_microwave_status_description(this, buffer, sizeof(buffer));
215 std::string descr = buffer;
216 return descr;
217#else
218 std::ostringstream ss;
219 ss << "timeLeft=" << (this->timeLeft() ? "true" : "false");
220 ss << ", ";
221 ss << "doorOpen=" << (this->doorOpen() ? "true" : "false");
222 ss << ", ";
223 ss << "buttonPushed=" << (this->buttonPushed() ? "true" : "false");
224 return ss.str();
225#endif
226 }
227
228 std::string to_string() {
229#ifdef USE_WB_MICROWAVE_STATUS_C_CONVERSION
231 wb_microwave_status_to_string(this, buffer, sizeof(buffer));
232 std::string toString = buffer;
233 return toString;
234#else
235 std::ostringstream ss;
236 ss << (this->timeLeft() ? "true" : "false");
237 ss << ", ";
238 ss << (this->doorOpen() ? "true" : "false");
239 ss << ", ";
240 ss << (this->buttonPushed() ? "true" : "false");
241 return ss.str();
242#endif
243 }
244
245#ifdef USE_WB_MICROWAVE_STATUS_C_CONVERSION
246 void from_string(const std::string &t_str) {
247 wb_microwave_status_from_string(this, t_str.c_str());
248#else
249 void from_string(const std::string &t_str) {
250 char * str_cstr = const_cast<char *>(t_str.c_str());
251 size_t temp_length = strlen(str_cstr);
252 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
253 if (length < 1 || length > MICROWAVE_STATUS_DESC_BUFFER_SIZE) {
254 return;
255 }
256 char var_str_buffer[MICROWAVE_STATUS_DESC_BUFFER_SIZE + 1];
257 char* var_str = &var_str_buffer[0];
258 char key_buffer[13];
259 char* key = &key_buffer[0];
260 int bracecount = 0;
261 int startVar = 0;
262 int index = 0;
263 int startKey = 0;
264 int endKey = -1;
265 int varIndex = 0;
266 if (index == 0 && str_cstr[0] == '{') {
267 index = 1;
268 }
269 startVar = index;
270 startKey = startVar;
271 do {
272 for (int i = index; i < length; i++) {
273 index = i + 1;
274 if (bracecount == 0 && str_cstr[i] == '=') {
275 endKey = i - 1;
276 startVar = index;
277 continue;
278 }
279 if (bracecount == 0 && isspace(str_cstr[i])) {
280 startVar = index;
281 if (endKey == -1) {
282 startKey = index;
283 }
284 continue;
285 }
286 if (bracecount == 0 && str_cstr[i] == ',') {
287 index = i - 1;
288 break;
289 }
290 if (str_cstr[i] == '{') {
291 bracecount++;
292 continue;
293 }
294 if (str_cstr[i] == '}') {
295 bracecount--;
296 if (bracecount < 0) {
297 index = i - 1;
298 break;
299 }
300 }
301 if (i == length - 1) {
302 index = i;
303 }
304 }
305 if (endKey >= startKey && endKey - startKey < length) {
306 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
307 key[(endKey - startKey) + 1] = 0;
308 } else {
309 key[0] = 0;
310 }
311 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
312 var_str[(index - startVar) + 1] = 0;
313 bracecount = 0;
314 index += 2;
315 startVar = index;
316 startKey = startVar;
317 endKey = -1;
318 if (strlen(key) > 0) {
319 if (0 == strcmp("timeLeft", key)) {
320 varIndex = 0;
321 } else if (0 == strcmp("doorOpen", key)) {
322 varIndex = 1;
323 } else if (0 == strcmp("buttonPushed", key)) {
324 varIndex = 2;
325 } else {
326 varIndex = -1;
327 }
328 }
329 switch (varIndex) {
330 case -1: { break; }
331 case 0:
332 {
333 this->set_timeLeft(strcmp(var_str, "true") == 0 || strcmp(var_str, "1") == 0);
334 break;
335 }
336 case 1:
337 {
338 this->set_doorOpen(strcmp(var_str, "true") == 0 || strcmp(var_str, "1") == 0);
339 break;
340 }
341 case 2:
342 {
343 this->set_buttonPushed(strcmp(var_str, "true") == 0 || strcmp(var_str, "1") == 0);
344 break;
345 }
346 }
347 if (varIndex >= 0) {
348 varIndex++;
349 }
350 } while(index < length);
351#endif
352 }
353#endif
354 };
355
356}
357
358#endif
Provides a C++ wrapper around wb_microwave_status.
void set_doorOpen(const bool &t_newValue)
const bool & buttonPushed() const
MicrowaveStatus & operator=(const MicrowaveStatus &t_other)
Copy Assignment Operator.
MicrowaveStatus(const MicrowaveStatus &t_other)
Copy Constructor.
MicrowaveStatus(const struct wb_microwave_status &t_other)
Copy Constructor.
void set_buttonPushed(const bool &t_newValue)
void from_string(const std::string &t_str)
void set_timeLeft(const bool &t_newValue)
MicrowaveStatus(bool t_timeLeft=true, bool t_doorOpen=true, bool t_buttonPushed=true)
Create a new MicrowaveStatus.
bool operator==(const MicrowaveStatus &t_other) const
bool operator!=(const MicrowaveStatus &t_other) const
MicrowaveStatus(const std::string &t_str)
String Constructor.
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
bool buttonPushed
Has the button been pushed?
bool timeLeft
Is the timer at zero?
bool doorOpen
Is the door open?
struct wb_microwave_status * wb_microwave_status_from_string(struct wb_microwave_status *self, const char *str)
Convert from a string.
const char * wb_microwave_status_description(const struct wb_microwave_status *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_microwave_status_to_string(const struct wb_microwave_status *self, char *toString, size_t bufferSize)
Convert to a string.
#define MICROWAVE_STATUS_DESC_BUFFER_SIZE
#define MICROWAVE_STATUS_TO_STRING_BUFFER_SIZE