gusimplewhiteboard
FrequencyLimits.hpp
Go to the documentation of this file.
1/*
2 * file FrequencyLimits.hpp
3 *
4 * This file was generated by classgenerator from frequency_limits.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Rene Hexel. 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 Rene Hexel.
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_FrequencyLimits_h
61#define guWhiteboard_FrequencyLimits_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_frequency_limits.h"
71
72#undef guWhiteboard_FrequencyLimits_DEFINED
73#define guWhiteboard_FrequencyLimits_DEFINED
74
75#undef FrequencyLimits_DEFINED
76#define FrequencyLimits_DEFINED
77
78namespace guWhiteboard {
79
84
85 private:
86
90 void init(int16_t t_lo_freq = 0, int16_t t_hi_freq = 0) {
91 set_lo_freq(t_lo_freq);
92 set_hi_freq(t_hi_freq);
93 }
94
95 public:
96
100 FrequencyLimits(int16_t t_lo_freq = 0, int16_t t_hi_freq = 0) {
101 this->init(t_lo_freq, t_hi_freq);
102 }
103
108 this->init(t_other.lo_freq(), t_other.hi_freq());
109 }
110
115 this->init(t_other.lo_freq, t_other.hi_freq);
116 }
117
122 this->init(t_other.lo_freq(), t_other.hi_freq());
123 return *this;
124 }
125
130 this->init(t_other.lo_freq, t_other.hi_freq);
131 return *this;
132 }
133
134 bool operator ==(const FrequencyLimits &t_other) const
135 {
136 return lo_freq() == t_other.lo_freq()
137 && hi_freq() == t_other.hi_freq();
138 }
139
140 bool operator !=(const FrequencyLimits &t_other) const
141 {
142 return !(*this == t_other);
143 }
144
145 bool operator ==(const wb_frequency_limits &t_other) const
146 {
147 return *this == FrequencyLimits(t_other);
148 }
149
150 bool operator !=(const wb_frequency_limits &t_other) const
151 {
152 return !(*this == t_other);
153 }
154
155 int16_t & lo_freq()
156 {
158 }
159
160 const int16_t & lo_freq() const
161 {
163 }
164
165 void set_lo_freq(const int16_t &t_newValue)
166 {
167 wb_frequency_limits::lo_freq = t_newValue;
168 }
169
170 int16_t & hi_freq()
171 {
173 }
174
175 const int16_t & hi_freq() const
176 {
178 }
179
180 void set_hi_freq(const int16_t &t_newValue)
181 {
182 wb_frequency_limits::hi_freq = t_newValue;
183 }
184
185#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
189 FrequencyLimits(const std::string &t_str) {
190 this->init();
191 this->from_string(t_str);
192 }
193
194 std::string description() {
195#ifdef USE_WB_FREQUENCY_LIMITS_C_CONVERSION
197 wb_frequency_limits_description(this, buffer, sizeof(buffer));
198 std::string descr = buffer;
199 return descr;
200#else
201 std::ostringstream ss;
202 ss << "lo_freq=" << static_cast<signed>(this->lo_freq());
203 ss << ", ";
204 ss << "hi_freq=" << static_cast<signed>(this->hi_freq());
205 return ss.str();
206#endif
207 }
208
209 std::string to_string() {
210#ifdef USE_WB_FREQUENCY_LIMITS_C_CONVERSION
212 wb_frequency_limits_to_string(this, buffer, sizeof(buffer));
213 std::string toString = buffer;
214 return toString;
215#else
216 std::ostringstream ss;
217 ss << static_cast<signed>(this->lo_freq());
218 ss << ", ";
219 ss << static_cast<signed>(this->hi_freq());
220 return ss.str();
221#endif
222 }
223
224#ifdef USE_WB_FREQUENCY_LIMITS_C_CONVERSION
225 void from_string(const std::string &t_str) {
226 wb_frequency_limits_from_string(this, t_str.c_str());
227#else
228 void from_string(const std::string &t_str) {
229 char * str_cstr = const_cast<char *>(t_str.c_str());
230 size_t temp_length = strlen(str_cstr);
231 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
232 if (length < 1 || length > FREQUENCY_LIMITS_DESC_BUFFER_SIZE) {
233 return;
234 }
235 char var_str_buffer[FREQUENCY_LIMITS_DESC_BUFFER_SIZE + 1];
236 char* var_str = &var_str_buffer[0];
237 char key_buffer[8];
238 char* key = &key_buffer[0];
239 int bracecount = 0;
240 int startVar = 0;
241 int index = 0;
242 int startKey = 0;
243 int endKey = -1;
244 int varIndex = 0;
245 if (index == 0 && str_cstr[0] == '{') {
246 index = 1;
247 }
248 startVar = index;
249 startKey = startVar;
250 do {
251 for (int i = index; i < length; i++) {
252 index = i + 1;
253 if (bracecount == 0 && str_cstr[i] == '=') {
254 endKey = i - 1;
255 startVar = index;
256 continue;
257 }
258 if (bracecount == 0 && isspace(str_cstr[i])) {
259 startVar = index;
260 if (endKey == -1) {
261 startKey = index;
262 }
263 continue;
264 }
265 if (bracecount == 0 && str_cstr[i] == ',') {
266 index = i - 1;
267 break;
268 }
269 if (str_cstr[i] == '{') {
270 bracecount++;
271 continue;
272 }
273 if (str_cstr[i] == '}') {
274 bracecount--;
275 if (bracecount < 0) {
276 index = i - 1;
277 break;
278 }
279 }
280 if (i == length - 1) {
281 index = i;
282 }
283 }
284 if (endKey >= startKey && endKey - startKey < length) {
285 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
286 key[(endKey - startKey) + 1] = 0;
287 } else {
288 key[0] = 0;
289 }
290 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
291 var_str[(index - startVar) + 1] = 0;
292 bracecount = 0;
293 index += 2;
294 startVar = index;
295 startKey = startVar;
296 endKey = -1;
297 if (strlen(key) > 0) {
298 if (0 == strcmp("lo_freq", key)) {
299 varIndex = 0;
300 } else if (0 == strcmp("hi_freq", key)) {
301 varIndex = 1;
302 } else {
303 varIndex = -1;
304 }
305 }
306 switch (varIndex) {
307 case -1: { break; }
308 case 0:
309 {
310 this->set_lo_freq(static_cast<int16_t>(atoi(var_str)));
311 break;
312 }
313 case 1:
314 {
315 this->set_hi_freq(static_cast<int16_t>(atoi(var_str)));
316 break;
317 }
318 }
319 if (varIndex >= 0) {
320 varIndex++;
321 }
322 } while(index < length);
323#endif
324 }
325#endif
326 };
327
328}
329
330#endif
Provides a C++ wrapper around wb_frequency_limits.
const int16_t & lo_freq() const
void set_hi_freq(const int16_t &t_newValue)
FrequencyLimits(const struct wb_frequency_limits &t_other)
Copy Constructor.
FrequencyLimits(int16_t t_lo_freq=0, int16_t t_hi_freq=0)
Create a new FrequencyLimits.
FrequencyLimits & operator=(const FrequencyLimits &t_other)
Copy Assignment Operator.
const int16_t & hi_freq() const
void set_lo_freq(const int16_t &t_newValue)
bool operator==(const FrequencyLimits &t_other) const
FrequencyLimits(const std::string &t_str)
String Constructor.
bool operator!=(const FrequencyLimits &t_other) const
void from_string(const std::string &t_str)
FrequencyLimits(const FrequencyLimits &t_other)
Copy Constructor.
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
int16_t hi_freq
high frequency bound in Hz
int16_t lo_freq
low frequency bound in Hz
const char * wb_frequency_limits_to_string(const struct wb_frequency_limits *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_frequency_limits * wb_frequency_limits_from_string(struct wb_frequency_limits *self, const char *str)
Convert from a string.
const char * wb_frequency_limits_description(const struct wb_frequency_limits *self, char *descString, size_t bufferSize)
Convert to a description string.
#define FREQUENCY_LIMITS_DESC_BUFFER_SIZE
#define FREQUENCY_LIMITS_TO_STRING_BUFFER_SIZE