WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
DynamicStruct.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <stdint.h>
8
9#include <cassert>
10#include <span>
11#include <string>
12#include <string_view>
13#include <utility>
14#include <vector>
15
17#include "wpi/util/bit.hpp"
18
19namespace wpi::util {
20
21template <typename T>
22class SmallVectorImpl;
23
24class DynamicStruct;
28
29/**
30 * Known data types for raw struct dynamic fields (see StructFieldDescriptor).
31 */
32enum class StructFieldType {
33 /// bool.
35 /// char.
37 /// int8.
39 /// int16.
41 /// int32.
43 /// int64.
45 /// uint8.
47 /// uint16.
49 /// uint32.
51 /// uint64.
53 /// float.
55 /// double.
57 /// struct.
59};
60
61/**
62 * Raw struct dynamic field descriptor.
63 */
65 struct private_init {};
66 friend class DynamicStruct;
68 friend class StructDescriptor;
70
71 public:
72 /**
73 * Set of enumerated values.
74 */
75 using EnumValues = std::vector<std::pair<std::string, int64_t>>;
76
77 StructFieldDescriptor(const StructDescriptor* parent, std::string_view name,
78 StructFieldType type, size_t size, size_t arraySize,
79 unsigned int bitWidth, EnumValues enumValues,
80 const StructDescriptor* structDesc,
81 const private_init&);
82
83 /**
84 * Gets the dynamic struct this field is contained in.
85 *
86 * @return struct descriptor
87 */
88 const StructDescriptor* GetParent() const { return m_parent; }
89
90 /**
91 * Gets the field name.
92 *
93 * @return field name
94 */
95 const std::string& GetName() const { return m_name; }
96
97 /**
98 * Gets the field type.
99 *
100 * @return field type
101 */
102 StructFieldType GetType() const { return m_type; }
103
104 /**
105 * Returns whether the field type is a signed integer.
106 *
107 * @return true if signed integer, false otherwise
108 */
109 bool IsInt() const {
110 return m_type == StructFieldType::INT8 ||
111 m_type == StructFieldType::INT16 ||
112 m_type == StructFieldType::INT32 || m_type == StructFieldType::INT64;
113 }
114
115 /**
116 * Returns whether the field type is an unsigned integer.
117 *
118 * @return true if unsigned integer, false otherwise
119 */
120 bool IsUint() const {
121 return m_type == StructFieldType::UINT8 ||
122 m_type == StructFieldType::UINT16 ||
123 m_type == StructFieldType::UINT32 ||
124 m_type == StructFieldType::UINT64;
125 }
126
127 /**
128 * Gets the underlying storage size of the field, in bytes.
129 *
130 * @return number of bytes
131 */
132 size_t GetSize() const { return m_size; }
133
134 /**
135 * Gets the storage offset of the field, in bytes.
136 *
137 * @return number of bytes from the start of the struct
138 */
139 size_t GetOffset() const { return m_offset; }
140
141 /**
142 * Gets the bit width of the field, in bits.
143 *
144 * @return number of bits
145 */
146 unsigned int GetBitWidth() const {
147 return m_bitWidth == 0 ? m_size * 8 : m_bitWidth;
148 }
149
150 /**
151 * Gets the bit mask for the field. The mask is always the least significant
152 * bits (it is not shifted).
153 *
154 * @return bit mask
155 */
156 uint64_t GetBitMask() const { return m_bitMask; }
157
158 /**
159 * Gets the bit shift for the field (LSB=0).
160 *
161 * @return number of bits
162 */
163 unsigned int GetBitShift() const { return m_bitShift; }
164
165 /**
166 * Returns whether the field is an array.
167 *
168 * @return true if array
169 */
170 bool IsArray() const { return m_arraySize > 1; }
171
172 /**
173 * Gets the array size. Returns 1 if non-array.
174 *
175 * @return number of elements
176 */
177 size_t GetArraySize() const { return m_arraySize; }
178
179 /**
180 * Returns whether the field has enumerated values.
181 *
182 * @return true if there are enumerated values
183 */
184 bool HasEnum() const { return !m_enum.empty(); }
185
186 /**
187 * Gets the enumerated values.
188 *
189 * @return set of enumerated values
190 */
191 const EnumValues& GetEnumValues() const { return m_enum; }
192
193 /**
194 * Gets the struct descriptor for a struct data type.
195 *
196 * @return struct descriptor; returns null for non-struct
197 */
198 const StructDescriptor* GetStruct() const { return m_struct; }
199
200 /**
201 * Gets the minimum unsigned integer value that can be stored in this field.
202 *
203 * @return minimum value
204 */
205 uint64_t GetUintMin() const { return 0; }
206
207 /**
208 * Gets the maximum unsigned integer value that can be stored in this field.
209 *
210 * @return maximum value
211 */
212 uint64_t GetUintMax() const { return m_bitMask; }
213
214 /**
215 * Gets the minimum signed integer value that can be stored in this field.
216 *
217 * @return minimum value
218 */
219 int64_t GetIntMin() const {
220 return static_cast<int64_t>(-(m_bitMask >> 1)) - 1;
221 }
222
223 /**
224 * Gets the maximum signed integer value that can be stored in this field.
225 *
226 * @return maximum value
227 */
228 int64_t GetIntMax() const { return m_bitMask >> 1; }
229
230 /**
231 * Returns whether the field is a bitfield.
232 *
233 * @return true if bitfield
234 */
235 bool IsBitField() const {
236 return (m_bitShift != 0 || m_bitWidth != (m_size * 8)) &&
237 m_struct == nullptr;
238 }
239
240 private:
241 // note: constructor fills in everything except offset and shift
242 const StructDescriptor* m_parent;
243 std::string m_name;
244 size_t m_size;
245 size_t m_offset = 0;
246 size_t m_arraySize; // 1 for non-arrays
247 EnumValues m_enum;
248 const StructDescriptor* m_struct; // nullptr for non-structs
249 uint64_t m_bitMask;
250 StructFieldType m_type;
251 unsigned int m_bitWidth;
252 unsigned int m_bitShift = 0;
253};
254
255/**
256 * Raw struct dynamic struct descriptor.
257 */
259 struct private_init {};
261
262 public:
263 StructDescriptor(std::string_view name, const private_init&) : m_name{name} {}
264
265 /**
266 * Gets the struct name.
267 *
268 * @return name
269 */
270 const std::string& GetName() const { return m_name; }
271
272 /**
273 * Gets the struct schema.
274 *
275 * @return schema
276 */
277 const std::string& GetSchema() const { return m_schema; }
278
279 /**
280 * Returns whether the struct is valid (e.g. the struct is fully defined and
281 * field offsets computed).
282 *
283 * @return true if valid
284 */
285 bool IsValid() const { return m_valid; }
286
287 /**
288 * Returns the struct size, in bytes. Not valid unless IsValid() is true.
289 *
290 * @return size in bytes
291 */
292 size_t GetSize() const {
293 assert(m_valid);
294 return m_size;
295 }
296
297 /**
298 * Gets a field descriptor by name. Note the field cannot be accessed until
299 * the struct is valid.
300 *
301 * @param name field name
302 * @return field descriptor, or nullptr if not found
303 */
304 const StructFieldDescriptor* FindFieldByName(std::string_view name) const;
305
306 /**
307 * Gets all field descriptors. Note fields cannot be accessed until the struct
308 * is valid.
309 *
310 * @return field descriptors
311 */
312 const std::vector<StructFieldDescriptor>& GetFields() const {
313 return m_fields;
314 }
315
316 private:
317 bool CheckCircular(
319 std::string CalculateOffsets(
321
322 std::string m_name;
323 std::string m_schema;
324 std::vector<StructDescriptor*> m_references;
325 std::vector<StructFieldDescriptor> m_fields;
326 StringMap<size_t> m_fieldsByName;
327 size_t m_size = 0;
328 bool m_valid = false;
329};
330
331/**
332 * Database of raw struct dynamic descriptors.
333 */
335 public:
336 /**
337 * Adds a structure schema to the database. If the struct references other
338 * structs that have not yet been added, it will not be valid until those
339 * structs are also added.
340 *
341 * @param[in] name structure name
342 * @param[in] schema structure schema
343 * @param[out] err detailed error, if nullptr is returned
344 * @return Added struct, or nullptr on error
345 */
346 const StructDescriptor* Add(std::string_view name, std::string_view schema,
347 std::string* err);
348
349 /**
350 * Finds a structure in the database by name.
351 *
352 * @param name structure name
353 * @return struct descriptor, or nullptr if not found
354 */
355 const StructDescriptor* Find(std::string_view name) const;
356
357 private:
359};
360
361/**
362 * Dynamic (run-time) read-only access to a serialized raw struct.
363 */
365 public:
366 /**
367 * Constructs a new dynamic struct. Note: the passed data is a span; no copy
368 * is made, so it's necessary for the lifetime of the referenced data to be
369 * longer than this object.
370 *
371 * @param desc struct descriptor
372 * @param data serialized data
373 */
374 DynamicStruct(const StructDescriptor* desc, std::span<const uint8_t> data)
375 : m_desc{desc}, m_data{data} {}
376
377 /**
378 * Gets the struct descriptor.
379 *
380 * @return struct descriptor
381 */
382 const StructDescriptor* GetDescriptor() const { return m_desc; }
383
384 /**
385 * Gets the serialized data.
386 *
387 * @return data
388 */
389 std::span<const uint8_t> GetData() const { return m_data; }
390
391 /**
392 * Gets a struct field descriptor by name.
393 *
394 * @param name field name
395 * @return field descriptor, or nullptr if no field with that name exists
396 */
397 const StructFieldDescriptor* FindField(std::string_view name) const {
398 return m_desc->FindFieldByName(name);
399 }
400
401 /**
402 * Gets the value of a boolean field.
403 *
404 * @param field field descriptor
405 * @param arrIndex array index (must be less than field array size)
406 * @return field value
407 */
409 size_t arrIndex = 0) const {
410 assert(field->m_type == StructFieldType::BOOL);
411 return GetFieldImpl(field, arrIndex);
412 }
413
414 /**
415 * Gets the value of a signed integer field.
416 *
417 * @param field field descriptor
418 * @param arrIndex array index (must be less than field array size)
419 * @return field value
420 */
421 int64_t GetIntField(const StructFieldDescriptor* field,
422 size_t arrIndex = 0) const {
423 assert(field->IsInt());
424 uint64_t raw = GetFieldImpl(field, arrIndex);
425 switch (field->m_size) {
426 case 1:
427 return static_cast<int8_t>(raw);
428 case 2:
429 return static_cast<int16_t>(raw);
430 case 4:
431 return static_cast<int32_t>(raw);
432 default:
433 return raw;
434 }
435 }
436
437 /**
438 * Gets the value of an unsigned integer field.
439 *
440 * @param field field descriptor
441 * @param arrIndex array index (must be less than field array size)
442 * @return field value
443 */
444 uint64_t GetUintField(const StructFieldDescriptor* field,
445 size_t arrIndex = 0) const {
446 assert(field->IsUint());
447 return GetFieldImpl(field, arrIndex);
448 }
449
450 /**
451 * Gets the value of a float field.
452 *
453 * @param field field descriptor
454 * @param arrIndex array index (must be less than field array size)
455 * @return field value
456 */
458 size_t arrIndex = 0) const {
459 assert(field->m_type == StructFieldType::FLOAT);
460 return bit_cast<float>(
461 static_cast<uint32_t>(GetFieldImpl(field, arrIndex)));
462 }
463
464 /**
465 * Gets the value of a double field.
466 *
467 * @param field field descriptor
468 * @param arrIndex array index (must be less than field array size)
469 * @return field value
470 */
472 size_t arrIndex = 0) const {
473 assert(field->m_type == StructFieldType::DOUBLE);
474 return bit_cast<double>(GetFieldImpl(field, arrIndex));
475 }
476
477 /**
478 * Gets the value of a char or char array field.
479 *
480 * @param field field descriptor
481 * @return field value
482 */
483 std::string_view GetStringField(const StructFieldDescriptor* field) const;
484
485 /**
486 * Gets the value of a struct field.
487 *
488 * @param field field descriptor
489 * @param arrIndex array index (must be less than field array size)
490 * @return field value
491 */
493 size_t arrIndex = 0) const {
494 assert(field->m_type == StructFieldType::STRUCT);
495 assert(field->m_parent == m_desc);
496 assert(m_desc->IsValid());
497 assert(arrIndex < field->m_arraySize);
498 return DynamicStruct{field->m_struct,
499 m_data.subspan(field->m_offset +
500 arrIndex * field->m_struct->GetSize())};
501 }
502
503 protected:
505
506 private:
507 uint64_t GetFieldImpl(const StructFieldDescriptor* field,
508 size_t arrIndex) const;
509
510 std::span<const uint8_t> m_data;
511};
512
513/**
514 * Dynamic (run-time) mutable access to a serialized raw struct.
515 */
517 public:
518 /**
519 * Constructs a new dynamic struct. Note: the passed data is a span; no copy
520 * is made, so it's necessary for the lifetime of the referenced data to be
521 * longer than this object.
522 *
523 * @param desc struct descriptor
524 * @param data serialized data
525 */
526 MutableDynamicStruct(const StructDescriptor* desc, std::span<uint8_t> data)
527 : DynamicStruct{desc, data}, m_data{data} {}
528
529 /**
530 * Gets the serialized data.
531 *
532 * @return data
533 */
534 std::span<uint8_t> GetData() { return m_data; }
535
537
538 /**
539 * Overwrites the entire serialized struct by copying data from a span.
540 *
541 * @param data replacement data for the struct
542 */
543 void SetData(std::span<const uint8_t> data);
544
545 /**
546 * Sets the value of a boolean field.
547 *
548 * @param field field descriptor
549 * @param value field value
550 * @param arrIndex array index (must be less than field array size)
551 */
552 void SetBoolField(const StructFieldDescriptor* field, bool value,
553 size_t arrIndex = 0) {
554 assert(field->m_type == StructFieldType::BOOL);
555 SetFieldImpl(field, value ? 1 : 0, arrIndex);
556 }
557
558 /**
559 * Sets the value of a signed integer field.
560 *
561 * @param field field descriptor
562 * @param value field value
563 * @param arrIndex array index (must be less than field array size)
564 */
565 void SetIntField(const StructFieldDescriptor* field, int64_t value,
566 size_t arrIndex = 0) {
567 assert(field->IsInt());
568 SetFieldImpl(field, value, arrIndex);
569 }
570
571 /**
572 * Sets the value of an unsigned integer field.
573 *
574 * @param field field descriptor
575 * @param value field value
576 * @param arrIndex array index (must be less than field array size)
577 */
578 void SetUintField(const StructFieldDescriptor* field, uint64_t value,
579 size_t arrIndex = 0) {
580 assert(field->IsUint());
581 SetFieldImpl(field, value, arrIndex);
582 }
583
584 /**
585 * Sets the value of a float field.
586 *
587 * @param field field descriptor
588 * @param value field value
589 * @param arrIndex array index (must be less than field array size)
590 */
591 void SetFloatField(const StructFieldDescriptor* field, float value,
592 size_t arrIndex = 0) {
593 assert(field->m_type == StructFieldType::FLOAT);
594 SetFieldImpl(field, bit_cast<uint32_t>(value), arrIndex);
595 }
596
597 /**
598 * Sets the value of a double field.
599 *
600 * @param field field descriptor
601 * @param value field value
602 * @param arrIndex array index (must be less than field array size)
603 */
604 void SetDoubleField(const StructFieldDescriptor* field, double value,
605 size_t arrIndex = 0) {
606 assert(field->m_type == StructFieldType::DOUBLE);
607 SetFieldImpl(field, bit_cast<uint64_t>(value), arrIndex);
608 }
609
610 /**
611 * Sets the value of a char or char array field.
612 *
613 * @param field field descriptor
614 * @param value field value
615 * @return true if the full value fit in the struct, false if truncated
616 */
618 std::string_view value);
619
620 /**
621 * Sets the value of a struct field.
622 *
623 * @param field field descriptor
624 * @param value field value
625 * @param arrIndex array index (must be less than field array size)
626 */
628 const DynamicStruct& value, size_t arrIndex = 0);
629
630 /**
631 * Gets the value of a struct field.
632 *
633 * @param field field descriptor
634 * @param arrIndex array index (must be less than field array size)
635 * @return field value
636 */
638 size_t arrIndex = 0) {
639 assert(field->m_type == StructFieldType::STRUCT);
640 assert(field->m_parent == m_desc);
641 assert(m_desc->IsValid());
642 assert(arrIndex < field->m_arraySize);
644 field->m_struct, m_data.subspan(field->m_offset +
645 arrIndex * field->m_struct->GetSize())};
646 }
647
649
650 private:
651 void SetFieldImpl(const StructFieldDescriptor* field, uint64_t value,
652 size_t arrIndex);
653
654 std::span<uint8_t> m_data;
655};
656
657namespace impl {
658struct DSOData {
659 explicit DSOData(size_t size) : m_dataStore(size) {}
660 explicit DSOData(std::span<const uint8_t> data)
661 : m_dataStore{data.begin(), data.end()} {}
662
663 std::vector<uint8_t> m_dataStore;
664};
665} // namespace impl
666
667/**
668 * Dynamic (run-time) mutable access to a serialized raw struct, with internal
669 * data storage.
670 */
671class DynamicStructObject : private impl::DSOData, public MutableDynamicStruct {
672 /**
673 * Constructs a new dynamic struct object. The descriptor must be valid.
674 *
675 * @param desc struct descriptor
676 */
677 explicit DynamicStructObject(const StructDescriptor* desc)
678 : DSOData{desc->GetSize()}, MutableDynamicStruct{desc, m_dataStore} {}
679
680 /**
681 * Constructs a new dynamic struct object. Makes a copy of the serialized
682 * data so there are no lifetime constraints on the data parameter.
683 *
684 * @param desc struct descriptor
685 * @param data serialized data
686 */
687 DynamicStructObject(const StructDescriptor* desc,
688 std::span<const uint8_t> data)
690 assert(data.size() >= desc->GetSize());
691 }
692
693 // can't be movable due to span references
694 DynamicStructObject(DynamicStructObject&&) = delete;
695 DynamicStructObject& operator=(DynamicStructObject&&) = delete;
696};
697
698} // namespace wpi::util
@ name
Definition base.h:690
Dynamic (run-time) read-only access to a serialized raw struct.
Definition DynamicStruct.hpp:364
float GetFloatField(const StructFieldDescriptor *field, size_t arrIndex=0) const
Gets the value of a float field.
Definition DynamicStruct.hpp:457
bool GetBoolField(const StructFieldDescriptor *field, size_t arrIndex=0) const
Gets the value of a boolean field.
Definition DynamicStruct.hpp:408
double GetDoubleField(const StructFieldDescriptor *field, size_t arrIndex=0) const
Gets the value of a double field.
Definition DynamicStruct.hpp:471
const StructDescriptor * GetDescriptor() const
Gets the struct descriptor.
Definition DynamicStruct.hpp:382
uint64_t GetUintField(const StructFieldDescriptor *field, size_t arrIndex=0) const
Gets the value of an unsigned integer field.
Definition DynamicStruct.hpp:444
std::string_view GetStringField(const StructFieldDescriptor *field) const
Gets the value of a char or char array field.
const StructDescriptor * m_desc
Definition DynamicStruct.hpp:504
DynamicStruct GetStructField(const StructFieldDescriptor *field, size_t arrIndex=0) const
Gets the value of a struct field.
Definition DynamicStruct.hpp:492
int64_t GetIntField(const StructFieldDescriptor *field, size_t arrIndex=0) const
Gets the value of a signed integer field.
Definition DynamicStruct.hpp:421
std::span< const uint8_t > GetData() const
Gets the serialized data.
Definition DynamicStruct.hpp:389
const StructFieldDescriptor * FindField(std::string_view name) const
Gets a struct field descriptor by name.
Definition DynamicStruct.hpp:397
DynamicStruct(const StructDescriptor *desc, std::span< const uint8_t > data)
Constructs a new dynamic struct.
Definition DynamicStruct.hpp:374
Dynamic (run-time) mutable access to a serialized raw struct.
Definition DynamicStruct.hpp:516
void SetUintField(const StructFieldDescriptor *field, uint64_t value, size_t arrIndex=0)
Sets the value of an unsigned integer field.
Definition DynamicStruct.hpp:578
void SetFloatField(const StructFieldDescriptor *field, float value, size_t arrIndex=0)
Sets the value of a float field.
Definition DynamicStruct.hpp:591
void SetBoolField(const StructFieldDescriptor *field, bool value, size_t arrIndex=0)
Sets the value of a boolean field.
Definition DynamicStruct.hpp:552
void SetIntField(const StructFieldDescriptor *field, int64_t value, size_t arrIndex=0)
Sets the value of a signed integer field.
Definition DynamicStruct.hpp:565
void SetStructField(const StructFieldDescriptor *field, const DynamicStruct &value, size_t arrIndex=0)
Sets the value of a struct field.
MutableDynamicStruct(const StructDescriptor *desc, std::span< uint8_t > data)
Constructs a new dynamic struct.
Definition DynamicStruct.hpp:526
void SetData(std::span< const uint8_t > data)
Overwrites the entire serialized struct by copying data from a span.
MutableDynamicStruct GetStructField(const StructFieldDescriptor *field, size_t arrIndex=0)
Gets the value of a struct field.
Definition DynamicStruct.hpp:637
void SetDoubleField(const StructFieldDescriptor *field, double value, size_t arrIndex=0)
Sets the value of a double field.
Definition DynamicStruct.hpp:604
bool SetStringField(const StructFieldDescriptor *field, std::string_view value)
Sets the value of a char or char array field.
std::span< uint8_t > GetData()
Gets the serialized data.
Definition DynamicStruct.hpp:534
Definition BooleanTopic.hpp:22
StringMap is a sorted associative container that contains key-value pairs with unique string keys.
Definition StringMap.hpp:26
Database of raw struct dynamic descriptors.
Definition DynamicStruct.hpp:334
const StructDescriptor * Find(std::string_view name) const
Finds a structure in the database by name.
const StructDescriptor * Add(std::string_view name, std::string_view schema, std::string *err)
Adds a structure schema to the database.
Raw struct dynamic struct descriptor.
Definition DynamicStruct.hpp:258
const std::string & GetSchema() const
Gets the struct schema.
Definition DynamicStruct.hpp:277
bool IsValid() const
Returns whether the struct is valid (e.g.
Definition DynamicStruct.hpp:285
StructDescriptor(std::string_view name, const private_init &)
Definition DynamicStruct.hpp:263
const std::vector< StructFieldDescriptor > & GetFields() const
Gets all field descriptors.
Definition DynamicStruct.hpp:312
const std::string & GetName() const
Gets the struct name.
Definition DynamicStruct.hpp:270
friend class StructDescriptorDatabase
Definition DynamicStruct.hpp:260
const StructFieldDescriptor * FindFieldByName(std::string_view name) const
Gets a field descriptor by name.
size_t GetSize() const
Returns the struct size, in bytes.
Definition DynamicStruct.hpp:292
Raw struct dynamic field descriptor.
Definition DynamicStruct.hpp:64
friend class MutableDynamicStruct
Definition DynamicStruct.hpp:67
const StructDescriptor * GetStruct() const
Gets the struct descriptor for a struct data type.
Definition DynamicStruct.hpp:198
StructFieldType GetType() const
Gets the field type.
Definition DynamicStruct.hpp:102
friend class StructDescriptor
Definition DynamicStruct.hpp:68
size_t GetSize() const
Gets the underlying storage size of the field, in bytes.
Definition DynamicStruct.hpp:132
size_t GetOffset() const
Gets the storage offset of the field, in bytes.
Definition DynamicStruct.hpp:139
const StructDescriptor * GetParent() const
Gets the dynamic struct this field is contained in.
Definition DynamicStruct.hpp:88
bool IsArray() const
Returns whether the field is an array.
Definition DynamicStruct.hpp:170
size_t GetArraySize() const
Gets the array size.
Definition DynamicStruct.hpp:177
bool IsUint() const
Returns whether the field type is an unsigned integer.
Definition DynamicStruct.hpp:120
std::vector< std::pair< std::string, int64_t > > EnumValues
Set of enumerated values.
Definition DynamicStruct.hpp:75
uint64_t GetUintMax() const
Gets the maximum unsigned integer value that can be stored in this field.
Definition DynamicStruct.hpp:212
friend class DynamicStruct
Definition DynamicStruct.hpp:66
uint64_t GetUintMin() const
Gets the minimum unsigned integer value that can be stored in this field.
Definition DynamicStruct.hpp:205
unsigned int GetBitWidth() const
Gets the bit width of the field, in bits.
Definition DynamicStruct.hpp:146
StructFieldDescriptor(const StructDescriptor *parent, std::string_view name, StructFieldType type, size_t size, size_t arraySize, unsigned int bitWidth, EnumValues enumValues, const StructDescriptor *structDesc, const private_init &)
int64_t GetIntMin() const
Gets the minimum signed integer value that can be stored in this field.
Definition DynamicStruct.hpp:219
bool HasEnum() const
Returns whether the field has enumerated values.
Definition DynamicStruct.hpp:184
bool IsInt() const
Returns whether the field type is a signed integer.
Definition DynamicStruct.hpp:109
unsigned int GetBitShift() const
Gets the bit shift for the field (LSB=0).
Definition DynamicStruct.hpp:163
const EnumValues & GetEnumValues() const
Gets the enumerated values.
Definition DynamicStruct.hpp:191
friend class StructDescriptorDatabase
Definition DynamicStruct.hpp:69
uint64_t GetBitMask() const
Gets the bit mask for the field.
Definition DynamicStruct.hpp:156
const std::string & GetName() const
Gets the field name.
Definition DynamicStruct.hpp:95
bool IsBitField() const
Returns whether the field is a bitfield.
Definition DynamicStruct.hpp:235
int64_t GetIntMax() const
Gets the maximum signed integer value that can be stored in this field.
Definition DynamicStruct.hpp:228
Definition Errors.hpp:112
Definition RobotBase.hpp:26
Definition raw_os_ostream.hpp:19
StructFieldType
Known data types for raw struct dynamic fields (see StructFieldDescriptor).
Definition DynamicStruct.hpp:32
@ CHAR
char.
Definition DynamicStruct.hpp:36
@ UINT32
uint32.
Definition DynamicStruct.hpp:50
@ UINT16
uint16.
Definition DynamicStruct.hpp:48
@ INT64
int64.
Definition DynamicStruct.hpp:44
@ INT16
int16.
Definition DynamicStruct.hpp:40
@ INT32
int32.
Definition DynamicStruct.hpp:42
@ UINT64
uint64.
Definition DynamicStruct.hpp:52
@ BOOL
bool.
Definition DynamicStruct.hpp:34
@ STRUCT
struct.
Definition DynamicStruct.hpp:58
@ FLOAT
float.
Definition DynamicStruct.hpp:54
@ UINT8
uint8.
Definition DynamicStruct.hpp:46
@ INT8
int8.
Definition DynamicStruct.hpp:38
@ DOUBLE
double.
Definition DynamicStruct.hpp:56
Definition DynamicStruct.hpp:658
DSOData(size_t size)
Definition DynamicStruct.hpp:659
DSOData(std::span< const uint8_t > data)
Definition DynamicStruct.hpp:660
std::vector< uint8_t > m_dataStore
Definition DynamicStruct.hpp:663