ADTF  3.18.2
workspace/conan/dev_essential/1.3.3/dw/stable/package/37682420cd166e229516a41c8d6a139a0b13e1e1/include/ddl/codec/static_codec.h
Go to the documentation of this file.
1 
15 #ifndef DDL_STATIC_CODEC_CLASS_HEADER
16 #define DDL_STATIC_CODEC_CLASS_HEADER
17 
18 #include <a_util/memory.h>
19 #include <a_util/result.h>
20 #include <ddl/codec/codec_index.h>
24 #include <ddl/codec/value_access.h>
25 
26 #include <functional>
27 namespace ddl {
28 namespace codec {
29 
30 // forward declarations
31 class ElementAccessor;
32 class StructAccess;
33 class CodecFactory;
34 
39 public:
41  ~StaticDecoder() = default;
49  StaticDecoder(const StaticDecoder&) = delete;
78  Element getElement(const CodecIndex& codec_index) const;
95  Element getElement(const std::string& full_element_name) const;
108  const Elements& getElements() const;
116  size_t getElementChildCount(const CodecIndex& codec_index = CodecIndex()) const;
128  std::string getElementFullName(const CodecIndex& codec_index) const;
140  std::string getElementName(const CodecIndex& codec_index) const;
152  const std::string& getElementBaseName(const CodecIndex& codec_index) const;
160  template <typename T>
161  T getElementValue(const CodecIndex& codec_index) const
162  {
163  return ValueGetterSelect<StaticDecoder, T>::getValue(*this, codec_index);
164  }
173  template <typename T>
174  T getElementValue(const LeafCodecIndex& leaf_codec_index) const
175  {
176  return LeafValueGetter<T>::getValue(getData(), getDataSize(), leaf_codec_index.getLayout());
177  }
191  void getElementVariantValue(const CodecIndex& codec_index,
192  a_util::variant::Variant& value) const;
201  std::string getElementStringValue(const CodecIndex& codec_index) const;
210  void getElementRawValue(const CodecIndex& index, void* value, size_t value_size) const;
215  const void* getElementAddress(const CodecIndex& index) const;
221  size_t getStaticBufferSize() const;
233 
234 public: // legacy
240  CodecIndex resolve(size_t leaf_index) const;
245  size_t getElementCount() const;
254  const ddl::StructElement*& legacy_struct_element) const;
255 
261  void resolve(CodecIndex& codec_index) const;
262 
268  const void* getData() const noexcept;
274  size_t getDataSize() const noexcept;
275 
276 protected:
277  friend class CodecFactory;
278 
280  StaticDecoder(std::shared_ptr<const StructAccess> codec_access,
281  const void* data,
282  size_t data_size,
283  DataRepresentation representation);
284 
285 protected:
287  std::shared_ptr<const StructAccess> _codec_access;
289  const void* _data = nullptr;
291  size_t _data_size = 0;
293  const ddl::codec::ElementAccessor* _element_accessor;
294 
295 private:
297  ddl::access_element::StructElementLegacy<const StaticDecoder> _legacy_element;
298  Element _first_element;
299 };
300 
304 class StaticCodec final : public StaticDecoder {
305 public:
313  StaticCodec(const StaticCodec&) = delete;
314 
318  StaticCodec& operator=(const StaticCodec&) = delete;
319 
324 
329 
343  Element getElement(const CodecIndex& codec_index);
360  Element getElement(const std::string& full_element_name);
361 
375 
384  template <typename T>
385  void setElementValue(const CodecIndex& codec_index, const T& value)
386  {
387  ValueSetterSelect<StaticCodec, T>::setValue(*this, codec_index, value);
388  }
398  template <typename T>
399  void setElementValue(const LeafCodecIndex& leaf_codec_index, const T& value)
400  {
401  LeafValueSetter<T>::setValue(getData(), getDataSize(), leaf_codec_index.getLayout(), value);
402  }
412  void setElementVariantValue(const CodecIndex& codec_index,
413  const a_util::variant::Variant& value);
421  void setElementStringValue(const CodecIndex& codec_index, const std::string& value);
432  void setElementRawValue(const CodecIndex& codec_index, const void* value, size_t value_size);
438  void* getElementAddress(const CodecIndex& codec_index);
445  void resetValues(bool zero_values = false);
446 
453  void* getData() noexcept;
454 
455 private:
456  friend class CodecFactory;
458  StaticCodec(std::shared_ptr<const StructAccess> codec_access,
459  void* data,
460  size_t data_size,
461  DataRepresentation representation);
462  Element _first_element;
463 };
464 
465 } // namespace codec
466 } // namespace ddl
467 
468 #include <ddl/codec/legacy/static_codec_legacy.h>
469 
470 #endif // DDL_STATIC_CODEC_CLASS_HEADER
Implementation of legacy access_element.
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.
Fast Access Index Type for the coders.
Definition: codec_index.h:132
A DecoderElement to get values.
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.
StaticCodec(const StaticCodec &)=delete
Noncopyable.
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.
StaticCodec & operator=(const StaticCodec &)=delete
Noncopyable.
void * getElementAddress(const CodecIndex &codec_index)
void resetValues(bool zero_values=false)
Sets all elements to their default values, constant values defined in the data definition or zero if ...
StaticCodec & operator=(StaticCodec &&)
Move assignment operator.
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.
StaticCodec()
Default 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 static 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.
StaticCodec(StaticCodec &&)
Move constructor.
ChildElements< CodecElementAccess< StaticCodec > > Elements
Iterator container to iterate all elements of the static decoder.
StaticDecoder(const StaticDecoder &)=delete
Noncopyable.
size_t getElementCount() const
is the leaf count
a_util::result::Result getElement(size_t leaf_index, const ddl::StructElement *&legacy_struct_element) const
Returns the StructElement of the element with given leaf index.
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.
std::string getElementFullName(const CodecIndex &codec_index) const
Retrieves the full name of the element within its main structure.
std::string getElementStringValue(const CodecIndex &codec_index) const
Returns the current value of the given element as a string.
const std::string & getElementBaseName(const CodecIndex &codec_index) const
Retrieves the base name of the element within its structured element.
void getElementVariantValue(const CodecIndex &codec_index, a_util::variant::Variant &value) const
Returns the current value of the given element as a variant.
StaticDecoder(StaticDecoder &&)
Move constructor.
virtual a_util::result::Result isValid() const
CodecIndex resolve(size_t leaf_index) const
size_t getStaticBufferSize(DataRepresentation rep) const
Gets the static buffer size in bytes for the main structure.
~StaticDecoder()=default
DTOR.
StaticDecoder & operator=(const StaticDecoder &)=delete
Noncopyable.
std::string getElementName(const CodecIndex &codec_index) const
Retrieves the name of the element within its structured element.
size_t getDataSize() const noexcept
Get the current size (in bytes) of the data.
size_t getStaticBufferSize() const
Gets the static buffer size in bytes for the main structure.
const void * getData() const noexcept
Get the current set data.
a_util::variant::Variant getElementVariantValue(const CodecIndex &codec_index) const
Returns the current value of the given element as a variant.
StaticDecoder()
Default constructor.
T getElementValue(const CodecIndex &codec_index) const
Returns the current value of the given element as a T if supported.
void getElementRawValue(const CodecIndex &index, void *value, size_t value_size) const
Returns the current value of the given element as a variant.
ChildElements< DecoderElementAccess< const StaticDecoder > > Elements
Iterator container to iterate all elements of the static decoder.
DataRepresentation getRepresentation() const
Returns the current data representation the decoder decodes from.
const void * getElementAddress(const CodecIndex &index) const
StaticDecoder & operator=(StaticDecoder &&)
Move assignment operator.
size_t getElementChildCount(const CodecIndex &codec_index=CodecIndex()) const
Retrieves the amount of child elements for the given codec index.
const Elements & getElements() const
Retrieves the elements of the static decoder to get element information.
T getElementValue(const LeafCodecIndex &leaf_codec_index) const
Returns the current value of the given element as a T if supported.
void resolve(CodecIndex &codec_index) const
The codec index will be resolved for fast access (layout will be set)
Implementation of the CodecIndex.
Implementation of the CodecIterator.
Definition of Data Representation header for Codec API.
Common include for component a_util::memory.
static ValueType getValue(const void *data, const size_t data_size, const LeafLayout &leaf_layout)
Returns the current value of the given element as a ValueType if supported.
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 ValueType getValue(const DecoderType &decoder, const CodecIndex &codec_index)
Returns the current value of the given element as a ValueType if supported.
Definition: value_access.h:168
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
Implementation of the decoder and coder value accesss setter and getter.
Common include for component a_util::result.