ADTF  3.18.2
workspace/conan/dev_essential/1.3.3/dw/stable/package/37682420cd166e229516a41c8d6a139a0b13e1e1/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>
24 
25 namespace ddl {
26 namespace codec {
30 class CodecFactory {
31 public:
46 
56 
58  ~CodecFactory() = default;
59 
65  CodecFactory(const std::string& struct_name, const std::string& dd_string);
66 
73 
78  CodecFactory(const DDStructure& dd_struct);
79 
84  CodecFactory(const ddl::dd::StructTypeAccess& struct_type_access);
85 
91 
99  inline StaticDecoder makeStaticDecoderFor(const void* data,
100  size_t data_size,
101  DataRepresentation rep = deserialized) const
102  {
103  return StaticDecoder(_codec_access, data, data_size, rep);
104  }
105 
113  inline StaticCodec makeStaticCodecFor(void* data,
114  size_t data_size,
115  DataRepresentation rep = deserialized) const
116  {
117  return StaticCodec(_codec_access, data, data_size, rep);
118  }
119 
127  Decoder makeDecoderFor(const void* data,
128  size_t data_size,
129  DataRepresentation rep = deserialized) const;
130 
138  Codec makeCodecFor(void* data, size_t data_size, DataRepresentation rep = deserialized) const;
150  Element getElement(const CodecIndex& codec_index) const;
167  Element getElement(const std::string& full_element_name) const;
180  const Elements& getElements() const;
188  size_t getElementChildCount(const CodecIndex& codec_index = CodecIndex()) const;
200  std::string getElementFullName(const CodecIndex& codec_index) const;
212  std::string getElementName(const CodecIndex& codec_index) const;
224  const std::string& getElementBaseName(const CodecIndex& codec_index) const;
232  size_t getStaticBufferSize(DataRepresentation rep = deserialized) const;
233 
239  void resolve(CodecIndex& codec_index) const;
240 
241 public: // legacy functions
249  CodecIndex resolve(size_t leaf_index) const;
256  size_t getStaticElementCount() const;
265  const ddl::StructElement*& legacy_struct_element) const;
266 
267 private:
269  std::shared_ptr<const StructAccess> _codec_access;
276 };
277 
278 namespace detail {
286 template <typename T>
287 size_t getDecoderOrFactoryElementCount(const T& decoder_or_factory)
288 {
289  return decoder_or_factory.getStaticElementCount();
290 }
297 template <>
299 {
300  return decoder.getElementCount();
301 }
308 template <>
310 {
311  return codec.getElementCount();
312 }
313 } // namespace detail
314 
321 template <typename T>
322 std::vector<CodecIndex> getCodecIndices(const T& decoder_or_factory)
323 {
324  std::vector<CodecIndex> indices;
325  indices.reserve(detail::getDecoderOrFactoryElementCount<T>(decoder_or_factory));
326  forEachLeafElement(decoder_or_factory.getElements(),
327  [&indices](const auto& element) { indices.push_back(element.getIndex()); });
328  return indices;
329 }
339 template <typename T>
340 std::vector<LeafCodecIndex> getLeafCodecIndices(const T& decoder_or_factory,
342 {
343  std::vector<LeafCodecIndex> indices;
344  indices.reserve(detail::getDecoderOrFactoryElementCount<T>(decoder_or_factory));
345  forEachLeafElement(decoder_or_factory.getElements(), [&indices, &rep](const auto& element) {
346  indices.push_back(LeafCodecIndex(element.getIndex(), rep));
347  });
348  return indices;
349 }
350 
351 } // namespace codec
352 } // namespace ddl
353 
355 
356 #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:55
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.
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:87
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.
@ struct_type
value for struct type
Definition: ddl_capi.h:57
OO DataDefinition DDStructure 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.
size_t getDecoderOrFactoryElementCount(const T &decoder_or_factory)
Get the Decoder or Factory leaf element count.