Dev Essential
Loading...
Searching...
No Matches
codec.h
Go to the documentation of this file.
1
14
15#ifndef DDL_CODEC_CLASS_HEADER
16#define DDL_CODEC_CLASS_HEADER
17
18#include <a_util/result.h>
20
21namespace ddl {
22namespace codec {
23
24class Codec;
25class StructAccess;
26
30class Decoder : public StaticDecoder {
31public:
36
41
46
50 Decoder(const Decoder&) = delete;
51
55 Decoder& operator=(const Decoder&) = delete;
56
72 Element getElement(const CodecIndex& codec_index) const;
89 Element getElement(std::string_view full_path) const;
90
104 Element getChildElement(const CodecIndex& parent_codec_index,
105 std::string_view relative_path) const;
117 const Elements& getElements() const;
123 size_t getBufferSize() const;
130 size_t getBufferSize(DataRepresentation representation) const;
138 Codec makeCodecFor(void* data, size_t data_size, DataRepresentation representation) const;
139
140protected:
141 friend class CodecFactory;
143 Decoder(std::shared_ptr<const StructAccess> codec_access,
144 const void* data,
145 size_t data_size,
146 DataRepresentation representation);
148 Decoder(const Decoder& decoder,
149 const void* data,
150 size_t data_size,
151 DataRepresentation representation);
153 friend class FactoryElementAccess<const Decoder>;
154
155private:
156 Element _first_element;
157};
158
164class Codec : public Decoder {
165public:
181 Codec(const Codec&) = delete;
185 Codec& operator=(const Codec&) = delete;
186
201 Element getElement(const CodecIndex& codec_index);
218 Element getElement(std::string_view full_path);
232 Element getChildElement(const CodecIndex& parent_codec_index, std::string_view relative_path);
253 template <typename T>
254 void setElementValue(const CodecIndex& codec_index, const T& value)
255 {
256 ValueSetterSelect<Codec, T>::setValue(*this, codec_index, value);
257 }
258
267 template <typename T>
268 void setElementValue(const LeafCodecIndex& leaf_codec_index, const T& value)
269 {
270 LeafValueSetter<T>::setValue(getData(), getDataSize(), leaf_codec_index.getLayout(), value);
271 }
272
281 void setElementVariantValue(const CodecIndex& codec_index,
282 const a_util::variant::Variant& value);
290 void setElementStringValue(const CodecIndex& codec_index, const std::string& value);
300 void setElementRawValue(const CodecIndex& codec_index, const void* value, size_t value_size);
305 void* getElementAddress(const CodecIndex& codec_index);
312 void resetValues(bool zero_values = false);
313
314 using Decoder::getData;
320 void* getData() noexcept;
321
322protected:
323 friend class CodecFactory;
324 friend class Decoder;
326 Codec(std::shared_ptr<const StructAccess> codec_access,
327 void* data,
328 size_t data_size,
331 Codec(const Decoder& decoder,
332 void* data,
333 size_t data_size,
334 ddl::DataRepresentation representation);
335
336private:
337 Element _first_element;
338};
339
340} // namespace codec
341} // namespace ddl
342
343#include <ddl/codec/legacy/codec_legacy.h>
344
345#endif // DDL_CODEC_CLASS_HEADER
Definition result_type_decl.h:34
Definition variant.h:46
Iteratable container type for the given Element type in ElementAccessType::element_type.
Definition codec_iterator.h:257
A CodecElement to get and set values.
Definition codec_iterator.h:1221
Definition codec_index.h:276
Definition codec.h:164
void * getData() noexcept
Get the current set data.
ChildElements< CodecElementAccess< Codec > > Elements
Definition codec.h:238
CodecElement< CodecElementAccess< Codec > > Element
Definition codec.h:193
Codec(const Codec &)=delete
void resetValues(bool zero_values=false)
void setElementValue(const CodecIndex &codec_index, const T &value)
Definition codec.h:254
Codec & operator=(Codec &&)
void setElementStringValue(const CodecIndex &codec_index, const std::string &value)
Element getElement(std::string_view full_path)
Element getChildElement(const CodecIndex &parent_codec_index, std::string_view relative_path)
void setElementValue(const LeafCodecIndex &leaf_codec_index, const T &value)
Definition codec.h:268
void setElementRawValue(const CodecIndex &codec_index, const void *value, size_t value_size)
Element getElement(const CodecIndex &codec_index)
void setElementVariantValue(const CodecIndex &codec_index, const a_util::variant::Variant &value)
Elements & getElements()
Codec & operator=(const Codec &)=delete
void * getElementAddress(const CodecIndex &codec_index)
A DecoderElement to get values.
Definition codec_iterator.h:969
a_util::result::Result isValid() const override
size_t getBufferSize(DataRepresentation representation) const
Gets the buffer size in bytes for the main structure.
Decoder & operator=(const Decoder &)=delete
Element getElement(const CodecIndex &codec_index) const
ChildElements< DecoderElementAccess< const Decoder > > Elements
Definition codec.h:111
const Elements & getElements() const
Element getElement(std::string_view full_path) const
size_t getBufferSize() const
Gets the buffer size in bytes for the main structure.
Decoder(const Decoder &decoder, const void *data, size_t data_size, DataRepresentation representation)
For internal use only.
Decoder(Decoder &&)
Decoder(std::shared_ptr< const StructAccess > codec_access, const void *data, size_t data_size, DataRepresentation representation)
For internal use only.
DecoderElement< DecoderElementAccess< const Decoder > > Element
Definition codec.h:64
Element getChildElement(const CodecIndex &parent_codec_index, std::string_view relative_path) const
Decoder(const Decoder &)=delete
Decoder & operator=(Decoder &&)
Codec makeCodecFor(void *data, size_t data_size, DataRepresentation representation) const
A factory element access type concept template to retrieve element information from the AccessType....
Definition codec_iterator.h:439
The Leaf codec index is a small layout information index to access the decoders/codecs data very fast...
Definition leaf_value_access.h:43
const LeafLayout & getLayout() const noexcept
Get the leaf layout.
Definition leaf_value_access.h:66
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
Namespace for the new faster CodecFactory/Decoder/Codec implementation.
Definition codec.h:22
definition of the ddl namespace
Definition codec.h:21
DataRepresentation
Definition data_representation.h:25
static void setValue(void *data, const size_t data_size, const LeafLayout &leaf_layout, const ValueType &value)
Definition leaf_value_access.h:820
static void setValue(CodecType &codec, const CodecIndex &codec_index, const ValueType &value)
Definition value_access.h:227