15#ifndef DDL_CODEC_ITERATOR_CLASS_HEADER
16#define DDL_CODEC_ITERATOR_CLASS_HEADER
27template <
typename ElementAccessType,
typename ChildElementsType>
29template <
typename ElementAccessType,
typename ChildElementsType>
31template <
typename ElementAccessType,
typename ChildElementsType>
41template <
typename ElementAccessType>
82 const auto old_index = _element.getIndex();
95 return _element.getIndex() == rhs._element.getIndex();
106 return _element.getIndex() != rhs._element.getIndex();
160template <
typename ElementAccessType>
196 const auto old_index = _element.getIndex();
198 return self_type(old_index, _element.getAccess());
210 return _element.getIndex() == rhs._element.getIndex();
221 return _element.getIndex() != rhs._element.getIndex();
256template <
typename ElementAccessType>
316 if (_child_element_count > 0) {
319 ElementAccessType::resolve(_access, begin_index);
320 size_t element_child_count = begin_index.getLayout().child_element_count;
322 std::move(begin_index), _child_element_count, element_child_count, _access));
343 if (_child_element_count > 0) {
347 _child_element_count,
369 if (_child_element_count > 0) {
370 CodecIndex begin_index(_codec_base_index, {0, 0});
371 ElementAccessType::resolve(_access, begin_index);
372 size_t element_child_count = begin_index.getLayout().child_element_count;
374 std::move(begin_index), _child_element_count, element_child_count, _access));
386 if (_child_element_count > 0) {
388 _child_element_count,
402 return _child_element_count;
407 : _codec_base_index(base_index),
408 _child_element_count(ElementAccessType::getChildCount(access, base_index)),
414 : _codec_base_index(base_index), _child_element_count(child_element_count), _access(access)
417 void resetChildCount(
size_t child_element_count)
419 _child_element_count = child_element_count;
421 void resetChildCount()
423 resetChildCount(ElementAccessType::getChildCount(_access, _codec_base_index));
426 const CodecIndex& _codec_base_index;
427 size_t _child_element_count;
438template <
typename AccessType>
455 return access.getElement(full_path);
466 return access.getElement(index);
480 std::string_view relative_path)
493 return access.getElementChildCount(index);
507 return access.getElementFullName(index);
521 return access.getElementName(index);
535 return access.getElementBaseName(index);
547 return access.resolve(index);
559template <
typename ElementAccessType,
typename ChildElementsType = ChildElements<ElementAccessType>>
603 : _codec_index(std::move(other._codec_index)),
604 _end_element_index(std::move(other._end_element_index)),
605 _child_elements(_codec_index, other._child_elements.size(), other._access),
606 _access(other._access)
616 _codec_index = std::move(other._codec_index);
617 _end_element_index = std::move(other._end_element_index);
618 _child_elements =
child_elements_type(_codec_index, other._child_elements.size(), _access);
625 : _codec_index(other._codec_index),
626 _end_element_index(other._end_element_index),
627 _child_elements(_codec_index, other._child_elements.size(), other._access),
628 _access(other._access)
638 _codec_index = other._codec_index;
639 _end_element_index = other._end_element_index;
640 _child_elements =
child_elements_type(_codec_index, other._child_elements.size(), _access);
662 return _codec_index.getLayout().array_size;
670 return _codec_index.getType();
681 return ElementAccessType::getFullName(_access, _codec_index);
692 return ElementAccessType::getName(_access, _codec_index);
703 return ElementAccessType::getBaseName(_access, _codec_index);
712 return _codec_index.getLayout().array_size > 1;
721 return _child_elements.size() > 0;
730 return _child_elements;
739 return ElementAccessType::getChildElement(_access, _codec_index, path);
748 return self_type(_codec_index.getIndexForArrayPos(array_pos), getAccess());
762 size_t end_element_index,
763 size_t child_elements_count,
765 : _codec_index(std::move(index)),
766 _end_element_index(end_element_index),
767 _child_elements(_codec_index, child_elements_count, access),
772 : _codec_index(std::move(index)),
773 _end_element_index(end_element_index),
775 _codec_index, ElementAccessType::getChildCount(access, _codec_index), access),
780 : _codec_index(std::move(ElementAccessType::getElement(access, full_path)._codec_index)),
781 _end_element_index(CodecIndex::ElementIndex::_invalid_element_index),
782 _child_elements(_codec_index, access),
788 : _codec_index(std::move(index)),
789 _end_element_index(CodecIndex::ElementIndex::_invalid_element_index),
790 _child_elements(_codec_index, access),
795 : _codec_index(CodecIndex()),
796 _end_element_index(CodecIndex::ElementIndex::_invalid_element_index),
797 _child_elements(_codec_index, 0, access),
803 auto break_increasing =
false;
804 auto index_valid =
false;
805 while (!break_increasing) {
807 const auto element_index = _codec_index.back();
809 element_index.getIndex() < _end_element_index) {
810 ElementAccessType::resolve(_access, _codec_index);
811 if (_codec_index.getLayout().array_size != 0) {
812 break_increasing =
true;
817 break_increasing =
true;
821 _child_elements.resetChildCount(_codec_index.getLayout().child_element_count);
829 void resetIndex(CodecIndex&& codec_index)
831 _codec_index = std::move(codec_index);
832 _child_elements.resetChildCount();
834 CodecIndex _codec_index;
835 size_t _end_element_index;
848template <
typename AccessType>
866 return access.getElement(full_path);
877 return access.getElement(index);
891 std::string_view relative_path)
905 template <
typename T>
908 return access.template getElementValue<T>(index);
920 return access.getElementVariantValue(index);
932 return access.getElementStringValue(index);
947 access.getElementRawValue(index, value, value_size);
958 return access.getElementAddress(index);
968template <
typename ElementAccessType,
typename ChildElementsType = ChildElements<ElementAccessType>>
1016 template <
typename T>
1019 return ElementAccessType::template
getValue<T>(base_type::getAccess(),
1046 ElementAccessType::getRawValue(
1064 return ElementAccessType::getChildElement(
1075 base_type::getAccess());
1080 size_t end_element_index,
1081 size_t child_elements_count,
1083 :
base_type(std::move(index), end_element_index, child_elements_count, access)
1087 :
base_type(std::move(index), end_element_index, access)
1114template <
typename AccessType>
1132 return access.getElement(full_path);
1143 return access.getElement(index);
1156 template <
typename T>
1159 access.template setElementValue<T>(index, value);
1172 access.setElementVariantValue(index, value);
1183 const std::string& value)
1185 access.setElementStringValue(index, value);
1200 access.setElementRawValue(index, value, value_size);
1211 return access.getElementAddress(index);
1220template <
typename ElementAccessType,
typename ChildElementsType = ChildElements<ElementAccessType>>
1270 template <
typename T>
1283 return ElementAccessType::setVariantValue(
1293 return ElementAccessType::setStringValue(
1304 return ElementAccessType::setRawValue(
1314 void reset(
bool zero_value_of_known_type =
false)
1317 if (layout.constant_info->isConstant()) {
1318 return ElementAccessType::setVariantValue(base_type::getAccess(),
1320 layout.constant_info->getConstantValue());
1322 else if (layout.default_value_info->hasDefaultValue()) {
1323 return ElementAccessType::setVariantValue(base_type::getAccess(),
1325 layout.default_value_info->getDefaultValue());
1329 if (zero_value_of_known_type) {
1334 uint64_t null_value = 0;
1335 return ElementAccessType::setRawValue(base_type::getAccess(),
1338 sizeof(null_value));
1362 return factory_base_type::_child_elements;
1372 return ElementAccessType::getChildElement(
1384 return ElementAccessType::getChildElement(
1395 base_type::getAccess());
1406 base_type::getAccess());
1411 size_t end_element_index,
1412 size_t child_elements_count,
1414 :
base_type(std::move(index), end_element_index, child_elements_count, access)
1418 :
base_type(std::move(index), end_element_index, access)
1474template <
typename ElementsType>
1476 ElementsType& elements,
1477 const std::function<
void(std::conditional_t<std::is_const<ElementsType>::value,
1478 const typename ElementsType::element_type,
1479 typename ElementsType::element_type>&)>& func)
1481 for (
auto& element: elements) {
1482 if (element.hasChildren()) {
1483 if (element.isArray()) {
1484 for (
size_t array_pos = 0; array_pos < element.getArraySize(); ++array_pos) {
1485 auto array_element = element.getArrayElement(array_pos);
1486 auto& children = array_element.getChildElements();
1491 auto& children = element.getChildElements();
1496 if (element.isArray()) {
1497 for (
size_t array_pos = 0; array_pos < element.getArraySize(); ++array_pos) {
1498 auto array_element = element.getArrayElement(array_pos);
1499 func(array_element);
1553template <
typename ElementsType>
1555 ElementsType& elements,
1556 const std::function<
void(std::conditional_t<std::is_const<ElementsType>::value,
1557 const typename ElementsType::element_type,
1558 typename ElementsType::element_type>&)>& func)
1560 for (
auto& element: elements) {
1562 if (element.hasChildren()) {
1563 auto& children = element.getChildElements();
~ChildElements()=default
DTOR.
ElementIteratorConst< sample_decoder_access< const cSampleDecoderBase > > const_iterator
Definition codec_iterator.h:263
ChildElements & operator=(const ChildElements &)=delete
no copy operator
iterator end()
end
Definition codec_iterator.h:384
typename sample_decoder_access< const cSampleDecoderBase >::element_type element_type
Definition codec_iterator.h:262
ElementIterator< sample_decoder_access< const cSampleDecoderBase > > iterator
Definition codec_iterator.h:264
const_iterator end() const
end
Definition codec_iterator.h:359
iterator begin()
begin
Definition codec_iterator.h:367
const_iterator begin() const
begin
Definition codec_iterator.h:333
ChildElements(ChildElements &&)=default
move CTOR
ChildElements(const ChildElements &)=delete
no copy CTOR
const_iterator cend() const
cend
Definition codec_iterator.h:341
typename sample_decoder_access< const cSampleDecoderBase >::access_type access_type
Definition codec_iterator.h:260
ChildElements & operator=(ChildElements &&)=default
move operator
const_iterator cbegin() const
cbegin
Definition codec_iterator.h:314
size_t size() const
Size of the container (child count)
Definition codec_iterator.h:400
A element access type concept template to retrieve element information from the AccessType,...
Definition codec_iterator.h:1115
static void setStringValue(access_type &access, const CodecIndex &index, const std::string &value)
Sets the value from value as string.
Definition codec_iterator.h:1181
AccessType access_type
access type
Definition codec_iterator.h:1117
static void setVariantValue(access_type &access, const CodecIndex &index, const a_util::variant::Variant &value)
Sets the value from value as variant.
Definition codec_iterator.h:1168
static void setValue(access_type &access, const CodecIndex &index, const T &value)
Sets the value from value of type T.
Definition codec_iterator.h:1157
static void setRawValue(access_type &access, const CodecIndex &index, const void *value, size_t value_size)
Set the value by copying from a value buffer.
Definition codec_iterator.h:1195
static element_type getElement(access_type &access, const CodecIndex &index)
Get a element object for the given index.
Definition codec_iterator.h:1141
static element_type getElement(access_type &access, std::string_view full_path)
Get a element object for the given full_path.
Definition codec_iterator.h:1130
CodecElementAccess< AccessType > self_type
Definition codec_iterator.h:1118
static void * getAddress(access_type &access, const CodecIndex &index)
Get the address (with write access)
Definition codec_iterator.h:1209
CodecElement< self_type, ChildElements< self_type > > element_type
supported element type
Definition codec_iterator.h:1120
A CodecElement to get and set values.
Definition codec_iterator.h:1221
void setValue(const T &value)
Sets the value from value of type T.
Definition codec_iterator.h:1271
self_type getChildElement(std::string_view path) const
Get a dedicated ChildElement by name.
Definition codec_iterator.h:1370
CodecElement< sample_codec_access< cStaticSampleCodec >, ChildElements< sample_codec_access< cStaticSampleCodec > > > self_type
Definition codec_iterator.h:1226
typename child_elements_type::iterator iterator_type
Definition codec_iterator.h:1230
typename factory_base_type::child_elements_type child_elements_type
Definition codec_iterator.h:1229
void setRawValue(const void *value, size_t value_size)
Set the value by copying from a value buffer.
Definition codec_iterator.h:1302
DecoderElement< sample_codec_access< cStaticSampleCodec >, ChildElements< sample_codec_access< cStaticSampleCodec > > > base_type
Definition codec_iterator.h:1225
self_type getArrayElement(size_t array_pos=0)
Get the array element of the given array_pos.
Definition codec_iterator.h:1403
FactoryElement< sample_codec_access< cStaticSampleCodec >, ChildElements< sample_codec_access< cStaticSampleCodec > > > factory_base_type
Definition codec_iterator.h:1224
self_type getArrayElement(size_t array_pos=0) const
Get the array element of the given array_pos.
Definition codec_iterator.h:1392
typename child_elements_type::const_iterator const_iterator_type
Definition codec_iterator.h:1232
child_elements_type & getChildElements()
Gets an reference to the child elements.
Definition codec_iterator.h:1360
typename sample_codec_access< cStaticSampleCodec >::access_type access_type
Definition codec_iterator.h:1227
void reset(bool zero_value_of_known_type=false)
Reset the elements value to their default values, constant values defined in the data definition or z...
Definition codec_iterator.h:1314
void setStringValue(const std::string &value)
Sets the value from value as string.
Definition codec_iterator.h:1291
CodecElement()=delete
CTOR.
self_type getChildElement(std::string_view name)
Get a dedicated ChildElement by name.
Definition codec_iterator.h:1382
void setVariantValue(const a_util::variant::Variant &value)
Sets the value from value as variant.
Definition codec_iterator.h:1281
void * getAddress()
Get the address (with writing access)
Definition codec_iterator.h:1349
static constexpr size_t _invalid_element_index
Invalid element index.
Definition codec_index.h:342
static constexpr size_t _invalid_array_pos
Invalid array pos.
Definition codec_index.h:346
Definition codec_index.h:276
const ElementLayout & getLayout() const
Get the Layout.
A element access type concept template to retrieve element information from the AccessType and get th...
Definition codec_iterator.h:849
AccessType access_type
access type in use
Definition codec_iterator.h:851
static element_type getChildElement(access_type &access, const CodecIndex &parent_index, std::string_view relative_path)
Get a child element object for the given element_name.
Definition codec_iterator.h:889
static element_type getElement(access_type &access, const CodecIndex &index)
Get a element object for the given index.
Definition codec_iterator.h:875
static element_type getElement(access_type &access, std::string_view full_path)
Get a element object for the given full_element_name.
Definition codec_iterator.h:864
DecoderElementAccess< AccessType > self_type
Definition codec_iterator.h:852
static const void * getAddress(access_type &access, const CodecIndex &index)
Get the address of the element.
Definition codec_iterator.h:956
DecoderElement< self_type, ChildElements< self_type > > element_type
supported element type
Definition codec_iterator.h:854
static void getRawValue(access_type &access, const CodecIndex &index, void *value, size_t value_size)
Get the value by copy to the given value buffer.
Definition codec_iterator.h:942
static std::string getStringValue(access_type &access, const CodecIndex &index)
Get the value as type string.
Definition codec_iterator.h:930
static a_util::variant::Variant getVariantValue(access_type &access, const CodecIndex &index)
Get the value as variant.
Definition codec_iterator.h:918
static T getValue(access_type &access, const CodecIndex &index)
Get the value as type T.
Definition codec_iterator.h:906
A DecoderElement to get values.
Definition codec_iterator.h:969
typename sample_decoder_access< const cSampleDecoderBase >::access_type access_type
Definition codec_iterator.h:974
void getRawValue(void *value, size_t value_size) const
Get the as copy to the value buffer.
Definition codec_iterator.h:1044
typename child_elements_type::iterator iterator_type
Definition codec_iterator.h:976
T getValue() const
Get the value as type T.
Definition codec_iterator.h:1017
self_type getArrayElement(size_t array_pos=0) const
Get the array element of the given array_pos.
Definition codec_iterator.h:1072
const void * getAddress() const
Get the address of the element.
Definition codec_iterator.h:1053
DecoderElement< sample_decoder_access< const cSampleDecoderBase >, ChildElements< sample_decoder_access< const cSampleDecoderBase > > > self_type
Definition codec_iterator.h:972
self_type getChildElement(std::string_view path) const
Get the child element with the given name.
Definition codec_iterator.h:1062
typename child_elements_type::const_iterator const_iterator_type
Definition codec_iterator.h:978
DecoderElement()=delete
CTOR.
typename base_type::child_elements_type child_elements_type
Definition codec_iterator.h:975
FactoryElement< sample_decoder_access< const cSampleDecoderBase >, ChildElements< sample_decoder_access< const cSampleDecoderBase > > > base_type
Definition codec_iterator.h:971
std::string getStringValue() const
Get the value as string.
Definition codec_iterator.h:1034
a_util::variant::Variant getVariantValue() const
Get the value as variant.
Definition codec_iterator.h:1026
The const element iterator.
Definition codec_iterator.h:161
ElementIteratorConst()=delete
default CTOR
const element_type value_type
const value type of the iterator
Definition codec_iterator.h:164
const_pointer operator->() const
pointer access (check for end!)
Definition codec_iterator.h:237
std::forward_iterator_tag iterator_category
iterator type
Definition codec_iterator.h:168
ElementIteratorConst & operator++()
increasing operator to the next position.
Definition codec_iterator.h:185
value_type * const_pointer
pointer to const data value type
Definition codec_iterator.h:166
ElementIteratorConst operator++(int)
iterator increasing.
Definition codec_iterator.h:194
const_reference operator*() const
defering access (check for end!)
Definition codec_iterator.h:228
value_type & const_reference
const reference value type
Definition codec_iterator.h:165
bool operator==(const ElementIteratorConst &rhs) const
checks for equality (refering the same element!)
Definition codec_iterator.h:208
bool operator!=(const ElementIteratorConst &rhs) const
checks for not equality (does not refer the same element!)
Definition codec_iterator.h:219
ElementIteratorConst(value_type &&element)
CTOR for one element.
Definition codec_iterator.h:178
typename ElementAccessType::element_type element_type
The element type in use.
Definition codec_iterator.h:163
int difference_type
difference value type
Definition codec_iterator.h:167
The element iterator.
Definition codec_iterator.h:42
const value_type & const_reference
const reference value type
Definition codec_iterator.h:47
ElementIterator operator++(int)
iterator increasing.
Definition codec_iterator.h:80
ElementIterator(value_type &&element)
CTOR for one element.
Definition codec_iterator.h:62
const_reference operator*() const
defering access (check for end!)
Definition codec_iterator.h:113
bool operator==(const ElementIterator &rhs) const
checks for equality (refering the same element!)
Definition codec_iterator.h:93
int difference_type
difference value type
Definition codec_iterator.h:50
typename ElementAccessType::element_type element_type
The element type in use.
Definition codec_iterator.h:44
std::forward_iterator_tag iterator_category
iterator type
Definition codec_iterator.h:51
ElementIterator & operator++()
increasing operator to the next position.
Definition codec_iterator.h:70
value_type & reference
Reference value type.
Definition codec_iterator.h:46
reference operator*()
defering access (check for end!)
Definition codec_iterator.h:131
element_type value_type
Value type of the iterator.
Definition codec_iterator.h:45
const_pointer operator->() const
pointer access (check for end!)
Definition codec_iterator.h:122
bool operator!=(const ElementIterator &rhs) const
checks for not equality (does not refer the same element!)
Definition codec_iterator.h:104
const value_type * const_pointer
pointer to const data value type
Definition codec_iterator.h:49
value_type * pointer
Pointer type.
Definition codec_iterator.h:48
ElementIterator()=delete
default CTOR
pointer operator->()
pointer access (check for end!)
Definition codec_iterator.h:140
A factory element access type concept template to retrieve element information from the AccessType....
Definition codec_iterator.h:439
static std::string getBaseName(access_type &access, const CodecIndex &index)
Get the name of the element within its level structure. If the element is an array you get the elemen...
Definition codec_iterator.h:533
FactoryElementAccess< AccessType > self_type
self type
Definition codec_iterator.h:442
static element_type getElement(access_type &access, const CodecIndex &index)
Get a element object for the given index.
Definition codec_iterator.h:464
static element_type getElement(access_type &access, std::string_view full_path)
Get a element object for the given full_element_name.
Definition codec_iterator.h:453
static std::string getName(access_type &access, const CodecIndex &index)
Get the name of the element within its level structure. If the element is an array you get the elemen...
Definition codec_iterator.h:519
static std::string getFullName(access_type &access, const CodecIndex &index)
Get the full name of the element within its main structure. If the element is an array you get the el...
Definition codec_iterator.h:505
static size_t getChildCount(access_type &access, const CodecIndex &index)
Get the Child Count.
Definition codec_iterator.h:491
AccessType access_type
The access type (CodecFactory, Codec, Decoder, etc.)
Definition codec_iterator.h:441
static void resolve(access_type &access, CodecIndex &index)
Resolves the given CodecIndex and set the layout information.
Definition codec_iterator.h:545
static element_type getChildElement(access_type &access, const CodecIndex &parent_index, std::string_view relative_path)
Get a child element object for the given element_name.
Definition codec_iterator.h:478
FactoryElement< self_type, ChildElements< self_type > > element_type
element type
Definition codec_iterator.h:443
A FactoryElement.
Definition codec_iterator.h:560
self_type getArrayElement(size_t array_pos=0) const
Get the array element of the given array_pos.
Definition codec_iterator.h:746
typename child_elements_type::iterator iterator_type
Definition codec_iterator.h:565
~FactoryElement()=default
DTOR.
FactoryElement & operator=(const FactoryElement &other)
move assignment operator
Definition codec_iterator.h:636
FactoryElement< sample_codec_factory_access< const cSampleCodecFactory >, ChildElements< sample_codec_factory_access< const cSampleCodecFactory > > > self_type
Definition codec_iterator.h:562
ChildElements< sample_codec_factory_access< const cSampleCodecFactory > > child_elements_type
Definition codec_iterator.h:564
const child_elements_type & getChildElements() const
Get the ChildElements.
Definition codec_iterator.h:728
std::string getBaseName() const
Get the base name of the element. If the element is an array you get the elements base name represent...
Definition codec_iterator.h:701
bool isArray() const
Get array information.
Definition codec_iterator.h:710
bool isValid() const
Get validation indormation.
Definition codec_iterator.h:755
self_type getChildElement(std::string_view path) const
Get the child element with the given name.
Definition codec_iterator.h:737
std::string getFullName() const
Get the full name of the element. If the element is an array you get the elements array name represen...
Definition codec_iterator.h:679
typename child_elements_type::const_iterator const_iterator_type
Definition codec_iterator.h:567
FactoryElement(const FactoryElement &other)
copy CTOR
Definition codec_iterator.h:624
size_t getArraySize() const
Get the array size.
Definition codec_iterator.h:660
FactoryElement(FactoryElement &&other)
move CTOR
Definition codec_iterator.h:602
ddl::codec::ElementType getType() const
Get the type of the element.
Definition codec_iterator.h:668
bool hasChildren() const
Get children information.
Definition codec_iterator.h:719
FactoryElement & operator=(FactoryElement &&other)
copy assignment operator
Definition codec_iterator.h:614
std::string getName() const
Get the name of the element If the element is an array you get the elements array name representation...
Definition codec_iterator.h:690
FactoryElement()=delete
no CTOR
const CodecIndex & getIndex() const
Get the codec index of the element.
Definition codec_iterator.h:652
typename sample_codec_factory_access< const cSampleCodecFactory >::access_type access_type
Definition codec_iterator.h:563
Namespace for the new faster CodecFactory/Decoder/Codec implementation.
Definition codec.h:22
void forEachLeafElement(ElementsType &elements, const std::function< void(std::conditional_t< std::is_const< ElementsType >::value, const typename ElementsType::element_type, typename ElementsType::element_type > &)> &func)
Iterates ALL leaf elements within ALL array elements.
Definition codec_iterator.h:1475
ElementType
The element type of the value.
Definition codec_type_info.h:30
@ cet_sub_codec
type marks a subcodec/substructure with children
Definition codec_type_info.h:43
@ cet_empty
Variant type is empty.
Definition codec_type_info.h:31
@ cet_user_type
type marks a user defined type
Definition codec_type_info.h:44
void forEachElement(ElementsType &elements, const std::function< void(std::conditional_t< std::is_const< ElementsType >::value, const typename ElementsType::element_type, typename ElementsType::element_type > &)> &func)
Iterates elements without array elements (also structures).
Definition codec_iterator.h:1554
definition of the ddl namespace
Definition codec.h:21