ADTF  3.18.2
codec_index.h
Go to the documentation of this file.
1 
15 #ifndef DDL_CODEC_INDEX_CLASS_HEADER
16 #define DDL_CODEC_INDEX_CLASS_HEADER
17 
19 #include <ddl/dd/dd_common_types.h>
20 
21 #include <string>
22 #include <vector>
23 
24 namespace ddl {
28 struct Position {
32  size_t bit_offset = {};
36  size_t bit_size = {};
37 };
41 namespace codec {
42 
47 
51 struct PositionWithTypeSize : public Position {
55  size_t type_bit_size = {};
56 };
64  size_t type_bit_size_aligned = {};
65 };
66 
74  size_t type_bit_size_used = {};
75 };
76 
96  size_t array_size = {};
100  size_t child_element_count = {};
113 };
114 
122  size_t array_pos = {};
123 };
124 
132 class CodecIndex {
133 public:
138  class ElementIndex {
139  public:
143  ElementIndex() = default;
149  ElementIndex(size_t element_index);
156  ElementIndex(size_t element_index, size_t array_pos);
157 
165  bool operator==(const ElementIndex& other) const;
173  bool operator!=(const ElementIndex& other) const;
174 
180  size_t getIndex() const;
186  size_t getArrayPos() const;
187 
194 
198  static constexpr size_t _invalid_element_index = static_cast<size_t>(-1);
202  static constexpr size_t _invalid_array_pos = static_cast<size_t>(-1);
203 
204  private:
205  size_t _element_index = _invalid_element_index;
206  size_t _array_pos = _invalid_array_pos;
207  };
211  CodecIndex() = default;
218  const ElementIndex& operator[](size_t pos) const;
226  bool operator==(const CodecIndex& other) const;
234  bool operator!=(const CodecIndex& other) const;
240  size_t getSize() const;
246  size_t size() const;
253  bool hasLayout() const;
264  const ElementLayout& getLayout() const;
265 
266 private:
267  friend class StructAccess;
268  friend class ChildElementAccess;
269  template <typename ElementAccessType, typename ChildElementsType>
270  friend class FactoryElement;
271  template <typename ElementAccessType, typename ChildElementsType>
272  friend class DecoderElement;
273  template <typename ElementAccessType, typename ChildElementsType>
274  friend class CodecElement;
275  template <typename ElementAccessType>
276  friend class ChildElements;
277 
278  CodecIndex(const CodecIndex& codec_index, ElementIndex index);
279  CodecIndex(ElementIndex index);
280  CodecIndex(const CodecIndex& codec_index, size_t count, ElementIndex index);
281  CodecIndex(const std::vector<ElementIndex>& indexes);
282  CodecIndex(ElementIndex index, const ElementLayout& layout);
283  CodecIndex(const CodecIndex& codec_index,
284  size_t count,
285  ElementIndex index,
286  const ElementLayout& layout);
287 
288  CodecIndex& operator++();
289  CodecIndex operator++(int);
290 
291  void setLayout(const ElementLayout& layout);
292  void addElementIndex(ElementIndex index);
293  CodecIndex::ElementIndex back() const noexcept;
294  CodecIndex getIndexForArrayPos(size_t array_pos) const;
295 
296 private:
297  std::vector<ElementIndex> _indices = {};
298  ElementLayout _layout = {};
299  bool _layout_valid = {};
300 };
301 
308 std::string toString(const CodecIndex& index);
309 
310 } // namespace codec
311 } // namespace ddl
312 
313 #endif // DDL_CODEC_INDEX_CLASS_HEADER
Iteratable container type for the given Element type in ElementAccessType::element_type.
The constant info of a element.
The default value info of a element.
A CodecElement to get and set values.
The element index at the CodecIndex.
Definition: codec_index.h:138
ElementIndex(size_t element_index, size_t array_pos)
CTOR.
bool operator!=(const ElementIndex &other) const
Not equal operator.
size_t getArrayPos() const
Get the Array Pos.
static constexpr size_t _invalid_array_pos
Invalid array pos.
Definition: codec_index.h:202
bool operator==(const ElementIndex &other) const
equal operator.
static constexpr size_t _invalid_element_index
Invalid element index.
Definition: codec_index.h:198
ElementIndex & operator++()
Incrememts the index, keeps array pos.
size_t getIndex() const
Get the Index.
ElementIndex(size_t element_index)
CTOR.
Fast Access Index Type for the coders.
Definition: codec_index.h:132
bool operator!=(const CodecIndex &other) const
Not equal operator.
const ElementIndex & operator[](size_t pos) const
Access operator to retrieve a elment index on the given pos.
ElementType getType() const
Get the elements type if CodecIndex is valid.
size_t size() const
Gets the Size of the codec index in element index count for generic programming.
bool operator==(const CodecIndex &other) const
Equal operator.
bool hasLayout() const
Has layout set.
size_t getSize() const
Get the Size of the codec index in element index count.
const ElementLayout & getLayout() const
Get the Layout.
CodecIndex()=default
Construct a new Codec Index.
Description of the elements Type.
A DecoderElement to get values.
Implementation of the CodecTypeInfoo and CodecConstantInfo.
OO DataDefinition Common Design.
ElementType
The element type of the value.
ddl::Position Position
Binary compatible reusing of structure for position of elements.
Definition: codec_index.h:46
std::string toString(const CodecIndex &index)
Converts the index to a string.
ByteOrder
Representation of the byteorder enumeration.
Structure for bit position of elements.
Definition: codec_index.h:28
size_t bit_offset
the bit offset
Definition: codec_index.h:32
size_t bit_size
the elements bitsize (the whole element)
Definition: codec_index.h:36
Base layout definition for one element.
Definition: codec_index.h:80
const CodecDefaultValueInfo * default_value_info
Pointer to the default_value_info if the value has a default value set.
Definition: codec_index.h:112
ddl::dd::ByteOrder byte_order
Byte order of the element value.
Definition: codec_index.h:92
size_t child_element_count
The child element count.
Definition: codec_index.h:100
const CodecConstantInfo * constant_info
Pointer to the constant_info if the value is a constant.
Definition: codec_index.h:108
const CodecTypeInfo * type_info
Pointer to the type_info.
Definition: codec_index.h:104
PositionWithUsedBitsTypeSize serialized
serialized position.
Definition: codec_index.h:88
PositionWithAlignedTypeSize deserialized
deserialized position.
Definition: codec_index.h:84
size_t array_size
Array size of the element value.
Definition: codec_index.h:96
Layout defintion for one element with set array position.
Definition: codec_index.h:118
size_t array_pos
The array position of the element.
Definition: codec_index.h:122
Position with type size information.
Definition: codec_index.h:60
size_t type_bit_size_aligned
aligned type size in bits
Definition: codec_index.h:64
Position with type size information.
Definition: codec_index.h:51
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:55
Position with used bit type size information.
Definition: codec_index.h:70
size_t type_bit_size_used
type size in bits which is used (may be a bitfield)
Definition: codec_index.h:74