gusimplewhiteboard
PixelCoordinate.hpp
Go to the documentation of this file.
1/*
2 * file PixelCoordinate.hpp
3 *
4 * This file was generated by classgenerator from pixel_coordinate.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_PixelCoordinate_h
61#define guWhiteboard_PixelCoordinate_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_pixel_coordinate.h"
71
72#undef guWhiteboard_PixelCoordinate_DEFINED
73#define guWhiteboard_PixelCoordinate_DEFINED
74
75#undef PixelCoordinate_DEFINED
76#define PixelCoordinate_DEFINED
77
78#include <guunits/guunits.h>
79#include <gucoordinates/gucoordinates.h>
80
81namespace guWhiteboard {
82
87
88 private:
89
93 void init(int16_t t_x = 0, int16_t t_y = 0) {
94 set_x(t_x);
95 set_y(t_y);
96 }
97
98 public:
99
103 PixelCoordinate(int16_t t_x = 0, int16_t t_y = 0) {
104 this->init(t_x, t_y);
105 }
106
111 this->init(t_other.x(), t_other.y());
112 }
113
118 this->init(t_other.x, t_other.y);
119 }
120
125 this->init(t_other.x(), t_other.y());
126 return *this;
127 }
128
133 this->init(t_other.x, t_other.y);
134 return *this;
135 }
136
137 bool operator ==(const PixelCoordinate &t_other) const
138 {
139 return x() == t_other.x()
140 && y() == t_other.y();
141 }
142
143 bool operator !=(const PixelCoordinate &t_other) const
144 {
145 return !(*this == t_other);
146 }
147
148 bool operator ==(const wb_pixel_coordinate &t_other) const
149 {
150 return *this == PixelCoordinate(t_other);
151 }
152
153 bool operator !=(const wb_pixel_coordinate &t_other) const
154 {
155 return !(*this == t_other);
156 }
157
158 int16_t & x()
159 {
161 }
162
163 const int16_t & x() const
164 {
166 }
167
168 void set_x(const int16_t &t_newValue)
169 {
170 wb_pixel_coordinate::x = t_newValue;
171 }
172
173 int16_t & y()
174 {
176 }
177
178 const int16_t & y() const
179 {
181 }
182
183 void set_y(const int16_t &t_newValue)
184 {
185 wb_pixel_coordinate::y = t_newValue;
186 }
187
188#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
192 PixelCoordinate(const std::string &t_str) {
193 this->init();
194 this->from_string(t_str);
195 }
196
197 std::string description() {
198#ifdef USE_WB_PIXEL_COORDINATE_C_CONVERSION
200 wb_pixel_coordinate_description(this, buffer, sizeof(buffer));
201 std::string descr = buffer;
202 return descr;
203#else
204 std::ostringstream ss;
205 ss << "x=" << static_cast<signed>(this->x());
206 ss << ", ";
207 ss << "y=" << static_cast<signed>(this->y());
208 return ss.str();
209#endif
210 }
211
212 std::string to_string() {
213#ifdef USE_WB_PIXEL_COORDINATE_C_CONVERSION
215 wb_pixel_coordinate_to_string(this, buffer, sizeof(buffer));
216 std::string toString = buffer;
217 return toString;
218#else
219 std::ostringstream ss;
220 ss << static_cast<signed>(this->x());
221 ss << ", ";
222 ss << static_cast<signed>(this->y());
223 return ss.str();
224#endif
225 }
226
227#ifdef USE_WB_PIXEL_COORDINATE_C_CONVERSION
228 void from_string(const std::string &t_str) {
229 wb_pixel_coordinate_from_string(this, t_str.c_str());
230#else
231 void from_string(const std::string &t_str) {
232 char * str_cstr = const_cast<char *>(t_str.c_str());
233 size_t temp_length = strlen(str_cstr);
234 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
235 if (length < 1 || length > PIXEL_COORDINATE_DESC_BUFFER_SIZE) {
236 return;
237 }
238 char var_str_buffer[PIXEL_COORDINATE_DESC_BUFFER_SIZE + 1];
239 char* var_str = &var_str_buffer[0];
240 char key_buffer[2];
241 char* key = &key_buffer[0];
242 int bracecount = 0;
243 int startVar = 0;
244 int index = 0;
245 int startKey = 0;
246 int endKey = -1;
247 int varIndex = 0;
248 if (index == 0 && str_cstr[0] == '{') {
249 index = 1;
250 }
251 startVar = index;
252 startKey = startVar;
253 do {
254 for (int i = index; i < length; i++) {
255 index = i + 1;
256 if (bracecount == 0 && str_cstr[i] == '=') {
257 endKey = i - 1;
258 startVar = index;
259 continue;
260 }
261 if (bracecount == 0 && isspace(str_cstr[i])) {
262 startVar = index;
263 if (endKey == -1) {
264 startKey = index;
265 }
266 continue;
267 }
268 if (bracecount == 0 && str_cstr[i] == ',') {
269 index = i - 1;
270 break;
271 }
272 if (str_cstr[i] == '{') {
273 bracecount++;
274 continue;
275 }
276 if (str_cstr[i] == '}') {
277 bracecount--;
278 if (bracecount < 0) {
279 index = i - 1;
280 break;
281 }
282 }
283 if (i == length - 1) {
284 index = i;
285 }
286 }
287 if (endKey >= startKey && endKey - startKey < length) {
288 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
289 key[(endKey - startKey) + 1] = 0;
290 } else {
291 key[0] = 0;
292 }
293 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
294 var_str[(index - startVar) + 1] = 0;
295 bracecount = 0;
296 index += 2;
297 startVar = index;
298 startKey = startVar;
299 endKey = -1;
300 if (strlen(key) > 0) {
301 if (0 == strcmp("x", key)) {
302 varIndex = 0;
303 } else if (0 == strcmp("y", key)) {
304 varIndex = 1;
305 } else {
306 varIndex = -1;
307 }
308 }
309 switch (varIndex) {
310 case -1: { break; }
311 case 0:
312 {
313 this->set_x(static_cast<int16_t>(atoi(var_str)));
314 break;
315 }
316 case 1:
317 {
318 this->set_y(static_cast<int16_t>(atoi(var_str)));
319 break;
320 }
321 }
322 if (varIndex >= 0) {
323 varIndex++;
324 }
325 } while(index < length);
326#endif
327 }
328#endif
329
330 PixelCoordinate(const GU::PixelCoordinate &other) {
331 this->init(px_t_to_i16(other.x()), px_t_to_i16(other.y()));
332 }
333
334 PixelCoordinate(const ::gu_pixel_coordinate &other) {
335 this->init(px_t_to_i16(other.x), px_t_to_i16(other.y));
336 }
337
338 GU::PixelCoordinate pixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
339 {
340 return GU::PixelCoordinate(wb_px_coord_to_px_coord(*this, resWidth, resHeight));
341 }
342 };
343
344}
345
346#endif
Provides a C++ wrapper around wb_pixel_coordinate.
const int16_t & y() const
const int16_t & x() const
PixelCoordinate & operator=(const PixelCoordinate &t_other)
Copy Assignment Operator.
PixelCoordinate(const struct wb_pixel_coordinate &t_other)
Copy Constructor.
void from_string(const std::string &t_str)
bool operator!=(const PixelCoordinate &t_other) const
PixelCoordinate(const std::string &t_str)
String Constructor.
void set_y(const int16_t &t_newValue)
PixelCoordinate(const GU::PixelCoordinate &other)
WHITEBOARD_POSTER_STRING_CONVERSION.
PixelCoordinate(int16_t t_x=0, int16_t t_y=0)
Create a new PixelCoordinate.
PixelCoordinate(const PixelCoordinate &t_other)
Copy Constructor.
bool operator==(const PixelCoordinate &t_other) const
PixelCoordinate(const ::gu_pixel_coordinate &other)
GU::PixelCoordinate pixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
void set_x(const int16_t &t_newValue)
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
int16_t y
The y coordinate.
int16_t x
The x coordinate.
const char * wb_pixel_coordinate_description(const struct wb_pixel_coordinate *self, char *descString, size_t bufferSize)
Convert to a description string.
struct wb_pixel_coordinate * wb_pixel_coordinate_from_string(struct wb_pixel_coordinate *self, const char *str)
Convert from a string.
const char * wb_pixel_coordinate_to_string(const struct wb_pixel_coordinate *self, char *toString, size_t bufferSize)
Convert to a string.
gu_pixel_coordinate wb_px_coord_to_px_coord(const struct wb_pixel_coordinate coord, const uint16_t resWidth, const uint16_t resHeight)
#define PIXEL_COORDINATE_DESC_BUFFER_SIZE
#define PIXEL_COORDINATE_TO_STRING_BUFFER_SIZE