Dev Essential
Loading...
Searching...
No Matches
codec_factory.h
Go to the documentation of this file.
1
14
15#ifndef DDL_CODEC_FACTORY_CLASS_HEADER
16#define DDL_CODEC_FACTORY_CLASS_HEADER
17
18#include <ddl/codec/codec.h>
22#include <ddl/dd/dd.h>
23#include <ddl/dd/ddstructure.h>
25
26namespace ddl {
27namespace codec {
32public:
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,
103 {
104 return StaticDecoder(_codec_access, data, data_size, rep);
105 }
106
115 size_t data_size,
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(std::string_view full_path) const;
169
183 Element getChildElement(const CodecIndex& parent_codec_index,
184 std::string_view relative_path) const;
197 const Elements& getElements() const;
205 size_t getElementChildCount(const CodecIndex& codec_index = CodecIndex()) const;
217 std::string getElementFullName(const CodecIndex& codec_index) const;
229 std::string getElementName(const CodecIndex& codec_index) const;
241 const std::string& getElementBaseName(const CodecIndex& codec_index) const;
250
256 void resolve(CodecIndex& codec_index) const;
257
258public: // legacy functions
266 CodecIndex resolve(size_t leaf_index) const;
267
276 CodecIndex resolve(size_t leaf_index, std::string& full_element_name) const;
283 size_t getStaticElementCount() const;
292 const ddl::StructElement*& legacy_struct_element) const;
293
294private:
296 std::shared_ptr<const StructAccess> _codec_access;
298 a_util::result::Result _constructor_result;
300 Element _first_element;
303};
304
305namespace detail {
313template <typename T>
314size_t getDecoderOrFactoryElementCount(const T& decoder_or_factory)
315{
316 return decoder_or_factory.getStaticElementCount();
317}
318
324template <>
326{
327 return static_decoder.getElementCount();
328}
329
336template <>
338{
339 return static_codec.getElementCount();
340}
341
347template <>
349{
350 return decoder.getElementCount();
351}
352
358template <>
360{
361 return codec.getElementCount();
362}
363} // namespace detail
364
371template <typename T>
372std::vector<CodecIndex> getCodecIndices(const T& decoder_or_factory)
373{
374 std::vector<CodecIndex> indices;
375 indices.reserve(detail::getDecoderOrFactoryElementCount<T>(decoder_or_factory));
376 forEachLeafElement(decoder_or_factory.getElements(),
377 [&indices](const auto& element) { indices.push_back(element.getIndex()); });
378 return indices;
379}
380
389template <typename T>
390std::vector<LeafCodecIndex> getLeafCodecIndices(const T& decoder_or_factory,
392{
393 std::vector<LeafCodecIndex> indices;
394 indices.reserve(detail::getDecoderOrFactoryElementCount<T>(decoder_or_factory));
395 forEachLeafElement(decoder_or_factory.getElements(), [&indices, &rep](const auto& element) {
396 indices.push_back(LeafCodecIndex(element.getIndex(), rep));
397 });
398 return indices;
399}
400
401} // namespace codec
402} // namespace ddl
403
405
406#endif // DDL_CODEC_FACTORY_CLASS_HEADER
Definition result_type_decl.h:34
Utility class for a complete valid data definition of one StructType and its dependencies....
Definition ddstructure.h:57
Legacy helper for the ddl::StructElement.
Definition access_element_legacy.h:35
Iteratable container type for the given Element type in ElementAccessType::element_type.
Definition codec_iterator.h:257
FactoryElement< FactoryElementAccess< const CodecFactory > > Element
Definition codec_factory.h:143
CodecFactory(const CodecFactory &)
copy CTOR
const Elements & getElements() const
size_t getStaticBufferSize(DataRepresentation rep=deserialized) const
Gets the static buffer size in bytes for the structure.
CodecFactory & operator=(const CodecFactory &)
copy assignment operator
size_t getStaticElementCount() const
a_util::result::Result getStaticElement(size_t leaf_index, const ddl::StructElement *&legacy_struct_element) const
const std::string & getElementBaseName(const CodecIndex &codec_index) const
Retrieves the base name of the element within its structured element.
Decoder makeDecoderFor(const void *data, size_t data_size, DataRepresentation rep=deserialized) const
Element getElement(std::string_view full_path) const
CodecFactory(const std::string &struct_name, const std::string &dd_string)
CodecFactory(CodecFactory &&)
move CTOR
CodecFactory & operator=(CodecFactory &&)
move assignment operator
Element getElement(const CodecIndex &codec_index) const
CodecIndex resolve(size_t leaf_index, std::string &full_element_name) const
CodecFactory(const ddl::dd::StructType &struct_type, const dd::DataDefinition &dd)
std::string getElementName(const CodecIndex &codec_index) const
Retrieves the name of the element within its structured element.
ChildElements< FactoryElementAccess< const CodecFactory > > Elements
Definition codec_factory.h:190
CodecIndex resolve(size_t leaf_index) const
void resolve(CodecIndex &codec_index) const
size_t getElementChildCount(const CodecIndex &codec_index=CodecIndex()) const
a_util::result::Result isValid() const
std::string getElementFullName(const CodecIndex &codec_index) const
Retrieves the full name of the element within its main structure.
Element getChildElement(const CodecIndex &parent_codec_index, std::string_view relative_path) const
StaticCodec makeStaticCodecFor(void *data, size_t data_size, DataRepresentation rep=deserialized) const
Definition codec_factory.h:114
~CodecFactory()=default
Default dtor.
CodecFactory(const DDStructure &dd_struct)
CodecFactory(const ddl::dd::StructTypeAccess &struct_type_access)
StaticDecoder makeStaticDecoderFor(const void *data, size_t data_size, DataRepresentation rep=deserialized) const
Definition codec_factory.h:100
Codec makeCodecFor(void *data, size_t data_size, DataRepresentation rep=deserialized) const
Definition codec_index.h:276
Definition codec.h:164
Definition codec.h:30
A FactoryElement.
Definition codec_iterator.h:560
Definition static_codec.h:328
Definition static_codec.h:38
size_t getElementCount() const
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. This will calculate the byte positions can be used for se...
Definition dd_struct_access.h:598
size_t getDecoderOrFactoryElementCount(const T &decoder_or_factory)
Get the Decoder or Factory leaf element count.
Definition codec_factory.h:314
Namespace for the new faster CodecFactory/Decoder/Codec implementation.
Definition codec.h:22
std::vector< LeafCodecIndex > getLeafCodecIndices(const T &decoder_or_factory, ddl::DataRepresentation rep)
Get the leaf indices object.
Definition codec_factory.h:390
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.
Definition codec_iterator.h:1475
@ deserialized
first bit is zero for deserialized data representation of the LeafCodecIndex::data_flags
Definition leaf_layout.h:30
std::vector< CodecIndex > getCodecIndices(const T &decoder_or_factory)
Retrieves all codec indices for the given codec of type T.
Definition codec_factory.h:372
definition of the dd namespace
Definition datamodel_base.h:26
datamodel::StructType StructType
Definition dd.h:59
definition of the ddl namespace
Definition codec.h:21
DataRepresentation
Definition data_representation.h:25
Definition struct_element.h:32