gusimplewhiteboard
PixelCoordinateLine.hpp
Go to the documentation of this file.
1/*
2 * file PixelCoordinateLine.hpp
3 *
4 * This file was generated by classgenerator from pixel_coordinate_line.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Carl Lusty. 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 Carl Lusty.
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_PixelCoordinateLine_h
61#define guWhiteboard_PixelCoordinateLine_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_PixelCoordinateLine_DEFINED
73#define guWhiteboard_PixelCoordinateLine_DEFINED
74
75#undef PixelCoordinateLine_DEFINED
76#define PixelCoordinateLine_DEFINED
77
78#include "PixelCoordinate.h"
79
80#include <guunits/guunits.h>
81#include <gucoordinates/gucoordinates.h>
82#include "PixelCoordinate.h"
83
84#include <guunits/guunits.h>
85#include <gucoordinates/gucoordinates.h>
86
87namespace guWhiteboard {
88
93
94 private:
95
99 void init(struct wb_pixel_coordinate t_start = wb_pixel_coordinate(), struct wb_pixel_coordinate t_end = wb_pixel_coordinate()) {
100 set_start(t_start);
101 set_end(t_end);
102 }
103
104 public:
105
110 this->init(t_start, t_end);
111 }
112
117 this->init(t_other.start(), t_other.end());
118 }
119
124 this->init(t_other.start, t_other.end);
125 }
126
131 this->init(t_other.start(), t_other.end());
132 return *this;
133 }
134
139 this->init(t_other.start, t_other.end);
140 return *this;
141 }
142
143 bool operator ==(const PixelCoordinateLine &t_other) const
144 {
145 return PixelCoordinate(start()) == PixelCoordinate(t_other.start())
146 && PixelCoordinate(end()) == PixelCoordinate(t_other.end());
147 }
148
149 bool operator !=(const PixelCoordinateLine &t_other) const
150 {
151 return !(*this == t_other);
152 }
153
154 bool operator ==(const wb_pixel_coordinate_line &t_other) const
155 {
156 return *this == PixelCoordinateLine(t_other);
157 }
158
159 bool operator !=(const wb_pixel_coordinate_line &t_other) const
160 {
161 return !(*this == t_other);
162 }
163
165 {
166 return const_cast<PixelCoordinate &>(static_cast<const PixelCoordinate &>(wb_pixel_coordinate_line::start));
167 }
168
169 const PixelCoordinate & start() const
170 {
171 return static_cast<const PixelCoordinate &>(wb_pixel_coordinate_line::start);
172 }
173
174 void set_start(const PixelCoordinate &t_newValue)
175 {
176 wb_pixel_coordinate_line::start = static_cast<wb_pixel_coordinate>(t_newValue);
177 }
178
180 {
181 return const_cast<PixelCoordinate &>(static_cast<const PixelCoordinate &>(wb_pixel_coordinate_line::end));
182 }
183
184 const PixelCoordinate & end() const
185 {
186 return static_cast<const PixelCoordinate &>(wb_pixel_coordinate_line::end);
187 }
188
189 void set_end(const PixelCoordinate &t_newValue)
190 {
191 wb_pixel_coordinate_line::end = static_cast<wb_pixel_coordinate>(t_newValue);
192 }
193
194#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
198 PixelCoordinateLine(const std::string &t_str) {
199 this->init();
200 this->from_string(t_str);
201 }
202
203 std::string description() {
204#ifdef USE_WB_PIXEL_COORDINATE_LINE_C_CONVERSION
206 wb_pixel_coordinate_line_description(this, buffer, sizeof(buffer));
207 std::string descr = buffer;
208 return descr;
209#else
210 std::ostringstream ss;
211 ss << "start=" << "{" << PixelCoordinate(this->start()).description() << "}";
212 ss << ", ";
213 ss << "end=" << "{" << PixelCoordinate(this->end()).description() << "}";
214 return ss.str();
215#endif
216 }
217
218 std::string to_string() {
219#ifdef USE_WB_PIXEL_COORDINATE_LINE_C_CONVERSION
221 wb_pixel_coordinate_line_to_string(this, buffer, sizeof(buffer));
222 std::string toString = buffer;
223 return toString;
224#else
225 std::ostringstream ss;
226 ss << "{" << PixelCoordinate(this->start()).to_string() << "}";
227 ss << ", ";
228 ss << "{" << PixelCoordinate(this->end()).to_string() << "}";
229 return ss.str();
230#endif
231 }
232
233#ifdef USE_WB_PIXEL_COORDINATE_LINE_C_CONVERSION
234 void from_string(const std::string &t_str) {
235 wb_pixel_coordinate_line_from_string(this, t_str.c_str());
236#else
237 void from_string(const std::string &t_str) {
238 char * str_cstr = const_cast<char *>(t_str.c_str());
239 size_t temp_length = strlen(str_cstr);
240 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
241 if (length < 1 || length > PIXEL_COORDINATE_LINE_DESC_BUFFER_SIZE) {
242 return;
243 }
244 char var_str_buffer[PIXEL_COORDINATE_LINE_DESC_BUFFER_SIZE + 1];
245 char* var_str = &var_str_buffer[0];
246 char key_buffer[6];
247 char* key = &key_buffer[0];
248 int bracecount = 0;
249 int startVar = 0;
250 int index = 0;
251 int startKey = 0;
252 int endKey = -1;
253 int varIndex = 0;
254 if (index == 0 && str_cstr[0] == '{') {
255 index = 1;
256 }
257 startVar = index;
258 startKey = startVar;
259 do {
260 for (int i = index; i < length; i++) {
261 index = i + 1;
262 if (bracecount == 0 && str_cstr[i] == '=') {
263 endKey = i - 1;
264 startVar = index;
265 continue;
266 }
267 if (bracecount == 0 && isspace(str_cstr[i])) {
268 startVar = index;
269 if (endKey == -1) {
270 startKey = index;
271 }
272 continue;
273 }
274 if (bracecount == 0 && str_cstr[i] == ',') {
275 index = i - 1;
276 break;
277 }
278 if (str_cstr[i] == '{') {
279 bracecount++;
280 continue;
281 }
282 if (str_cstr[i] == '}') {
283 bracecount--;
284 if (bracecount < 0) {
285 index = i - 1;
286 break;
287 }
288 }
289 if (i == length - 1) {
290 index = i;
291 }
292 }
293 if (endKey >= startKey && endKey - startKey < length) {
294 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
295 key[(endKey - startKey) + 1] = 0;
296 } else {
297 key[0] = 0;
298 }
299 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
300 var_str[(index - startVar) + 1] = 0;
301 bracecount = 0;
302 index += 2;
303 startVar = index;
304 startKey = startVar;
305 endKey = -1;
306 if (strlen(key) > 0) {
307 if (0 == strcmp("start", key)) {
308 varIndex = 0;
309 } else if (0 == strcmp("end", key)) {
310 varIndex = 1;
311 } else {
312 varIndex = -1;
313 }
314 }
315 switch (varIndex) {
316 case -1: { break; }
317 case 0:
318 {
319 PixelCoordinate start_temp = PixelCoordinate();
320 start_temp.from_string(var_str);
321 this->set_start(start_temp);
322 break;
323 }
324 case 1:
325 {
326 PixelCoordinate end_temp = PixelCoordinate();
327 end_temp.from_string(var_str);
328 this->set_end(end_temp);
329 break;
330 }
331 }
332 if (varIndex >= 0) {
333 varIndex++;
334 }
335 } while(index < length);
336#endif
337 }
338#endif
339
340 GU::PixelCoordinate startPixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
341 {
342 return PixelCoordinate(start()).pixelCoordinate(resWidth, resHeight);
343 }
344 GU::PixelCoordinate endPixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
345 {
346 return PixelCoordinate(end()).pixelCoordinate(resWidth, resHeight);
347 }
348 };
349
350}
351
352#endif
Provides a C++ wrapper around wb_pixel_coordinate.
void from_string(const std::string &t_str)
GU::PixelCoordinate pixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
Provides a C++ wrapper around wb_pixel_coordinate_line.
PixelCoordinateLine(const std::string &t_str)
String Constructor.
bool operator==(const PixelCoordinateLine &t_other) const
const PixelCoordinate & end() const
bool operator!=(const PixelCoordinateLine &t_other) const
void set_start(const PixelCoordinate &t_newValue)
void set_end(const PixelCoordinate &t_newValue)
PixelCoordinateLine(const struct wb_pixel_coordinate_line &t_other)
Copy Constructor.
const PixelCoordinate & start() const
void from_string(const std::string &t_str)
PixelCoordinateLine & operator=(const PixelCoordinateLine &t_other)
Copy Assignment Operator.
GU::PixelCoordinate startPixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
WHITEBOARD_POSTER_STRING_CONVERSION.
PixelCoordinateLine(const PixelCoordinateLine &t_other)
Copy Constructor.
PixelCoordinateLine(struct wb_pixel_coordinate t_start=wb_pixel_coordinate(), struct wb_pixel_coordinate t_end=wb_pixel_coordinate())
Create a new PixelCoordinateLine.
GU::PixelCoordinate endPixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
struct wb_pixel_coordinate end
End point of the line.
struct wb_pixel_coordinate start
Start point of the line.
WHITEBOARD_POSTER_STRING_CONVERSION.
struct wb_pixel_coordinate_line * wb_pixel_coordinate_line_from_string(struct wb_pixel_coordinate_line *self, const char *str)
Convert from a string.
const char * wb_pixel_coordinate_line_to_string(const struct wb_pixel_coordinate_line *self, char *toString, size_t bufferSize)
Convert to a string.
const char * wb_pixel_coordinate_line_description(const struct wb_pixel_coordinate_line *self, char *descString, size_t bufferSize)
Convert to a description string.
#define PIXEL_COORDINATE_LINE_TO_STRING_BUFFER_SIZE
#define PIXEL_COORDINATE_LINE_DESC_BUFFER_SIZE