15#ifndef DD_DDL_STRUCT_ACCESS_H_INCLUDED
16#define DD_DDL_STRUCT_ACCESS_H_INCLUDED
43 friend class StructTypeAccess;
44 friend class StructElementAccessIterator;
45 friend class StructArrayElementAccessIterator;
92 operator
bool() const;
358 const ElementTypeInfo* _element_type_info =
nullptr;
371class StructArrayElementAccessIterator {
373 StructArrayElementAccessIterator() =
delete;
381 StructArrayElementAccessIterator&
operator=(
const StructArrayElementAccessIterator&);
389 StructArrayElementAccessIterator& operator=(StructArrayElementAccessIterator&&) noexcept;
393 ~StructArrayElementAccessIterator();
469 friend class StructElementAccess;
470 StructArrayElementAccessIterator(const StructElementAccess* parent,
471 StructElementAccess array_element);
472 const StructElementAccess* _parent;
473 StructElementAccess _current_array_element;
481class StructElementAccessIterator {
483 StructElementAccessIterator() =
delete;
491 StructElementAccessIterator&
operator=(
const StructElementAccessIterator&);
499 StructElementAccessIterator& operator=(StructElementAccessIterator&&) noexcept;
503 ~StructElementAccessIterator();
580 friend StructTypeAccess;
607 friend class DataDefinition;
608 friend class StructElementAccess;
609 friend class ElementTypeInfo;
691 operator
bool() const;
768 const TypeInfo* _type_info =
nullptr;
788std::pair<std::string_view, OptionalSize>
findArrayPos(std::string_view name);
810template <
class RETURN_VALUE,
class CALLBACK>
811inline constexpr bool is_for_each_element_callback_v =
812 std::is_invocable_r_v<RETURN_VALUE,
813 std::decay_t<CALLBACK>,
849template <
typename ACCESS_LEAF_CALLBACK,
850 typename ENTER_ELEMENT_MEMBER_CALLBACK,
851 typename LEAVE_ELEMENT_MEMBER_CALLBACK,
852 typename ENTER_ARRAY_ELEMENT_MEMBER_CALLBACK,
853 typename LEAVE_ARRAY_ELEMENT_MEMBER_CALLBACK>
855 ACCESS_LEAF_CALLBACK&& access_leaf_callback,
856 ENTER_ELEMENT_MEMBER_CALLBACK&& enter_element_member_callback,
857 LEAVE_ELEMENT_MEMBER_CALLBACK&& leave_element_member_callback,
858 ENTER_ARRAY_ELEMENT_MEMBER_CALLBACK&& enter_array_element_member_callback,
859 LEAVE_ARRAY_ELEMENT_MEMBER_CALLBACK&& leave_array_element_member_callback,
860 bool filter_padding_elements =
true,
861 bool continue_arrays_after_skip =
true)
863 static_assert(is_for_each_element_callback_v<void, ACCESS_LEAF_CALLBACK>);
864 static_assert(is_for_each_element_callback_v<bool, ENTER_ELEMENT_MEMBER_CALLBACK>);
865 static_assert(is_for_each_element_callback_v<void, LEAVE_ELEMENT_MEMBER_CALLBACK>);
866 static_assert(is_for_each_element_callback_v<bool, ENTER_ARRAY_ELEMENT_MEMBER_CALLBACK>);
867 static_assert(is_for_each_element_callback_v<void, LEAVE_ARRAY_ELEMENT_MEMBER_CALLBACK>);
869 for (
const auto& child: parent) {
870 if (filter_padding_elements && child.isPadding()) {
873 if (enter_element_member_callback(child, parent)) {
874 if (child.isArray()) {
875 for (
const auto& array_element: child) {
876 if (array_element.isStruct()) {
877 const auto child_array_struct_access = array_element.getStructTypeAccess();
878 if (enter_array_element_member_callback(array_element,
879 child_array_struct_access)) {
881 access_leaf_callback,
882 enter_element_member_callback,
883 leave_element_member_callback,
884 enter_array_element_member_callback,
885 leave_array_element_member_callback,
886 filter_padding_elements,
887 continue_arrays_after_skip);
888 leave_array_element_member_callback(array_element,
889 child_array_struct_access);
891 else if (!continue_arrays_after_skip) {
896 if (enter_array_element_member_callback(array_element, parent)) {
897 access_leaf_callback(array_element, parent);
898 leave_array_element_member_callback(array_element, parent);
900 else if (!continue_arrays_after_skip) {
907 if (child.isStruct()) {
909 access_leaf_callback,
910 enter_element_member_callback,
911 leave_element_member_callback,
912 enter_array_element_member_callback,
913 leave_array_element_member_callback,
914 filter_padding_elements,
915 continue_arrays_after_skip);
918 access_leaf_callback(child, parent);
921 leave_element_member_callback(child, parent);
946template <
typename ACCESS_LEAF_CALLBACK,
947 typename ENTER_ELEMENT_MEMBER_CALLBACK,
948 typename LEAVE_ELEMENT_MEMBER_CALLBACK>
950 ACCESS_LEAF_CALLBACK&& access_leaf_callback,
951 ENTER_ELEMENT_MEMBER_CALLBACK&& enter_element_member_callback,
952 LEAVE_ELEMENT_MEMBER_CALLBACK&& leave_element_member_callback,
953 bool filter_padding_elements =
true)
957 std::forward<ACCESS_LEAF_CALLBACK>(access_leaf_callback),
958 std::forward<ENTER_ELEMENT_MEMBER_CALLBACK>(enter_element_member_callback),
959 std::forward<LEAVE_ELEMENT_MEMBER_CALLBACK>(leave_element_member_callback),
960 [](
const auto&,
const auto&)
noexcept ->
bool {
return true; },
961 [](
const auto&,
const auto&)
noexcept ->
void {},
962 filter_padding_elements,
977template <
typename ACCESS_LEAF_CALLBACK>
979 ACCESS_LEAF_CALLBACK&& access_leaf_callback,
980 bool filter_padding_elements =
true)
984 std::forward<ACCESS_LEAF_CALLBACK>(access_leaf_callback),
985 [](
const auto&,
const auto&)
noexcept ->
bool {
return true; },
986 [](
const auto&,
const auto&)
noexcept ->
void {},
987 [](
const auto&,
const auto&)
noexcept ->
bool {
return true; },
988 [](
const auto&,
const auto&)
noexcept ->
void {},
989 filter_padding_elements,
1019template <
typename TARGET_ELEMENT_CALLBACK,
1020 typename ENTER_ELEMENT_MEMBER_CALLBACK,
1021 typename LEAVE_ELEMENT_MEMBER_CALLBACK,
1022 typename ENTER_ARRAY_ELEMENT_MEMBER_CALLBACK,
1023 typename LEAVE_ARRAY_ELEMENT_MEMBER_CALLBACK>
1026 std::string_view path,
1027 TARGET_ELEMENT_CALLBACK&& target_element_callback,
1028 ENTER_ELEMENT_MEMBER_CALLBACK&& enter_element_member_callback,
1029 LEAVE_ELEMENT_MEMBER_CALLBACK&& leave_element_member_callback,
1030 ENTER_ARRAY_ELEMENT_MEMBER_CALLBACK&& enter_array_element_member_callback,
1031 LEAVE_ARRAY_ELEMENT_MEMBER_CALLBACK&& leave_array_element_member_callback)
1033 static_assert(is_for_each_element_callback_v<void, TARGET_ELEMENT_CALLBACK>);
1034 static_assert(is_for_each_element_callback_v<void, ENTER_ELEMENT_MEMBER_CALLBACK>);
1035 static_assert(is_for_each_element_callback_v<void, LEAVE_ELEMENT_MEMBER_CALLBACK>);
1036 static_assert(is_for_each_element_callback_v<void, ENTER_ARRAY_ELEMENT_MEMBER_CALLBACK>);
1037 static_assert(is_for_each_element_callback_v<void, LEAVE_ARRAY_ELEMENT_MEMBER_CALLBACK>);
1041 const auto [element_name, array_pos] =
findArrayPos(name);
1044 enter_element_member_callback(child, parent);
1046 const auto array_element_child = child.getArrayElement(array_pos.get());
1047 if (array_element_child) {
1048 enter_array_element_member_callback(array_element_child, parent);
1050 target_element_callback(array_element_child, parent);
1055 target_element_callback,
1056 enter_element_member_callback,
1057 leave_element_member_callback,
1058 enter_array_element_member_callback,
1059 leave_array_element_member_callback);
1061 leave_array_element_member_callback(array_element_child, parent);
1066 target_element_callback(child, parent);
1071 target_element_callback,
1072 enter_element_member_callback,
1073 leave_element_member_callback,
1074 enter_array_element_member_callback,
1075 leave_array_element_member_callback);
1078 leave_element_member_callback(child, parent);
1104template <
typename TARGET_ELEMENT_CALLBACK,
1105 typename ENTER_ELEMENT_MEMBER_CALLBACK,
1106 typename LEAVE_ELEMENT_MEMBER_CALLBACK>
1108 std::string_view path,
1109 TARGET_ELEMENT_CALLBACK&& target_element_callback,
1110 ENTER_ELEMENT_MEMBER_CALLBACK&& enter_element_member_callback,
1111 LEAVE_ELEMENT_MEMBER_CALLBACK&& leave_element_member_callback)
1116 std::forward<TARGET_ELEMENT_CALLBACK>(target_element_callback),
1117 std::forward<ENTER_ELEMENT_MEMBER_CALLBACK>(enter_element_member_callback),
1118 std::forward<LEAVE_ELEMENT_MEMBER_CALLBACK>(leave_element_member_callback),
1119 [](
const auto&,
const auto&)
noexcept ->
void {},
1120 [](
const auto&,
const auto&)
noexcept ->
void {});
Definition dd_struct_access.h:371
int difference_type
difference value type definition
Definition dd_struct_access.h:421
const StructElementAccess * const_pointer
pointer to const data value type definition
Definition dd_struct_access.h:417
const StructElementAccess & const_reference
const reference value type definition
Definition dd_struct_access.h:409
StructElementAccess & reference
reference value type definition
Definition dd_struct_access.h:405
std::forward_iterator_tag iterator_category
iterator type definition
Definition dd_struct_access.h:425
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:397
StructElementAccess value_type
iterator value type definition
Definition dd_struct_access.h:401
StructElementAccess * pointer
pointer value type definition
Definition dd_struct_access.h:413
Iterator to iterate thru the StructTypeAccess.
Definition dd_struct_access.h:481
const StructElementAccess & const_reference
const reference value type definition
Definition dd_struct_access.h:519
int difference_type
difference value type definition
Definition dd_struct_access.h:531
StructElementAccessIterator & operator=(const StructElementAccessIterator &)
Copy Assignment Operator.
const StructElementAccess * const_pointer
pointer to const data value type definition
Definition dd_struct_access.h:527
StructElementAccessIterator(const StructElementAccessIterator &)
Copy CTOR.
StructElementAccess & reference
reference value type definition
Definition dd_struct_access.h:515
StructElementAccess value_type
iterator value type definition
Definition dd_struct_access.h:511
StructElementAccess * pointer
pointer value type definition
Definition dd_struct_access.h:523
StructElementAccessIterator self_type
this iterator type definition
Definition dd_struct_access.h:507
std::forward_iterator_tag iterator_category
iterator type definition
Definition dd_struct_access.h:535
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)
bool hasValidElementCount() const
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:306
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.
bool isPadding() const
Determines if the element is a padding.
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:605
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:734
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:794
std::pair< std::string_view, std::string_view > findFirstNameInPath(std::string_view name_path)
Extract first naming component from a path.
datamodel::StructType StructType
Definition dd.h:59
std::pair< std::string_view, OptionalSize > findArrayPos(std::string_view name)
Determine the position of the named element within an array.
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, ACCESS_LEAF_CALLBACK &&access_leaf_callback, ENTER_ELEMENT_MEMBER_CALLBACK &&enter_element_member_callback, LEAVE_ELEMENT_MEMBER_CALLBACK &&leave_element_member_callback, ENTER_ARRAY_ELEMENT_MEMBER_CALLBACK &&enter_array_element_member_callback, LEAVE_ARRAY_ELEMENT_MEMBER_CALLBACK &&leave_array_element_member_callback, bool filter_padding_elements=true, bool continue_arrays_after_skip=true)
Traverse all elements of a struct type access in infix order and calls the callbacks.
Definition dd_struct_access.h:854
@ element_type_info
Element Type Info.
Definition dd_infomodel_type.h:44
void forEachElementInPathInfix(const StructTypeAccess &parent, std::string_view path, TARGET_ELEMENT_CALLBACK &&target_element_callback, ENTER_ELEMENT_MEMBER_CALLBACK &&enter_element_member_callback, LEAVE_ELEMENT_MEMBER_CALLBACK &&leave_element_member_callback, ENTER_ARRAY_ELEMENT_MEMBER_CALLBACK &&enter_array_element_member_callback, LEAVE_ARRAY_ELEMENT_MEMBER_CALLBACK &&leave_array_element_member_callback)
Traverse all elements along a given path in struct type access in infix order and calls the callbacks...
Definition dd_struct_access.h:1024
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:802
definition of the ddl namespace
Definition codec.h:21