gusimplewhiteboard
DominantFrequencies.hpp
Go to the documentation of this file.
1/*
2 * file DominantFrequencies.hpp
3 *
4 * This file was generated by classgenerator from dominant_frequencies.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_DominantFrequencies_h
61#define guWhiteboard_DominantFrequencies_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_DominantFrequencies_DEFINED
73#define guWhiteboard_DominantFrequencies_DEFINED
74
75#undef DominantFrequencies_DEFINED
76#define DominantFrequencies_DEFINED
77
79#include "RMSLevels.h"
80
81namespace guWhiteboard {
82
87
88 private:
89
93 void init(struct wb_r_m_s_levels t_rms = wb_r_m_s_levels(), const struct wb_microphone_frequencies t_frequencies[DOMINANT_NUMFREQi] = NULLPTR) {
94 set_rms(t_rms);
95 if (t_frequencies != NULLPTR) {
97 } else {
100 }
101 }
102
103 public:
104
108 DominantFrequencies(struct wb_r_m_s_levels t_rms = wb_r_m_s_levels(), const struct wb_microphone_frequencies t_frequencies[DOMINANT_NUMFREQi] = NULLPTR) {
109 this->init(t_rms, t_frequencies);
110 }
111
116 this->init(t_other.rms(), t_other.frequencies());
117 }
118
123 this->init(t_other.rms, t_other.frequencies);
124 }
125
130 this->init(t_other.rms(), t_other.frequencies());
131 return *this;
132 }
133
138 this->init(t_other.rms, t_other.frequencies);
139 return *this;
140 }
141
142 bool operator ==(const DominantFrequencies &t_other) const
143 {
144 if (!(RMSLevels(rms()) == RMSLevels(t_other.rms())))
145 {
146 return false;
147 }
148 for (int frequencies_0_index = 0; frequencies_0_index < DOMINANT_NUMFREQi; frequencies_0_index++)
149 {
150 if (!(MicrophoneFrequencies(frequencies(frequencies_0_index)) == MicrophoneFrequencies(t_other.frequencies(frequencies_0_index)))) return false;
151 }
152 return true;
153 }
154
155 bool operator !=(const DominantFrequencies &t_other) const
156 {
157 return !(*this == t_other);
158 }
159
160 bool operator ==(const wb_dominant_frequencies &t_other) const
161 {
162 return *this == DominantFrequencies(t_other);
163 }
164
165 bool operator !=(const wb_dominant_frequencies &t_other) const
166 {
167 return !(*this == t_other);
168 }
169
171 {
172 return const_cast<RMSLevels &>(static_cast<const RMSLevels &>(wb_dominant_frequencies::rms));
173 }
174
175 const RMSLevels & rms() const
176 {
177 return static_cast<const RMSLevels &>(wb_dominant_frequencies::rms);
178 }
179
180 void set_rms(const RMSLevels &t_newValue)
181 {
182 wb_dominant_frequencies::rms = static_cast<wb_r_m_s_levels>(t_newValue);
183 }
184
186 {
187 return static_cast<const MicrophoneFrequencies *>(&(wb_dominant_frequencies::frequencies[0]));
188 }
189
190 size_t frequencies_size() const
191 {
193 }
194
196 {
197 return const_cast<MicrophoneFrequencies &>(static_cast<const MicrophoneFrequencies &>(wb_dominant_frequencies::frequencies[t_i]));
198 }
199
200 const MicrophoneFrequencies & frequencies(int t_i) const
201 {
202 return static_cast<const MicrophoneFrequencies &>(wb_dominant_frequencies::frequencies[t_i]);
203 }
204
206 {
208 }
209
210 void set_frequencies(const MicrophoneFrequencies &t_newValue, int t_i)
211 {
213 }
214
215#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
219 DominantFrequencies(const std::string &t_str) {
220 this->init();
221 this->from_string(t_str);
222 }
223
224 std::string description() {
225#ifdef USE_WB_DOMINANT_FREQUENCIES_C_CONVERSION
227 wb_dominant_frequencies_description(this, buffer, sizeof(buffer));
228 std::string descr = buffer;
229 return descr;
230#else
231 std::ostringstream ss;
232 ss << "rms=" << "{" << RMSLevels(this->rms()).description() << "}";
233 ss << ", ";
234 bool frequencies_first = true;
235 ss << "frequencies={";
236 for (int i = 0; i < DOMINANT_FREQUENCIES_FREQUENCIES_ARRAY_SIZE; i++) {
237 ss << (frequencies_first ? "" : ", ") << "{" << MicrophoneFrequencies(this->frequencies(i)).description() << "}";
238 frequencies_first = false;
239 }
240 ss << "}";
241 return ss.str();
242#endif
243 }
244
245 std::string to_string() {
246#ifdef USE_WB_DOMINANT_FREQUENCIES_C_CONVERSION
248 wb_dominant_frequencies_to_string(this, buffer, sizeof(buffer));
249 std::string toString = buffer;
250 return toString;
251#else
252 std::ostringstream ss;
253 ss << "{" << RMSLevels(this->rms()).to_string() << "}";
254 ss << ", ";
255 bool frequencies_first = true;
256 ss << "{";
257 for (int i = 0; i < DOMINANT_FREQUENCIES_FREQUENCIES_ARRAY_SIZE; i++) {
258 ss << (frequencies_first ? "" : ", ") << "{" << MicrophoneFrequencies(this->frequencies(i)).to_string() << "}";
259 frequencies_first = false;
260 }
261 ss << "}";
262 return ss.str();
263#endif
264 }
265
266#ifdef USE_WB_DOMINANT_FREQUENCIES_C_CONVERSION
267 void from_string(const std::string &t_str) {
268 wb_dominant_frequencies_from_string(this, t_str.c_str());
269#else
270 void from_string(const std::string &t_str) {
271 char * str_cstr = const_cast<char *>(t_str.c_str());
272 size_t temp_length = strlen(str_cstr);
273 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
274 if (length < 1 || length > DOMINANT_FREQUENCIES_DESC_BUFFER_SIZE) {
275 return;
276 }
277 char var_str_buffer[DOMINANT_FREQUENCIES_DESC_BUFFER_SIZE + 1];
278 char* var_str = &var_str_buffer[0];
279 char key_buffer[12];
280 char* key = &key_buffer[0];
281 int bracecount = 0;
282 int lastBrace = -1;
283 int startVar = 0;
284 int index = 0;
285 int startKey = 0;
286 int endKey = -1;
287 int varIndex = 0;
288 if (index == 0 && str_cstr[0] == '{') {
289 index = 1;
290 }
291 startVar = index;
292 startKey = startVar;
293 do {
294 for (int i = index; i < length; i++) {
295 index = i + 1;
296 if (bracecount == 0 && str_cstr[i] == '=') {
297 endKey = i - 1;
298 startVar = index;
299 continue;
300 }
301 if (bracecount == 0 && isspace(str_cstr[i])) {
302 startVar = index;
303 if (endKey == -1) {
304 startKey = index;
305 }
306 continue;
307 }
308 if (bracecount == 0 && str_cstr[i] == ',') {
309 index = i - 1;
310 break;
311 }
312 if (str_cstr[i] == '{') {
313 bracecount++;
314 if (bracecount == 1) {
315 lastBrace = i;
316 }
317 continue;
318 }
319 if (str_cstr[i] == '}') {
320 bracecount--;
321 if (bracecount < 0) {
322 index = i - 1;
323 break;
324 }
325 }
326 if (i == length - 1) {
327 index = i;
328 }
329 }
330 if (endKey >= startKey && endKey - startKey < length) {
331 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
332 key[(endKey - startKey) + 1] = 0;
333 } else {
334 key[0] = 0;
335 }
336 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
337 var_str[(index - startVar) + 1] = 0;
338 bracecount = 0;
339 index += 2;
340 startVar = index;
341 startKey = startVar;
342 endKey = -1;
343 if (strlen(key) > 0) {
344 if (0 == strcmp("rms", key)) {
345 varIndex = 0;
346 } else if (0 == strcmp("frequencies", key)) {
347 varIndex = 1;
348 } else {
349 varIndex = -1;
350 }
351 }
352 switch (varIndex) {
353 case -1: { break; }
354 case 0:
355 {
356 RMSLevels rms_temp = RMSLevels();
357 rms_temp.from_string(var_str);
358 this->set_rms(rms_temp);
359 break;
360 }
361 case 1:
362 {
363 int restartIndex = index;
364 index = lastBrace + 1;
365 startVar = index;
366 startKey = startVar;
367 endKey = -1;
368 bracecount = 0;
369 for (int frequencies_0_index = 0; frequencies_0_index < DOMINANT_FREQUENCIES_FREQUENCIES_ARRAY_SIZE; frequencies_0_index++) {
370 for (int i = index; i < length; i++) {
371 index = i + 1;
372 if (bracecount == 0 && str_cstr[i] == '=') {
373 endKey = i - 1;
374 startVar = index;
375 continue;
376 }
377 if (bracecount == 0 && isspace(str_cstr[i])) {
378 startVar = index;
379 if (endKey == -1) {
380 startKey = index;
381 }
382 continue;
383 }
384 if (bracecount == 0 && str_cstr[i] == ',') {
385 index = i - 1;
386 break;
387 }
388 if (str_cstr[i] == '{') {
389 bracecount++;
390 continue;
391 }
392 if (str_cstr[i] == '}') {
393 bracecount--;
394 if (bracecount < 0) {
395 index = i - 1;
396 break;
397 }
398 }
399 if (i == length - 1) {
400 index = i;
401 }
402 }
403 if (endKey >= startKey && endKey - startKey < length) {
404 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
405 key[(endKey - startKey) + 1] = 0;
406 } else {
407 key[0] = 0;
408 }
409 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
410 var_str[(index - startVar) + 1] = 0;
411 bracecount = 0;
412 index += 2;
413 startVar = index;
414 startKey = startVar;
415 endKey = -1;
416 MicrophoneFrequencies frequencies_0_temp = MicrophoneFrequencies();
417 frequencies_0_temp.from_string(var_str);
418 struct wb_microphone_frequencies frequencies_0 = frequencies_0_temp;
419 this->set_frequencies(frequencies_0, frequencies_0_index);
420 }
421 index = restartIndex;
422 break;
423 }
424 }
425 if (varIndex >= 0) {
426 varIndex++;
427 }
428 } while(index < length);
429#endif
430 }
431#endif
432
433 static int num_frequencies() { return DOMINANT_NUMFREQi; }
434 };
435
436}
437
438#endif
Provides a C++ wrapper around wb_dominant_frequencies.
MicrophoneFrequencies & frequencies(int t_i)
bool operator!=(const DominantFrequencies &t_other) const
bool operator==(const DominantFrequencies &t_other) const
void set_frequencies(const MicrophoneFrequencies &t_newValue, int t_i)
DominantFrequencies(const DominantFrequencies &t_other)
Copy Constructor.
DominantFrequencies(const std::string &t_str)
String Constructor.
void set_frequencies(const MicrophoneFrequencies *t_newValue)
const MicrophoneFrequencies & frequencies(int t_i) const
DominantFrequencies(struct wb_r_m_s_levels t_rms=wb_r_m_s_levels(), const struct wb_microphone_frequencies t_frequencies[static_cast< int >(((GU_SIMPLE_WHITEBOARD_BUFSIZE - sizeof(struct wb_r_m_s_levels))/sizeof(struct wb_microphone_frequencies)))]=NULLPTR)
Create a new DominantFrequencies.
void from_string(const std::string &t_str)
DominantFrequencies & operator=(const DominantFrequencies &t_other)
Copy Assignment Operator.
const MicrophoneFrequencies * frequencies() const
static int num_frequencies()
WHITEBOARD_POSTER_STRING_CONVERSION.
DominantFrequencies(const struct wb_dominant_frequencies &t_other)
Copy Constructor.
void set_rms(const RMSLevels &t_newValue)
Provides a C++ wrapper around wb_microphone_frequencies.
void from_string(const std::string &t_str)
Provides a C++ wrapper around wb_r_m_s_levels.
Definition: RMSLevels.hpp:83
std::string to_string()
Definition: RMSLevels.hpp:247
std::string description()
Definition: RMSLevels.hpp:228
void from_string(const std::string &t_str)
Definition: RMSLevels.hpp:270
/file APM_Interface.h
Frequency quadruple for rear and front stereo channels.
struct wb_microphone_frequencies frequencies[static_cast< int >(((GU_SIMPLE_WHITEBOARD_BUFSIZE - sizeof(struct wb_r_m_s_levels))/sizeof(struct wb_microphone_frequencies)))]
dominant frequencies
struct wb_r_m_s_levels rms
RMS levels of dominant frequency.
WHITEBOARD_POSTER_STRING_CONVERSION.
WHITEBOARD_POSTER_STRING_CONVERSION.
const char * wb_dominant_frequencies_description(const struct wb_dominant_frequencies *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_dominant_frequencies_to_string(const struct wb_dominant_frequencies *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_dominant_frequencies * wb_dominant_frequencies_from_string(struct wb_dominant_frequencies *self, const char *str)
Convert from a string.
#define DOMINANT_NUMFREQi
#define DOMINANT_FREQUENCIES_FREQUENCIES_ARRAY_SIZE
WHITEBOARD_POSTER_STRING_CONVERSION.
#define DOMINANT_FREQUENCIES_DESC_BUFFER_SIZE
#define DOMINANT_FREQUENCIES_TO_STRING_BUFFER_SIZE