ADTF
Loading...
Searching...
No Matches
dd_struct_access.h
Go to the documentation of this file.
1
14
15#ifndef DD_DDL_STRUCT_ACCESS_H_INCLUDED
16#define DD_DDL_STRUCT_ACCESS_H_INCLUDED
17
19
20#include <cstddef>
21#include <functional>
22#include <string>
23
24namespace ddl {
25namespace dd {
26
27class TypeInfo;
28class ElementTypeInfo;
31
42public:
43 friend class StructTypeAccess;
44 friend class StructElementAccessIterator;
45 friend class StructArrayElementAccessIterator;
46
77 StructElementAccess(std::nullptr_t);
78
83
92 operator bool() const;
99
104 std::string getName() const;
113 std::shared_ptr<const datamodel::StructType> getStructType() const;
122 std::shared_ptr<const datamodel::EnumType> getEnumType() const;
131 std::shared_ptr<const datamodel::DataType> getDataType() const;
132
151 StructTypeAccess getStructTypeAccess(size_t array_pos = 0) const;
152
158 bool isStruct() const;
159
165 bool isLeaf() const;
166
172 bool isArray() const;
173
179 size_t getArraySize() const;
180
188 StructElementAccess getArrayElement(size_t array_pos = 0) const;
189
195 const datamodel::StructType::Element& getElement() const;
202 bool isDynamic() const;
211 bool isAfterDynamic() const;
229 size_t getDeserializedBytePos(size_t array_pos = 0) const;
237
244
259 size_t getSerializedBytePos(size_t array_pos = 0) const;
267 size_t getSerializedBitOffset(size_t array_pos = 0) const;
274 size_t getSerializedBitSize() const;
281
287
293 const std::string& getValidElementCount() const;
294
299 typedef StructArrayElementAccessIterator const_iterator;
300
321
322private:
331 StructElementAccess(const std::shared_ptr<const datamodel::StructType::Element>& elem,
332 OptionalSize serialized_element_bit_offset,
333 OptionalSize deserialized_element_byte_offset,
334 OptionalSize array_pos);
343 StructElementAccess(const std::shared_ptr<const datamodel::StructType::Element>& elem,
344 const ElementTypeInfo* element_type_info,
345 OptionalSize serialized_element_bit_offset,
346 OptionalSize deserialized_element_byte_offset,
347 OptionalSize array_pos);
348
349private:
350 std::shared_ptr<const datamodel::StructType::Element> _element = {};
351 const ElementTypeInfo* _element_type_info = nullptr;
352 OptionalSize _deserialized_struct_byte_offset = {};
353 OptionalSize _serialized_struct_bit_offset = {};
354 OptionalSize _array_pos = {};
355};
356
364class StructArrayElementAccessIterator {
365public:
366 StructArrayElementAccessIterator() = delete;
370 StructArrayElementAccessIterator(const StructArrayElementAccessIterator&);
374 StructArrayElementAccessIterator& operator=(const StructArrayElementAccessIterator&);
378 StructArrayElementAccessIterator(StructArrayElementAccessIterator&&) noexcept;
382 StructArrayElementAccessIterator& operator=(StructArrayElementAccessIterator&&) noexcept;
386 ~StructArrayElementAccessIterator();
390 typedef StructArrayElementAccessIterator self_type;
394 typedef StructElementAccess value_type;
398 typedef StructElementAccess& reference;
402 typedef const StructElementAccess& const_reference;
406 typedef StructElementAccess* pointer;
410 typedef const StructElementAccess* const_pointer;
414 typedef int difference_type;
418 typedef std::forward_iterator_tag iterator_category;
419
425 self_type& operator++();
431 self_type operator++(int);
437 const_reference operator*() const;
443 const_pointer operator->() const;
451 bool operator==(const self_type& rhs) const;
459 bool operator!=(const self_type& rhs) const;
460
461private:
462 friend class StructElementAccess;
463 StructArrayElementAccessIterator(const StructElementAccess* parent,
464 StructElementAccess array_element);
465 const StructElementAccess* _parent;
466 StructElementAccess _current_array_element;
467};
468
474class StructElementAccessIterator {
475public:
476 StructElementAccessIterator() = delete;
480 StructElementAccessIterator(const StructElementAccessIterator&);
484 StructElementAccessIterator& operator=(const StructElementAccessIterator&);
488 StructElementAccessIterator(StructElementAccessIterator&&) noexcept;
492 StructElementAccessIterator& operator=(StructElementAccessIterator&&) noexcept;
496 ~StructElementAccessIterator();
500 typedef StructElementAccessIterator self_type;
524 typedef int difference_type;
528 typedef std::forward_iterator_tag iterator_category;
529
535 self_type operator++();
542 self_type operator++(int junk);
548 const_reference operator*() const;
554 const_pointer operator->() const;
562 bool operator==(const self_type& rhs) const;
570 bool operator!=(const self_type& rhs) const;
571
572private:
573 friend StructTypeAccess;
582 StructElementAccessIterator(datamodel::StructType::Elements::const_iterator other_it,
583 datamodel::StructType::Elements::const_iterator end_it,
584 OptionalSize struct_ser,
585 OptionalSize struct_deser);
586 datamodel::StructType::Elements::const_iterator _base_it;
587 datamodel::StructType::Elements::const_iterator _end_it;
589 OptionalSize _struct_ser;
590 OptionalSize _struct_deser;
591};
592
599public:
600 friend class DataDefinition;
601 friend class StructElementAccess;
602 friend class ElementTypeInfo;
616 StructTypeAccess& operator=(StructTypeAccess&&) noexcept;
625
633 StructTypeAccess(const std::shared_ptr<const datamodel::StructType>& struct_type);
634
638 StructTypeAccess(std::nullptr_t);
639
644
645private:
653 StructTypeAccess(const std::shared_ptr<const datamodel::StructType>& struct_type,
654 OptionalSize serialized_struct_offset,
655 OptionalSize deserialized_struct_offset);
656
657public:
675 StructElementAccess getElementByPath(std::string_view name_path) const;
684 operator bool() const;
690 size_t getStaticStructSize() const;
691
699
707
714 bool isDynamic() const;
715
722
752
753private:
754 std::shared_ptr<const datamodel::StructType> _struct_type;
755 OptionalSize _serialized_struct_as_element_offset =
756 {}; // these values are greater 0 if the struct is used within another struct and we
757 // calculate that element
758 OptionalSize _deserialized_struct_as_element_offset =
759 {}; // these values are greater 0 if the struct is used within another struct and we
760 // calculate that element
761 const TypeInfo* _type_info = nullptr;
762};
763
769 std::function<void(const StructElementAccess& /*child*/, const StructTypeAccess& /*parent*/)>;
777 std::function<bool(const StructElementAccess& /*child*/, const StructTypeAccess& /*parent*/)>;
778
809 const StructTypeAccess& parent,
810 const CallbackStructElementAccess& access_leaf_callback,
811 const CallbackStructElementAccessControl& enter_element_member_callback =
812 [](auto&, auto&) { return true; },
813 const CallbackStructElementAccess& leave_element_member_callback = [](auto&, auto&) {},
814 const CallbackStructElementAccessControl& enter_array_element_member_callback =
815 [](auto&, auto&) { return true; },
816 const CallbackStructElementAccess& leave_array_element_member_callback = [](auto&, auto&) {},
817 bool filter_padding_elements = true);
818
846 const StructTypeAccess& parent,
847 std::string_view path,
848 const CallbackStructElementAccess& target_element_callback,
849 const CallbackStructElementAccess& enter_element_member_callback = [](auto&, auto&) {},
850 const CallbackStructElementAccess& leave_element_member_callback = [](auto&, auto&) {},
851 const CallbackStructElementAccess& enter_array_element_member_callback = [](auto&, auto&) {},
852 const CallbackStructElementAccess& leave_array_element_member_callback = [](auto&, auto&) {});
853
854} // namespace dd
855} // namespace ddl
856
857#endif // DD_DDL_STRUCT_ACCESS_H_INCLUDED
Definition dd_struct_access.h:364
int difference_type
difference value type definition
Definition dd_struct_access.h:414
const StructElementAccess * const_pointer
pointer to const data value type definition
Definition dd_struct_access.h:410
const StructElementAccess & const_reference
const reference value type definition
Definition dd_struct_access.h:402
StructElementAccess & reference
reference value type definition
Definition dd_struct_access.h:398
std::forward_iterator_tag iterator_category
iterator type definition
Definition dd_struct_access.h:418
StructArrayElementAccessIterator(const StructArrayElementAccessIterator &)
Copy CTOR.
StructArrayElementAccessIterator & operator=(const StructArrayElementAccessIterator &)
Copy Assignment Operator.
StructArrayElementAccessIterator(StructArrayElementAccessIterator &&) noexcept
Move CTOR.
StructArrayElementAccessIterator self_type
this iterator type definition
Definition dd_struct_access.h:390
StructElementAccess value_type
iterator value type definition
Definition dd_struct_access.h:394
StructElementAccess * pointer
pointer value type definition
Definition dd_struct_access.h:406
Iterator to iterate thru the StructTypeAccess.
Definition dd_struct_access.h:474
const StructElementAccess & const_reference
const reference value type definition
Definition dd_struct_access.h:512
int difference_type
difference value type definition
Definition dd_struct_access.h:524
StructElementAccessIterator & operator=(const StructElementAccessIterator &)
Copy Assignment Operator.
const StructElementAccess * const_pointer
pointer to const data value type definition
Definition dd_struct_access.h:520
StructElementAccessIterator(const StructElementAccessIterator &)
Copy CTOR.
StructElementAccess & reference
reference value type definition
Definition dd_struct_access.h:508
StructElementAccess value_type
iterator value type definition
Definition dd_struct_access.h:504
StructElementAccess * pointer
pointer value type definition
Definition dd_struct_access.h:516
StructElementAccessIterator self_type
this iterator type definition
Definition dd_struct_access.h:500
std::forward_iterator_tag iterator_category
iterator type definition
Definition dd_struct_access.h:528
StructElementAccessIterator(StructElementAccessIterator &&) noexcept
Move CTOR.
Class to access and obtain the byte position and other information of a instance of this element with...
Definition dd_struct_access.h:41
bool isStruct() const
Determines if the element is an struct type.
size_t getSerializedBitOffset(size_t array_pos=0) const
Get SerializedBitOffset.
const_iterator begin() const
Get the begin const iterator to the array elements of this element access.
size_t getSerializedBitSize() const
Get the serialized Bit size of the value.
TypeOfType getTypeOfType() const
Get the Type Of the type. Retrieves the information of the elements type.
const datamodel::StructType::Element & getElement() const
Get the Element Information which is also part of the data definition.
StructElementAccess getArrayElement(size_t array_pos=0) const
Retrieves an element with byte and bit offsets for the given array position.
bool isDynamic() const
Retieve information if this element is a dynamic array.
const std::string & getValidElementCount() const
StructElementAccess()=delete
deleted CTOR
bool isArray() const
Determines if the element is an array type.
const_iterator end() const
Get the end const iterator to the array elements of this element access.
StructElementAccess(StructElementAccess &&) noexcept
Default move CTOR.
size_t getDeserializedBytePos(size_t array_pos=0) const
Get the Deserialized Byte Pos relative to the first byte position of the struct obtained by dd::DataD...
StructTypeAccess getStructTypeAccess(size_t array_pos=0) const
Get the Struct Type Access if the element depends on a structtype. All byte positions within the retu...
size_t getSerializedBytePos(size_t array_pos=0) const
Get SerializedBytePos obtained by dd::DataDefinition::getStructTypeAccess.
bool isLeaf() const
Determines if the element is a leaf type (no struct, no array).
std::string getName() const
size_t getDeserializedByteSize() const
Get the Byte size (depends on alignments, ddlversion and arraysize)
const_iterator cend() const
Get the end const iterator to the array elements of this element access.
size_t getSerializedTypeBitSize() const
Get the serialized bit size of one element.
OptionalSize getArrayPos() const
Get the Array Pos, if this element was retrieved via StructTypeAccess::getElementByPath and the opera...
size_t getDeserializedTypeAlignedByteSize() const
Get the Serialized Type Byte size aligned.
std::shared_ptr< const datamodel::EnumType > getEnumType() const
Gets the Enum Type if the element is dependent on a enumtype.
std::shared_ptr< const datamodel::StructType > getStructType() const
Gets the Struct Type if the element is dependent on a structtype.
bool isAfterDynamic() const
The element is on a byte position after a dynamic element, the byte position can not be calculated un...
size_t getArraySize() const
Retrieves the array size if the element is an static array type.
StructArrayElementAccessIterator const_iterator
this is the const iterator type definition for the array elements of this element access.
Definition dd_struct_access.h:299
size_t getDeserializedTypeByteSize() const
Get the Serialized Type Byte size.
const_iterator cbegin() const
Get the begin const iterator to the array elements of this element access.
std::shared_ptr< const datamodel::DataType > getDataType() const
Gets the Data Type if the element is dependent on a datatype.
Accessing class for a instance of a struct. This will calculate the byte positions can be used for se...
Definition dd_struct_access.h:598
const_iterator end() const
constant range based end iterator
StructElementAccess getElementByPath(std::string_view name_path) const
Get the StructElementAccess information class by path. Separator is "." or "/" Following element ac...
const_iterator cend() const
constant end iterator
size_t getStaticStructSize() const
Get the known Static Struct Size of this instance.
size_t getStaticUnalignedStructSize() const
Get the known unaligned Static Struct Size of this instance (this is usually the last position + size...
const_iterator begin() const
constant range based iterator access
StructTypeAccess()=delete
default CTOR is deleted
bool isDynamic() const
retrieves information if it contains dynamic elements and so has dynamic size.
const_iterator cbegin() const
constant iterator access
const datamodel::StructType & getStructType() const
Get the Struct Type it refers to (for data definition information)
const StructElementAccessIterator const_iterator
iterator type of this struct
Definition dd_struct_access.h:727
StructTypeAccess(StructTypeAccess &&) noexcept
Move CTOR.
size_t getStaticSerializedBitSize() const
Get the known bitsize of this instance (this is usually the last position + sizeof last element)
definition of the datamodel namespace
Definition datamodel_base.h:28
definition of the dd namespace
Definition datamodel_base.h:26
datamodel::DataType DataType
Definition dd.h:51
datamodel::EnumType EnumType
Definition dd.h:55
std::function< void(const StructElementAccess &, const StructTypeAccess &)> CallbackStructElementAccess
Callback function type definitions for struct element access traversal.
Definition dd_struct_access.h:768
datamodel::StructType StructType
Definition dd.h:59
utility::Optional< size_t > OptionalSize
Optional Size Type.
Definition dd_common_types.h:38
TypeOfType
Classification of a Type.
Definition dd_common_types.h:44
@ struct_type
the type is a struct type (StructType)
Definition dd_common_types.h:64
void forEachElementInfix(const StructTypeAccess &parent, const CallbackStructElementAccess &access_leaf_callback, const CallbackStructElementAccessControl &enter_element_member_callback=[](auto &, auto &) { return true;}, const CallbackStructElementAccess &leave_element_member_callback=[](auto &, auto &) {}, const CallbackStructElementAccessControl &enter_array_element_member_callback=[](auto &, auto &) { return true;}, const CallbackStructElementAccess &leave_array_element_member_callback=[](auto &, auto &) {}, bool filter_padding_elements=true)
Traverse all elements of a struct type access in infix order and calls the callbacks.
void forEachElementInPathInfix(const StructTypeAccess &parent, std::string_view path, const CallbackStructElementAccess &target_element_callback, const CallbackStructElementAccess &enter_element_member_callback=[](auto &, auto &) {}, const CallbackStructElementAccess &leave_element_member_callback=[](auto &, auto &) {}, const CallbackStructElementAccess &enter_array_element_member_callback=[](auto &, auto &) {}, const CallbackStructElementAccess &leave_array_element_member_callback=[](auto &, auto &) {})
Traverse all elements along a given path in struct type access in infix order and calls the callbacks...
@ element_type_info
Element Type Info.
Definition dd_infomodel_type.h:44
std::function< bool(const StructElementAccess &, const StructTypeAccess &)> CallbackStructElementAccessControl
Callback function type definitions for struct element access traversal. The return value indicates if...
Definition dd_struct_access.h:776
definition of the ddl namespace
Definition codec.h:21