gusimplewhiteboard
Count.hpp
Go to the documentation of this file.
1/*
2 * file Count.hpp
3 *
4 * This file was generated by classgenerator from count.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_Count_h
61#define guWhiteboard_Count_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_count.h"
71
72#undef guWhiteboard_Count_DEFINED
73#define guWhiteboard_Count_DEFINED
74
75#undef Count_DEFINED
76#define Count_DEFINED
77
78namespace guWhiteboard {
79
83 class Count: public wb_count {
84
85 private:
86
90 void init(int64_t t_count = 0) {
91 set_count(t_count);
92 }
93
94 public:
95
99 Count(int64_t t_count = 0) {
100 this->init(t_count);
101 }
102
106 Count(const Count &t_other): wb_count() {
107 this->init(t_other.count());
108 }
109
113 Count(const struct wb_count &t_other): wb_count() {
114 this->init(t_other.count);
115 }
116
120 Count &operator = (const Count &t_other) {
121 this->init(t_other.count());
122 return *this;
123 }
124
128 Count &operator = (const struct wb_count &t_other) {
129 this->init(t_other.count);
130 return *this;
131 }
132
133 bool operator ==(const Count &t_other) const
134 {
135 return count() == t_other.count();
136 }
137
138 bool operator !=(const Count &t_other) const
139 {
140 return !(*this == t_other);
141 }
142
143 bool operator ==(const wb_count &t_other) const
144 {
145 return *this == Count(t_other);
146 }
147
148 bool operator !=(const wb_count &t_other) const
149 {
150 return !(*this == t_other);
151 }
152
153 int64_t & count()
154 {
155 return wb_count::count;
156 }
157
158 const int64_t & count() const
159 {
160 return wb_count::count;
161 }
162
163 void set_count(const int64_t &t_newValue)
164 {
165 wb_count::count = t_newValue;
166 }
167
168#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
172 Count(const std::string &t_str) {
173 this->init();
174 this->from_string(t_str);
175 }
176
177 std::string description() {
178#ifdef USE_WB_COUNT_C_CONVERSION
179 char buffer[COUNT_DESC_BUFFER_SIZE];
180 wb_count_description(this, buffer, sizeof(buffer));
181 std::string descr = buffer;
182 return descr;
183#else
184 std::ostringstream ss;
185 ss << "count=" << this->count();
186 return ss.str();
187#endif
188 }
189
190 std::string to_string() {
191#ifdef USE_WB_COUNT_C_CONVERSION
192 char buffer[COUNT_TO_STRING_BUFFER_SIZE];
193 wb_count_to_string(this, buffer, sizeof(buffer));
194 std::string toString = buffer;
195 return toString;
196#else
197 std::ostringstream ss;
198 ss << this->count();
199 return ss.str();
200#endif
201 }
202
203#ifdef USE_WB_COUNT_C_CONVERSION
204 void from_string(const std::string &t_str) {
205 wb_count_from_string(this, t_str.c_str());
206#else
207 void from_string(const std::string &t_str) {
208 char * str_cstr = const_cast<char *>(t_str.c_str());
209 size_t temp_length = strlen(str_cstr);
210 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
211 if (length < 1 || length > COUNT_DESC_BUFFER_SIZE) {
212 return;
213 }
214 char var_str_buffer[COUNT_DESC_BUFFER_SIZE + 1];
215 char* var_str = &var_str_buffer[0];
216 char key_buffer[6];
217 char* key = &key_buffer[0];
218 int bracecount = 0;
219 int startVar = 0;
220 int index = 0;
221 int startKey = 0;
222 int endKey = -1;
223 int varIndex = 0;
224 if (index == 0 && str_cstr[0] == '{') {
225 index = 1;
226 }
227 startVar = index;
228 startKey = startVar;
229 do {
230 for (int i = index; i < length; i++) {
231 index = i + 1;
232 if (bracecount == 0 && str_cstr[i] == '=') {
233 endKey = i - 1;
234 startVar = index;
235 continue;
236 }
237 if (bracecount == 0 && isspace(str_cstr[i])) {
238 startVar = index;
239 if (endKey == -1) {
240 startKey = index;
241 }
242 continue;
243 }
244 if (bracecount == 0 && str_cstr[i] == ',') {
245 index = i - 1;
246 break;
247 }
248 if (str_cstr[i] == '{') {
249 bracecount++;
250 continue;
251 }
252 if (str_cstr[i] == '}') {
253 bracecount--;
254 if (bracecount < 0) {
255 index = i - 1;
256 break;
257 }
258 }
259 if (i == length - 1) {
260 index = i;
261 }
262 }
263 if (endKey >= startKey && endKey - startKey < length) {
264 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
265 key[(endKey - startKey) + 1] = 0;
266 } else {
267 key[0] = 0;
268 }
269 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
270 var_str[(index - startVar) + 1] = 0;
271 bracecount = 0;
272 index += 2;
273 startVar = index;
274 startKey = startVar;
275 endKey = -1;
276 if (strlen(key) > 0) {
277 if (0 == strcmp("count", key)) {
278 varIndex = 0;
279 } else {
280 varIndex = -1;
281 }
282 }
283 switch (varIndex) {
284 case -1: { break; }
285 case 0:
286 {
287#ifdef __APPLE__
288 this->set_count(static_cast<int64_t>(atoll(var_str)));
289#else
290 this->set_count(static_cast<int64_t>(atol(var_str)));
291#endif
292 break;
293 }
294 }
295 if (varIndex >= 0) {
296 varIndex++;
297 }
298 } while(index < length);
299#endif
300 }
301#endif
302 };
303
304}
305
306#endif
Provides a C++ wrapper around wb_count.
Definition: Count.hpp:83
Count(const Count &t_other)
Copy Constructor.
Definition: Count.hpp:106
std::string to_string()
Definition: Count.hpp:190
int64_t & count()
Definition: Count.hpp:153
bool operator==(const Count &t_other) const
Definition: Count.hpp:133
Count & operator=(const Count &t_other)
Copy Assignment Operator.
Definition: Count.hpp:120
void from_string(const std::string &t_str)
Definition: Count.hpp:207
void set_count(const int64_t &t_newValue)
Definition: Count.hpp:163
Count(const std::string &t_str)
String Constructor.
Definition: Count.hpp:172
Count(int64_t t_count=0)
Create a new Count.
Definition: Count.hpp:99
std::string description()
Definition: Count.hpp:177
Count(const struct wb_count &t_other)
Copy Constructor.
Definition: Count.hpp:113
bool operator!=(const Count &t_other) const
Definition: Count.hpp:138
const int64_t & count() const
Definition: Count.hpp:158
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
Definition: wb_count.h:105
int64_t count
The count.
Definition: wb_count.h:110
const char * wb_count_to_string(const struct wb_count *self, char *toString, size_t bufferSize)
Convert to a string.
Definition: wb_count.c:145
const char * wb_count_description(const struct wb_count *self, char *descString, size_t bufferSize)
Convert to a description string.
Definition: wb_count.c:125
struct wb_count * wb_count_from_string(struct wb_count *self, const char *str)
Convert from a string.
Definition: wb_count.c:165
#define COUNT_DESC_BUFFER_SIZE
Definition: wb_count.h:93
#define COUNT_TO_STRING_BUFFER_SIZE
Definition: wb_count.h:94