ADTF  3.18.2
workspace/conan/dev_essential/1.3.3/dw/stable/package/37682420cd166e229516a41c8d6a139a0b13e1e1/include/ddl/codec/codec.h
Go to the documentation of this file.
1 
15 #ifndef DDL_CODEC_CLASS_HEADER
16 #define DDL_CODEC_CLASS_HEADER
17 
18 #include <a_util/result.h>
19 #include <ddl/codec/static_codec.h>
20 
21 namespace ddl {
22 namespace codec {
23 
24 class Codec;
25 class StructAccess;
26 
30 class Decoder : public StaticDecoder {
31 public:
36 
41 
46 
50  Decoder(const Decoder&) = delete;
51 
55  Decoder& operator=(const Decoder&) = delete;
56 
60  a_util::result::Result isValid() const override;
72  Element getElement(const CodecIndex& codec_index) const;
89  Element getElement(const std::string& full_element_name) const;
101  const Elements& getElements() const;
107  size_t getBufferSize() const;
114  size_t getBufferSize(DataRepresentation representation) const;
122  Codec makeCodecFor(void* data, size_t data_size, DataRepresentation representation) const;
123 
124 protected:
125  friend class CodecFactory;
127  Decoder(std::shared_ptr<const StructAccess> codec_access,
128  const void* data,
129  size_t data_size,
130  DataRepresentation representation);
132  Decoder(const Decoder& decoder,
133  const void* data,
134  size_t data_size,
135  DataRepresentation representation);
137  friend class FactoryElementAccess<const Decoder>;
138 
139 private:
140  Element _first_element;
141 };
142 
148 class Codec : public Decoder {
149 public:
153  Codec();
165  Codec(const Codec&) = delete;
169  Codec& operator=(const Codec&) = delete;
170 
171  using Decoder::getElement;
173  using Decoder::getElements;
185  Element getElement(const CodecIndex& codec_index);
202  Element getElement(const std::string& full_element_name);
223  template <typename T>
224  void setElementValue(const CodecIndex& codec_index, const T& value)
225  {
226  ValueSetterSelect<Codec, T>::setValue(*this, codec_index, value);
227  }
237  template <typename T>
238  void setElementValue(const LeafCodecIndex& leaf_codec_index, const T& value)
239  {
240  LeafValueSetter<T>::setValue(getData(), getDataSize(), leaf_codec_index.getLayout(), value);
241  }
251  void setElementVariantValue(const CodecIndex& codec_index,
252  const a_util::variant::Variant& value);
260  void setElementStringValue(const CodecIndex& codec_index, const std::string& value);
270  void setElementRawValue(const CodecIndex& codec_index, const void* value, size_t value_size);
275  void* getElementAddress(const CodecIndex& codec_index);
282  void resetValues(bool zero_values = false);
283 
284  using Decoder::getData;
290  void* getData() noexcept;
291 
292 protected:
293  friend class CodecFactory;
294  friend class Decoder;
296  Codec(std::shared_ptr<const StructAccess> codec_access,
297  void* data,
298  size_t data_size,
299  ddl::DataRepresentation rep);
301  Codec(const Decoder& decoder,
302  void* data,
303  size_t data_size,
304  ddl::DataRepresentation representation);
305 
306 private:
307  Element _first_element;
308 };
309 
310 } // namespace codec
311 } // namespace ddl
312 
313 #include <ddl/codec/legacy/codec_legacy.h>
314 
315 #endif // DDL_CODEC_CLASS_HEADER
A common result class usable as return value throughout.
Iteratable container type for the given Element type in ElementAccessType::element_type.
A CodecElement to get and set values.
void setElementValue(const LeafCodecIndex &leaf_codec_index, const T &value)
Sets the current value of the given element from given value in type T.
Element getElement(const CodecIndex &codec_index)
Retrieves an element instance based on the codec index of that element.
void setElementVariantValue(const CodecIndex &codec_index, const a_util::variant::Variant &value)
Sets the current value of the given element from the given variant.
Codec()
Default constructor.
ChildElements< CodecElementAccess< Codec > > Elements
Iterator container to iterate all elements of the codec.
void * getElementAddress(const CodecIndex &codec_index)
Codec & operator=(Codec &&)
Move assignment operator.
Codec(Codec &&)
Move constructor.
void resetValues(bool zero_values=false)
Sets all elements to their default values, constant values defined in the data definition or zero if ...
void setElementValue(const CodecIndex &codec_index, const T &value)
Sets the current value of the given element from given value in type T.
Element getElement(const std::string &full_element_name)
Retrieves an element instance based on the full name of the element.
Codec(const Codec &)=delete
No copy constructor.
void setElementRawValue(const CodecIndex &codec_index, const void *value, size_t value_size)
Sets the current value of the given element by copying its data from the passed-in location.
void * getData() noexcept
Get the current set data.
Elements & getElements()
Retrieves the elements of the codec to get element information.
void setElementStringValue(const CodecIndex &codec_index, const std::string &value)
Sets the current value of the given element from the given string.
Codec & operator=(const Codec &)=delete
No copy assignment operator.
Fast Access Index Type for the coders.
Definition: codec_index.h:132
A DecoderElement to get values.
Decoder(const Decoder &decoder, const void *data, size_t data_size, DataRepresentation representation)
For internal use only.
Element getElement(const CodecIndex &codec_index) const
Retrieves an element instance based on the codec index of that element.
Element getElement(const std::string &full_element_name) const
Retrieves an element instance based on the full name of the element.
Decoder(Decoder &&)
Move constructor.
Codec makeCodecFor(void *data, size_t data_size, DataRepresentation representation) const
Create a new codec with the current dynamic structure layout for a new data buffer.
Decoder(const Decoder &)=delete
No copy constructor.
Decoder & operator=(const Decoder &)=delete
No copy assignment operator.
a_util::result::Result isValid() const override
Decoder(std::shared_ptr< const StructAccess > codec_access, const void *data, size_t data_size, DataRepresentation representation)
For internal use only.
size_t getBufferSize() const
Gets the buffer size in bytes for the main structure.
Decoder & operator=(Decoder &&)
Move assignment operator.
ChildElements< DecoderElementAccess< const Decoder > > Elements
Iterator container to iterate all elements of the decoder and get values.
const Elements & getElements() const
Retrieves the elements of the decoder to get element information and get values.
size_t getBufferSize(DataRepresentation representation) const
Gets the buffer size in bytes for the main structure.
Decoder()
Default constructor.
A factory element access type concept template to retrieve element information from the AccessType.
The Leaf codec index is a small layout information index to access the decoders/codecs data very fast...
const LeafLayout & getLayout() const noexcept
Get the leaf layout.
size_t getDataSize() const noexcept
Get the current size (in bytes) of the data.
const void * getData() const noexcept
Get the current set data.
const void * getElementAddress(const CodecIndex &index) const
static void setValue(void *data, const size_t data_size, const LeafLayout &leaf_layout, const ValueType &value)
Sets the current value if the given element as a ValueType if supported.
static void setValue(CodecType &codec, const CodecIndex &codec_index, const ValueType &value)
Sets the current value of the given element as a ValueType if supported.
Definition: value_access.h:227
Common include for component a_util::result.