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) {
318 ElementAccessType::resolve(_access, begin_index);
319 size_t element_child_count = begin_index.getLayout().child_element_count;
321 std::move(begin_index), _child_element_count, element_child_count, _access));
342 if (_child_element_count > 0) {
345 _child_element_count,
367 if (_child_element_count > 0) {
368 CodecIndex begin_index(_codec_base_index, {0, 0});
369 ElementAccessType::resolve(_access, begin_index);
370 size_t element_child_count = begin_index.getLayout().child_element_count;
372 std::move(begin_index), _child_element_count, element_child_count, _access));
384 if (_child_element_count > 0) {
386 _child_element_count,
400 return _child_element_count;
405 : _codec_base_index(base_index),
406 _child_element_count(ElementAccessType::getChildCount(access, base_index)),
412 : _codec_base_index(base_index), _child_element_count(child_element_count), _access(access)
415 void resetChildCount(
size_t child_element_count)
417 _child_element_count = child_element_count;
419 void resetChildCount()
421 resetChildCount(ElementAccessType::getChildCount(_access, _codec_base_index));
424 const CodecIndex& _codec_base_index;
425 size_t _child_element_count;
436template <
typename AccessType>
453 return access.getElement(full_element_name);
464 return access.getElement(index);
475 return access.getElementChildCount(index);
489 return access.getElementFullName(index);
503 return access.getElementName(index);
517 return access.getElementBaseName(index);
529 return access.resolve(index);
541template <
typename ElementAccessType,
typename ChildElementsType = ChildElements<ElementAccessType>>
585 : _codec_index(std::move(other._codec_index)),
586 _end_element_index(std::move(other._end_element_index)),
587 _child_elements(_codec_index, other._child_elements.size(), other._access),
588 _access(other._access)
598 _codec_index = std::move(other._codec_index);
599 _end_element_index = std::move(other._end_element_index);
600 _child_elements =
child_elements_type(_codec_index, other._child_elements.size(), _access);
607 : _codec_index(other._codec_index),
608 _end_element_index(other._end_element_index),
609 _child_elements(_codec_index, other._child_elements.size(), other._access),
610 _access(other._access)
620 _codec_index = other._codec_index;
621 _end_element_index = other._end_element_index;
622 _child_elements =
child_elements_type(_codec_index, other._child_elements.size(), _access);
644 return _codec_index.getLayout().array_size;
652 return _codec_index.getType();
663 return ElementAccessType::getFullName(_access, _codec_index);
674 return ElementAccessType::getName(_access, _codec_index);
685 return ElementAccessType::getBaseName(_access, _codec_index);
694 return _codec_index.getLayout().array_size > 1;
703 return _child_elements.size() > 0;
712 return _child_elements;
722 full_name.append(
".");
723 full_name.append(name);
724 return self_type(full_name, getAccess());
733 return self_type(_codec_index.getIndexForArrayPos(array_pos), getAccess());
747 size_t end_element_index,
748 size_t child_elements_count,
750 : _codec_index(std::move(index)),
751 _end_element_index(end_element_index),
752 _child_elements(_codec_index, child_elements_count, access),
757 : _codec_index(std::move(index)),
758 _end_element_index(end_element_index),
760 _codec_index, ElementAccessType::getChildCount(access, _codec_index), access),
765 : _codec_index(std::move(ElementAccessType::getElement(access, element_name)._codec_index)),
766 _end_element_index(CodecIndex::ElementIndex::_invalid_element_index),
767 _child_elements(_codec_index, access),
773 : _codec_index(std::move(index)),
774 _end_element_index(CodecIndex::ElementIndex::_invalid_element_index),
775 _child_elements(_codec_index, access),
780 : _codec_index(CodecIndex()),
781 _end_element_index(CodecIndex::ElementIndex::_invalid_element_index),
782 _child_elements(_codec_index, 0, access),
788 auto break_increasing =
false;
789 auto index_valid =
false;
790 while (!break_increasing) {
792 const auto element_index = _codec_index.back();
794 element_index.getIndex() < _end_element_index) {
795 ElementAccessType::resolve(_access, _codec_index);
796 if (_codec_index.getLayout().array_size != 0) {
797 break_increasing =
true;
802 break_increasing =
true;
806 _child_elements.resetChildCount(_codec_index.getLayout().child_element_count);
814 void resetIndex(CodecIndex&& codec_index)
816 _codec_index = std::move(codec_index);
817 _child_elements.resetChildCount();
819 CodecIndex _codec_index;
820 size_t _end_element_index;
833template <
typename AccessType>
851 return access.getElement(full_element_name);
862 return access.getElement(index);
874 template <
typename T>
877 return access.template getElementValue<T>(index);
889 return access.getElementVariantValue(index);
901 return access.getElementStringValue(index);
916 access.getElementRawValue(index, value, value_size);
927 return access.getElementAddress(index);
937template <
typename ElementAccessType,
typename ChildElementsType = ChildElements<ElementAccessType>>
985 template <
typename T>
988 return ElementAccessType::template
getValue<T>(base_type::getAccess(),
1015 ElementAccessType::getRawValue(
1034 full_name.append(
".");
1035 full_name.append(name);
1036 return self_type(full_name, base_type::getAccess());
1046 base_type::getAccess());
1051 size_t end_element_index,
1052 size_t child_elements_count,
1054 :
base_type(std::move(index), end_element_index, child_elements_count, access)
1058 :
base_type(std::move(index), end_element_index, access)
1085template <
typename AccessType>
1103 return access.getElement(full_element_name);
1114 return access.getElement(index);
1126 template <
typename T>
1129 access.template setElementValue<T>(index, value);
1142 access.setElementVariantValue(index, value);
1153 const std::string& value)
1155 access.setElementStringValue(index, value);
1170 access.setElementRawValue(index, value, value_size);
1181 return access.getElementAddress(index);
1190template <
typename ElementAccessType,
typename ChildElementsType = ChildElements<ElementAccessType>>
1240 template <
typename T>
1253 return ElementAccessType::setVariantValue(
1263 return ElementAccessType::setStringValue(
1274 return ElementAccessType::setRawValue(
1284 void reset(
bool zero_value_of_known_type =
false)
1287 if (layout.constant_info->isConstant()) {
1288 return ElementAccessType::setVariantValue(base_type::getAccess(),
1290 layout.constant_info->getConstantValue());
1292 else if (layout.default_value_info->hasDefaultValue()) {
1293 return ElementAccessType::setVariantValue(base_type::getAccess(),
1295 layout.default_value_info->getDefaultValue());
1299 if (zero_value_of_known_type) {
1304 uint64_t null_value = 0;
1305 return ElementAccessType::setRawValue(base_type::getAccess(),
1308 sizeof(null_value));
1284 void reset(
bool zero_value_of_known_type =
false) {
…}
1332 return factory_base_type::_child_elements;
1343 full_name.append(
".");
1344 full_name.append(name);
1345 return self_type(full_name, base_type::getAccess());
1357 full_name.append(
".");
1358 full_name.append(name);
1359 return self_type(full_name, base_type::getAccess());
1369 base_type::getAccess());
1380 base_type::getAccess());
1385 size_t end_element_index,
1386 size_t child_elements_count,
1388 :
base_type(std::move(index), end_element_index, child_elements_count, access)
1392 :
base_type(std::move(index), end_element_index, access)
1448template <
typename ElementsType>
1450 ElementsType& elements,
1451 const std::function<
void(std::conditional_t<std::is_const<ElementsType>::value,
1452 const typename ElementsType::element_type,
1453 typename ElementsType::element_type>&)>& func)
1455 for (
auto& element: elements) {
1456 if (element.hasChildren()) {
1457 if (element.isArray()) {
1458 for (
size_t array_pos = 0; array_pos < element.getArraySize(); ++array_pos) {
1459 auto array_element = element.getArrayElement(array_pos);
1460 auto& children = array_element.getChildElements();
1465 auto& children = element.getChildElements();
1470 if (element.isArray()) {
1471 for (
size_t array_pos = 0; array_pos < element.getArraySize(); ++array_pos) {
1472 auto array_element = element.getArrayElement(array_pos);
1473 func(array_element);
1527template <
typename ElementsType>
1529 ElementsType& elements,
1530 const std::function<
void(std::conditional_t<std::is_const<ElementsType>::value,
1531 const typename ElementsType::element_type,
1532 typename ElementsType::element_type>&)>& func)
1534 for (
auto& element: elements) {
1536 if (element.hasChildren()) {
1537 auto& children = element.getChildElements();
Container type, able to store any primitive data type (and arrays thereof)
typename DecoderElementAccess< const Decoder >::element_type element_type
ChildElements & operator=(ChildElements &&)=default
move operator
~ChildElements()=default
DTOR.
size_t size() const
Size of the container (child count)
const_iterator begin() const
begin
ElementIterator< DecoderElementAccess< const Decoder > > iterator
ElementIteratorConst< DecoderElementAccess< const Decoder > > const_iterator
const_iterator cbegin() const
cbegin
ChildElements(ChildElements &&)=default
move CTOR
ChildElements & operator=(const ChildElements &)=delete
no copy operator
const_iterator cend() const
cend
const_iterator end() const
end
typename DecoderElementAccess< const Decoder >::access_type access_type
ChildElements(const ChildElements &)=delete
no copy CTOR
A element access type concept template to retrieve element information from the AccessType,...
AccessType access_type
access type
static element_type getElement(access_type &access, const std::string &full_element_name)
Get a element object for the given full_element_name.
CodecElement< self_type, ChildElements< self_type > > element_type
supported element type
static element_type getElement(access_type &access, const CodecIndex &index)
Get a element object for the given index.
static void setStringValue(access_type &access, const CodecIndex &index, const std::string &value)
Sets the value from value as string.
static void setValue(access_type &access, const CodecIndex &index, const T &value)
Sets the value from value of type T.
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.
static void setVariantValue(access_type &access, const CodecIndex &index, const a_util::variant::Variant &value)
Sets the value from value as variant.
CodecElementAccess< AccessType > self_type
self type
static void * getAddress(access_type &access, const CodecIndex &index)
Get the address (with write access)
A CodecElement to get and set values.
child_elements_type & getChildElements()
Gets an reference to the child elements.
self_type getChildElement(const std::string &name) const
Get a dedicated ChildElement by name.
CodecElement()=delete
CTOR.
self_type getArrayElement(size_t array_pos=0)
Get the array element of the given array_pos.
typename child_elements_type::const_iterator const_iterator_type
CodecElement< CodecElementAccess< Codec >, ChildElements< CodecElementAccess< Codec > > > self_type
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...
void setValue(const T &value)
Sets the value from value of type T.
typename child_elements_type::iterator iterator_type
self_type getChildElement(const std::string &name)
Get a dedicated ChildElement by name.
void setRawValue(const void *value, size_t value_size)
Set the value by copying from a value buffer.
FactoryElement< CodecElementAccess< Codec >, ChildElements< CodecElementAccess< Codec > > > factory_base_type
void * getAddress()
Get the address (with writing access)
void setVariantValue(const a_util::variant::Variant &value)
Sets the value from value as variant.
DecoderElement< CodecElementAccess< Codec >, ChildElements< CodecElementAccess< Codec > > > base_type
typename factory_base_type::child_elements_type child_elements_type
void setStringValue(const std::string &value)
Sets the value from value as string.
self_type getArrayElement(size_t array_pos=0) const
Get the array element of the given array_pos.
typename CodecElementAccess< Codec >::access_type access_type
static constexpr size_t _invalid_array_pos
Invalid array pos.
static constexpr size_t _invalid_element_index
Invalid element index.
Fast Access Index Type for the coders.
const ElementLayout & getLayout() const
Get the Layout.
A element access type concept template to retrieve element information from the AccessType and get th...
static std::string getStringValue(access_type &access, const CodecIndex &index)
Get the value as type string.
static T getValue(access_type &access, const CodecIndex &index)
Get the value as type T.
static a_util::variant::Variant getVariantValue(access_type &access, const CodecIndex &index)
Get the value as variant.
AccessType access_type
access type in use
static element_type getElement(access_type &access, const std::string &full_element_name)
Get a element object for the given full_element_name.
static element_type getElement(access_type &access, const CodecIndex &index)
Get a element object for the given index.
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.
static const void * getAddress(access_type &access, const CodecIndex &index)
Get the address of the element.
DecoderElementAccess< AccessType > self_type
self type
DecoderElement< self_type, ChildElements< self_type > > element_type
supported element type
A DecoderElement to get values.
std::string getStringValue() const
Get the value as string.
FactoryElement< DecoderElementAccess< const Decoder >, ChildElements< DecoderElementAccess< const Decoder > > > base_type
self_type getChildElement(const std::string &name) const
Get the child element with the given name.
typename child_elements_type::const_iterator const_iterator_type
T getValue() const
Get the value as type T.
void getRawValue(void *value, size_t value_size) const
Get the as copy to the value buffer.
DecoderElement< DecoderElementAccess< const Decoder >, ChildElements< DecoderElementAccess< const Decoder > > > self_type
typename child_elements_type::iterator iterator_type
a_util::variant::Variant getVariantValue() const
Get the value as variant.
typename base_type::child_elements_type child_elements_type
DecoderElement()=delete
CTOR.
self_type getArrayElement(size_t array_pos=0) const
Get the array element of the given array_pos.
const void * getAddress() const
Get the address of the element.
typename DecoderElementAccess< const Decoder >::access_type access_type
The const element iterator.
int difference_type
difference value type
typename ElementAccessType::element_type element_type
The element type in use.
const_pointer operator->() const
pointer access (check for end!)
value_type & const_reference
const reference value type
bool operator!=(const ElementIteratorConst &rhs) const
checks for not equality (does not refer the same element!)
bool operator==(const ElementIteratorConst &rhs) const
checks for equality (refering the same element!)
ElementIteratorConst & operator++()
increasing operator to the next position.
std::forward_iterator_tag iterator_category
iterator type
value_type * const_pointer
pointer to const data value type
const element_type value_type
const value type of the iterator
ElementIteratorConst()=delete
default CTOR
ElementIteratorConst(value_type &&element)
CTOR for one element.
const_reference operator*() const
defering access (check for end!)
ElementIteratorConst operator++(int)
iterator increasing.
int difference_type
difference value type
typename ElementAccessType::element_type element_type
The element type in use.
const_pointer operator->() const
pointer access (check for end!)
pointer operator->()
pointer access (check for end!)
reference operator*()
defering access (check for end!)
value_type * pointer
Pointer type.
std::forward_iterator_tag iterator_category
iterator type
ElementIterator & operator++()
increasing operator to the next position.
value_type & reference
Reference value type.
const value_type * const_pointer
pointer to const data value type
bool operator==(const ElementIterator &rhs) const
checks for equality (refering the same element!)
const value_type & const_reference
const reference value type
ElementIterator operator++(int)
iterator increasing.
element_type value_type
Value type of the iterator.
bool operator!=(const ElementIterator &rhs) const
checks for not equality (does not refer the same element!)
const_reference operator*() const
defering access (check for end!)
ElementIterator()=delete
default CTOR
ElementIterator(value_type &&element)
CTOR for one element.
A factory element access type concept template to retrieve element information from the AccessType.
static size_t getChildCount(access_type &access, const CodecIndex &index)
Get the Child Count.
FactoryElementAccess< AccessType > self_type
self type
static std::string getName(access_type &access, const CodecIndex &index)
Get the name of the element within its level structure.
static std::string getFullName(access_type &access, const CodecIndex &index)
Get the full name of the element within its main structure.
static void resolve(access_type &access, CodecIndex &index)
Resolves the given CodecIndex and set the layout information.
AccessType access_type
The access type (CodecFactory, Codec, Decoder, etc.)
static element_type getElement(access_type &access, const std::string &full_element_name)
Get a element object for the given full_element_name.
static element_type getElement(access_type &access, const CodecIndex &index)
Get a element object for the given index.
FactoryElement< self_type, ChildElements< self_type > > element_type
element type
static std::string getBaseName(access_type &access, const CodecIndex &index)
Get the name of the element within its level structure.
std::string getBaseName() const
Get the base name of the element.
FactoryElement(const FactoryElement &other)
copy CTOR
FactoryElement(FactoryElement &&other)
move CTOR
std::string getFullName() const
Get the full name of the element.
const child_elements_type & getChildElements() const
Get the ChildElements.
self_type getChildElement(const std::string &name) const
Get the child element with the given name.
bool isValid() const
Get validation indormation.
FactoryElement()=delete
no CTOR
typename child_elements_type::const_iterator const_iterator_type
const CodecIndex & getIndex() const
Get the codec index of the element.
FactoryElement & operator=(const FactoryElement &other)
move assignment operator
~FactoryElement()=default
DTOR.
ChildElements< FactoryElementAccess< const CodecFactory > > child_elements_type
std::string getName() const
Get the name of the element If the element is an array you get the elements array name representation...
typename child_elements_type::iterator iterator_type
ddl::codec::ElementType getType() const
Get the type of the element.
FactoryElement< FactoryElementAccess< const CodecFactory >, ChildElements< FactoryElementAccess< const CodecFactory > > > self_type
bool hasChildren() const
Get children information.
size_t getArraySize() const
Get the array size.
self_type getArrayElement(size_t array_pos=0) const
Get the array element of the given array_pos.
bool isArray() const
Get array information.
typename FactoryElementAccess< const CodecFactory >::access_type access_type
FactoryElement & operator=(FactoryElement &&other)
copy assignment operator
Implementation of the CodecIndex.
Namespace for the new faster CodecFactory/Decoder/Codec implementation.
ElementType
The element type of the value.
@ cet_sub_codec
type marks a subcodec/substructure with children
@ cet_empty
Variant type is empty.
@ cet_user_type
type marks a user defined type
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.
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 of the ddl namespace
Common include for component a_util::variant.