Dev Essential  1.6.3
Loading...
Searching...
No Matches
codec_index.h
Go to the documentation of this file.
1
14
15#ifndef DDL_CODEC_INDEX_CLASS_HEADER
16#define DDL_CODEC_INDEX_CLASS_HEADER
17
20
21#include <string>
22#include <vector>
23
24namespace ddl {
28struct Position {
32 size_t bit_offset = {};
36 size_t bit_size = {};
37
45 constexpr bool operator==(const Position& other) const noexcept
46 {
47 return bit_offset == other.bit_offset && bit_size == other.bit_size;
48 }
49
56 constexpr bool operator!=(const Position& other) const noexcept
57 {
58 return !operator==(other);
59 }
60};
61
64namespace codec {
65
70
78 size_t type_bit_size = {};
79
87 constexpr bool operator==(const PositionWithTypeSize& other) const noexcept
88 {
89 return Position::operator==(other) && type_bit_size == other.type_bit_size;
90 }
91
98 constexpr bool operator!=(const PositionWithTypeSize& other) const noexcept
99 {
100 return !operator==(other);
101 }
102};
103
111
119 constexpr bool operator==(const PositionWithAlignedTypeSize& other) const noexcept
120 {
121 return PositionWithTypeSize::operator==(other) &&
122 type_bit_size_aligned == other.type_bit_size_aligned;
123 }
124
131 constexpr bool operator!=(const PositionWithAlignedTypeSize& other) const noexcept
132 {
133 return !operator==(other);
134 }
135};
136
145
153 constexpr bool operator==(const PositionWithUsedBitsTypeSize& other) const noexcept
154 {
155 return PositionWithTypeSize::operator==(other) &&
156 type_bit_size_used == other.type_bit_size_used;
157 }
158
165 constexpr bool operator!=(const PositionWithUsedBitsTypeSize& other) const noexcept
166 {
167 return !operator==(other);
168 }
169};
170
190 size_t array_size = {};
207
215 constexpr bool operator==(const ElementLayoutBase& other) const noexcept
216 {
217 return deserialized == other.deserialized && serialized == other.serialized &&
218 byte_order == other.byte_order && array_size == other.array_size &&
219 child_element_count == other.child_element_count && type_info == other.type_info &&
220 constant_info == other.constant_info &&
221 default_value_info == other.default_value_info;
222 }
223
230 constexpr bool operator!=(const ElementLayoutBase& other) const noexcept
231 {
232 return !operator==(other);
233 }
234};
235
243 size_t array_pos = {};
244
252 constexpr bool operator==(const ElementLayout& other) const noexcept
253 {
254 return ElementLayoutBase::operator==(other) && array_pos == other.array_pos;
255 }
256
263 constexpr bool operator!=(const ElementLayout& other) const noexcept
264 {
265 return !operator==(other);
266 }
267};
268
277public:
283 public:
287 ElementIndex() = default;
293 ElementIndex(size_t element_index);
300 ElementIndex(size_t element_index, size_t array_pos);
301
309 bool operator==(const ElementIndex& other) const;
317 bool operator!=(const ElementIndex& other) const;
318
324 size_t getIndex() const;
330 size_t getArrayPos() const;
331
338
342 static constexpr size_t _invalid_element_index = static_cast<size_t>(-1);
346 static constexpr size_t _invalid_array_pos = static_cast<size_t>(-1);
347
348 private:
349 size_t _element_index = _invalid_element_index;
350 size_t _array_pos = _invalid_array_pos;
351 };
352
355 CodecIndex() = default;
362 const ElementIndex& operator[](size_t pos) const;
370 bool operator==(const CodecIndex& other) const;
378 bool operator!=(const CodecIndex& other) const;
384 size_t getSize() const;
390 size_t size() const;
397 bool hasLayout() const;
408 const ElementLayout& getLayout() const;
409
410private:
411 friend class StructAccess;
412 friend class ChildElementAccess;
413 template <typename ElementAccessType, typename ChildElementsType>
414 friend class FactoryElement;
415 template <typename ElementAccessType, typename ChildElementsType>
416 friend class DecoderElement;
417 template <typename ElementAccessType, typename ChildElementsType>
418 friend class CodecElement;
419 template <typename ElementAccessType>
420 friend class ChildElements;
421
422 CodecIndex(const CodecIndex& codec_index, ElementIndex index);
423 CodecIndex(const CodecIndex& codec_index, size_t reserved_count);
425 CodecIndex(const CodecIndex& codec_index, size_t count, ElementIndex index);
426 CodecIndex(const std::vector<ElementIndex>& indexes);
427 CodecIndex(ElementIndex index, const ElementLayout& layout);
428 CodecIndex(const CodecIndex& codec_index,
429 size_t count,
430 ElementIndex index,
431 const ElementLayout& layout);
432
433 CodecIndex& operator++();
434 CodecIndex operator++(int);
435
436 void setLayout(const ElementLayout& layout);
437 void reserve(size_t size);
438 void addElementIndex(ElementIndex index);
439 CodecIndex::ElementIndex back() const noexcept;
440 CodecIndex getIndexForArrayPos(size_t array_pos) const;
441
442private:
443 std::vector<ElementIndex> _indices = {};
444 ElementLayout _layout = {};
445 bool _layout_valid = {};
446};
447
454std::string toString(const CodecIndex& index);
455
456} // namespace codec
457} // namespace ddl
458
459#endif // DDL_CODEC_INDEX_CLASS_HEADER
The constant info of a element.
Definition codec_type_info.h:138
The default value info of a element.
Definition codec_type_info.h:173
The element index at the CodecIndex.
Definition codec_index.h:282
ElementIndex(size_t element_index)
CTOR.
bool operator!=(const ElementIndex &other) const
Not equal operator.
size_t getIndex() const
Get the Index.
ElementIndex(size_t element_index, size_t array_pos)
CTOR.
static constexpr size_t _invalid_element_index
Invalid element index.
Definition codec_index.h:342
size_t getArrayPos() const
Get the Array Pos.
ElementIndex & operator++()
Incrememts the index, keeps array pos.
static constexpr size_t _invalid_array_pos
Invalid array pos.
Definition codec_index.h:346
bool operator==(const ElementIndex &other) const
equal operator.
Definition codec_index.h:276
bool operator==(const CodecIndex &other) const
Equal operator.
ElementType getType() const
Get the elements type if CodecIndex is valid.
const ElementIndex & operator[](size_t pos) const
Access operator to retrieve a elment index on the given pos.
bool hasLayout() const
Has layout set.
bool operator!=(const CodecIndex &other) const
Not equal operator.
CodecIndex()=default
Construct a new Codec Index.
size_t getSize() const
Get the Size of the codec index in element index count.
const ElementLayout & getLayout() const
Get the Layout.
size_t size() const
Gets the Size of the codec index in element index count for generic programming.
Description of the elements Type.
Definition codec_type_info.h:61
ddl::Position Position
Definition codec_index.h:69
ElementType
The element type of the value.
Definition codec_type_info.h:30
std::string toString(const CodecIndex &index)
Converts the index to a string.
ByteOrder
Definition dd_common_types.h:152
definition of the ddl namespace
Definition codec.h:21
Definition codec_index.h:28
constexpr bool operator==(const Position &other) const noexcept
Equality operator.
Definition codec_index.h:45
constexpr bool operator!=(const Position &other) const noexcept
Non-Equality operator.
Definition codec_index.h:56
size_t bit_size
the elements bitsize (the whole element)
Definition codec_index.h:36
size_t bit_offset
the bit offset
Definition codec_index.h:32
Definition codec_index.h:174
constexpr bool operator==(const ElementLayoutBase &other) const noexcept
Equality operator.
Definition codec_index.h:215
PositionWithAlignedTypeSize deserialized
deserialized position.
Definition codec_index.h:178
PositionWithUsedBitsTypeSize serialized
serialized position.
Definition codec_index.h:182
const CodecConstantInfo * constant_info
Pointer to the constant_info if the value is a constant.
Definition codec_index.h:202
const CodecDefaultValueInfo * default_value_info
Pointer to the default_value_info if the value has a default value set.
Definition codec_index.h:206
size_t child_element_count
The child element count.
Definition codec_index.h:194
size_t array_size
Array size of the element value.
Definition codec_index.h:190
constexpr bool operator!=(const ElementLayoutBase &other) const noexcept
Non-Equality operator.
Definition codec_index.h:230
const CodecTypeInfo * type_info
Pointer to the type_info.
Definition codec_index.h:198
ddl::dd::ByteOrder byte_order
Byte order of the element value.
Definition codec_index.h:186
Definition codec_index.h:239
constexpr bool operator==(const ElementLayout &other) const noexcept
Equality operator.
Definition codec_index.h:252
size_t array_pos
The array position of the element.
Definition codec_index.h:243
constexpr bool operator!=(const ElementLayout &other) const noexcept
Non-Equality operator.
Definition codec_index.h:263
Definition codec_index.h:106
constexpr bool operator!=(const PositionWithAlignedTypeSize &other) const noexcept
Non-Equality operator.
Definition codec_index.h:131
constexpr bool operator==(const PositionWithAlignedTypeSize &other) const noexcept
Equality operator.
Definition codec_index.h:119
size_t type_bit_size_aligned
aligned type size in bits
Definition codec_index.h:110
Definition codec_index.h:74
constexpr bool operator==(const PositionWithTypeSize &other) const noexcept
Equality operator.
Definition codec_index.h:87
size_t type_bit_size
type size in bits (in case of array, this is the size of one element within the array)
Definition codec_index.h:78
constexpr bool operator!=(const PositionWithTypeSize &other) const noexcept
Non-Equality operator.
Definition codec_index.h:98
Definition codec_index.h:140
constexpr bool operator!=(const PositionWithUsedBitsTypeSize &other) const noexcept
Non-Equality operator.
Definition codec_index.h:165
size_t type_bit_size_used
type size in bits which is used (may be a bitfield)
Definition codec_index.h:144
constexpr bool operator==(const PositionWithUsedBitsTypeSize &other) const noexcept
Equality operator.
Definition codec_index.h:153