ADTF
workspace/conan/dev_essential/1.4.3/dw/stable/package/aef85909f792a5a628750d25016a24323084963f/include/ddl/codec/codec_factory.h
Go to the documentation of this file.
1 
15 #ifndef DDL_CODEC_FACTORY_CLASS_HEADER
16 #define DDL_CODEC_FACTORY_CLASS_HEADER
17 
18 #include <ddl/codec/codec.h>
21 #include <ddl/codec/static_codec.h>
22 #include <ddl/dd/dd.h>
23 #include <ddl/dd/ddstructure.h>
25 
26 namespace ddl {
27 namespace codec {
31 class CodecFactory {
32 public:
47 
57 
59  ~CodecFactory() = default;
60 
66  CodecFactory(const std::string& struct_name, const std::string& dd_string);
67 
74 
79  CodecFactory(const DDStructure& dd_struct);
80 
85  CodecFactory(const ddl::dd::StructTypeAccess& struct_type_access);
86 
92 
100  inline StaticDecoder makeStaticDecoderFor(const void* data,
101  size_t data_size,
102  DataRepresentation rep = deserialized) const
103  {
104  return StaticDecoder(_codec_access, data, data_size, rep);
105  }
106 
114  inline StaticCodec makeStaticCodecFor(void* data,
115  size_t data_size,
116  DataRepresentation rep = deserialized) const
117  {
118  return StaticCodec(_codec_access, data, data_size, rep);
119  }
120 
128  Decoder makeDecoderFor(const void* data,
129  size_t data_size,
130  DataRepresentation rep = deserialized) const;
131 
139  Codec makeCodecFor(void* data, size_t data_size, DataRepresentation rep = deserialized) const;
151  Element getElement(const CodecIndex& codec_index) const;
168  Element getElement(const std::string& full_element_name) const;
181  const Elements& getElements() const;
189  size_t getElementChildCount(const CodecIndex& codec_index = CodecIndex()) const;
201  std::string getElementFullName(const CodecIndex& codec_index) const;
213  std::string getElementName(const CodecIndex& codec_index) const;
225  const std::string& getElementBaseName(const CodecIndex& codec_index) const;
233  size_t getStaticBufferSize(DataRepresentation rep = deserialized) const;
234 
240  void resolve(CodecIndex& codec_index) const;
241 
242 public: // legacy functions
250  CodecIndex resolve(size_t leaf_index) const;
251 
260  CodecIndex resolve(size_t leaf_index, std::string& full_element_name) const;
267  size_t getStaticElementCount() const;
276  const ddl::StructElement*& legacy_struct_element) const;
277 
278 private:
280  std::shared_ptr<const StructAccess> _codec_access;
287 };
288 
289 namespace detail {
297 template <typename T>
298 size_t getDecoderOrFactoryElementCount(const T& decoder_or_factory)
299 {
300  return decoder_or_factory.getStaticElementCount();
301 }
308 template <>
309 inline size_t getDecoderOrFactoryElementCount(const ddl::codec::StaticDecoder& static_decoder)
310 {
311  return static_decoder.getElementCount();
312 }
313 
320 template <>
322 {
323  return static_codec.getElementCount();
324 }
331 template <>
333 {
334  return decoder.getElementCount();
335 }
342 template <>
344 {
345  return codec.getElementCount();
346 }
347 } // namespace detail
348 
355 template <typename T>
356 std::vector<CodecIndex> getCodecIndices(const T& decoder_or_factory)
357 {
358  std::vector<CodecIndex> indices;
359  indices.reserve(detail::getDecoderOrFactoryElementCount<T>(decoder_or_factory));
360  forEachLeafElement(decoder_or_factory.getElements(),
361  [&indices](const auto& element) { indices.push_back(element.getIndex()); });
362  return indices;
363 }
373 template <typename T>
374 std::vector<LeafCodecIndex> getLeafCodecIndices(const T& decoder_or_factory,
376 {
377  std::vector<LeafCodecIndex> indices;
378  indices.reserve(detail::getDecoderOrFactoryElementCount<T>(decoder_or_factory));
379  forEachLeafElement(decoder_or_factory.getElements(), [&indices, &rep](const auto& element) {
380  indices.push_back(LeafCodecIndex(element.getIndex(), rep));
381  });
382  return indices;
383 }
384 
385 } // namespace codec
386 } // namespace ddl
387 
389 
390 #endif // DDL_CODEC_FACTORY_CLASS_HEADER
Implementation of legacy access_element.
A common result class usable as return value throughout.
Utility class for a complete valid data definition of one StructType and its dependencies.
Definition: ddstructure.h:57
Legacy helper for the ddl::StructElement.
Iteratable container type for the given Element type in ElementAccessType::element_type.
Codec makeCodecFor(void *data, size_t data_size, DataRepresentation rep=deserialized) const
Creates a codec for the given data.
a_util::result::Result isValid() const
Check if the factory is in a valid state.
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.
CodecFactory & operator=(CodecFactory &&)
move assignment operator
CodecFactory(const std::string &struct_name, const std::string &dd_string)
Constructor that take a DataDefinition string for initialization.
CodecFactory(const DDStructure &dd_struct)
Constructor that uses an OO-DataDefinition struct for initialization.
StaticCodec makeStaticCodecFor(void *data, size_t data_size, DataRepresentation rep=deserialized) const
Creates a static codec for the given data.
const std::string & getElementBaseName(const CodecIndex &codec_index) const
Retrieves the base name of the element within its structured element.
CodecIndex resolve(size_t leaf_index) const
Legacy: Resolves given the leaf index to a codec index.
StaticDecoder makeStaticDecoderFor(const void *data, size_t data_size, DataRepresentation rep=deserialized) const
Creates a static decoder for the given data.
std::string getElementName(const CodecIndex &codec_index) const
Retrieves the name of the element within its structured element.
CodecFactory & operator=(const CodecFactory &)
copy assignment operator
CodecFactory(const ddl::dd::StructTypeAccess &struct_type_access)
Constructor that uses an StructTypeAccess for initialization.
FactoryElement< FactoryElementAccess< const CodecFactory > > Element
Type of a single factory element.
Decoder makeDecoderFor(const void *data, size_t data_size, DataRepresentation rep=deserialized) const
Creates a decoder for the given data.
ChildElements< FactoryElementAccess< const CodecFactory > > Elements
Iterator container to iterate all elements of the factory.
CodecFactory(const ddl::dd::StructType &struct_type, const dd::DataDefinition &dd)
Constructor that uses an OO-DataDefinition struct for initialization.
CodecFactory(const CodecFactory &)
copy CTOR
CodecFactory()
Empty constructor.
a_util::result::Result getStaticElement(size_t leaf_index, const ddl::StructElement *&legacy_struct_element) const
Legacy: Returns the StructElement of the element with given leaf index.
size_t getElementChildCount(const CodecIndex &codec_index=CodecIndex()) const
Retrieves the amount of child elements for the given codec index.
~CodecFactory()=default
Default dtor.
const Elements & getElements() const
Retrieves the elements of the factory to get element information.
CodecIndex resolve(size_t leaf_index, std::string &full_element_name) const
Legacy: Resolves the given leaf index to a codec index and the full element name.
CodecFactory(CodecFactory &&)
move CTOR
void resolve(CodecIndex &codec_index) const
The codec index will be resolved for fast access.
size_t getStaticElementCount() const
Legacy: Returns the amount of static (leaf) elements.
size_t getStaticBufferSize(DataRepresentation rep=deserialized) const
Gets the static buffer size in bytes for the structure.
Fast Access Index Type for the coders.
Definition: codec_index.h:132
size_t getElementCount() const
is the leaf count
The Data Definiton class uses the validation model to keep a Data Definition datamodel (ddl::dd::data...
Definition: dd.h:92
Accessing class for a instance of a struct.
observable DataDefinition object class to describe StructType.
Definition of old CodecFactory legacy header for old Codec API.
Implementation of the CodecIterator.
OO DataDefinition - Data Definition.
OO DataDefinition DDStructure Header.
OO DataDefinition DDStructureGenerator Header.
std::vector< LeafCodecIndex > getLeafCodecIndices(const T &decoder_or_factory, ddl::DataRepresentation rep)
Get the leaf indices object.
std::vector< CodecIndex > getCodecIndices(const T &decoder_or_factory)
Retrieves all codec indices for the given codec of type T.
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.
@ struct_type
the type is a struct type (StructType)
size_t getDecoderOrFactoryElementCount(const T &decoder_or_factory)
Get the Decoder or Factory leaf element count.