Dev Essential  1.6.3
Loading...
Searching...
No Matches
static_codec.h
Go to the documentation of this file.
1
14
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>
25
26#include <functional>
27namespace ddl {
28namespace codec {
29
30// forward declarations
31class ElementAccessor;
32class StructAccess;
33class CodecFactory;
34
39public:
41 ~StaticDecoder() = default;
49 StaticDecoder(const StaticDecoder&) = delete;
78 Element getElement(const CodecIndex& codec_index) const;
95 Element getElement(std::string_view full_path) const;
96
110 Element getChildElement(const CodecIndex& parent_codec_index,
111 std::string_view relative_path) const;
124 const Elements& getElements() const;
132 size_t getElementChildCount(const CodecIndex& codec_index = CodecIndex()) const;
144 std::string getElementFullName(const CodecIndex& codec_index) const;
156 std::string getElementName(const CodecIndex& codec_index) const;
168 const std::string& getElementBaseName(const CodecIndex& codec_index) const;
176 template <typename T>
177 T getElementValue(const CodecIndex& codec_index) const
178 {
179 return ValueGetterSelect<StaticDecoder, T>::getValue(*this, codec_index);
180 }
181
189 template <typename T>
190 T getElementValue(const LeafCodecIndex& leaf_codec_index) const
191 {
192 return LeafValueGetter<T>::getValue(getData(), getDataSize(), leaf_codec_index.getLayout());
193 }
194
207 void getElementVariantValue(const CodecIndex& codec_index,
208 a_util::variant::Variant& value) const;
217 std::string getElementStringValue(const CodecIndex& codec_index) const;
226 void getElementRawValue(const CodecIndex& index, void* value, size_t value_size) const;
231 const void* getElementAddress(const CodecIndex& index) const;
237 size_t getStaticBufferSize() const;
249
250public: // legacy
256 CodecIndex resolve(size_t leaf_index) const;
257
264 CodecIndex resolve(size_t leaf_index, std::string& element_full_name) const;
269 size_t getElementCount() const;
278 const ddl::StructElement*& legacy_struct_element) const;
279
285 void resolve(CodecIndex& codec_index) const;
286
292 const void* getData() const noexcept;
298 size_t getDataSize() const noexcept;
299
300protected:
301 friend class CodecFactory;
302
304 StaticDecoder(std::shared_ptr<const StructAccess> codec_access,
305 const void* data,
306 size_t data_size,
307 DataRepresentation representation);
308
309protected:
311 std::shared_ptr<const StructAccess> _codec_access;
313 const void* _data = nullptr;
315 size_t _data_size = 0;
317 const ddl::codec::ElementAccessor* _element_accessor;
318
319private:
321 ddl::access_element::StructElementLegacy<const StaticDecoder> _legacy_element;
322 Element _first_element;
323};
324
328class StaticCodec final : public StaticDecoder {
329public:
337 StaticCodec(const StaticCodec&) = delete;
338
343
348
353
367 Element getElement(const CodecIndex& codec_index);
384 Element getElement(std::string_view full_path);
385
399 Element getChildElement(const CodecIndex& parent_codec_index,
400 std::string_view relative_path);
401
415
424 template <typename T>
425 void setElementValue(const CodecIndex& codec_index, const T& value)
426 {
427 ValueSetterSelect<StaticCodec, T>::setValue(*this, codec_index, value);
428 }
429
438 template <typename T>
439 void setElementValue(const LeafCodecIndex& leaf_codec_index, const T& value)
440 {
441 LeafValueSetter<T>::setValue(getData(), getDataSize(), leaf_codec_index.getLayout(), value);
442 }
443
452 void setElementVariantValue(const CodecIndex& codec_index,
453 const a_util::variant::Variant& value);
461 void setElementStringValue(const CodecIndex& codec_index, const std::string& value);
472 void setElementRawValue(const CodecIndex& codec_index, const void* value, size_t value_size);
478 void* getElementAddress(const CodecIndex& codec_index);
485 void resetValues(bool zero_values = false);
486
493 void* getData() noexcept;
494
495private:
496 friend class CodecFactory;
498 StaticCodec(std::shared_ptr<const StructAccess> codec_access,
499 void* data,
500 size_t data_size,
501 DataRepresentation representation);
502 Element _first_element;
503};
504
505} // namespace codec
506} // namespace ddl
507
508#include <ddl/codec/legacy/static_codec_legacy.h>
509
510#endif // DDL_STATIC_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_factory.h:31
Definition codec_index.h:276
A DecoderElement to get values.
Definition codec_iterator.h:969
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
void * getElementAddress(const CodecIndex &codec_index)
StaticCodec & operator=(const StaticCodec &)=delete
void setElementValue(const LeafCodecIndex &leaf_codec_index, const T &value)
Definition static_codec.h:439
void setElementStringValue(const CodecIndex &codec_index, const std::string &value)
CodecElement< CodecElementAccess< StaticCodec > > Element
Definition static_codec.h:359
void resetValues(bool zero_values=false)
Element getChildElement(const CodecIndex &parent_codec_index, std::string_view relative_path)
ChildElements< CodecElementAccess< StaticCodec > > Elements
Definition static_codec.h:408
StaticCodec(StaticCodec &&)
void * getData() noexcept
Get the current set data.
StaticCodec(const StaticCodec &)=delete
StaticCodec & operator=(StaticCodec &&)
void setElementVariantValue(const CodecIndex &codec_index, const a_util::variant::Variant &value)
void setElementRawValue(const CodecIndex &codec_index, const void *value, size_t value_size)
Element getElement(const CodecIndex &codec_index)
Elements & getElements()
Element getElement(std::string_view full_path)
void setElementValue(const CodecIndex &codec_index, const T &value)
Definition static_codec.h:425
size_t getDataSize() const noexcept
Get the current size (in bytes) of the data.
size_t _data_size
For internal use only.
Definition static_codec.h:315
StaticDecoder & operator=(StaticDecoder &&)
const std::string & getElementBaseName(const CodecIndex &codec_index) const
Retrieves the base name of the element within its structured element.
T getElementValue(const CodecIndex &codec_index) const
Definition static_codec.h:177
size_t getElementChildCount(const CodecIndex &codec_index=CodecIndex()) const
Element getElement(std::string_view full_path) const
std::string getElementFullName(const CodecIndex &codec_index) const
Retrieves the full name of the element within its main structure.
std::string getElementName(const CodecIndex &codec_index) const
Retrieves the name of the element within its structured element.
std::string getElementStringValue(const CodecIndex &codec_index) const
size_t getStaticBufferSize(DataRepresentation rep) const
Gets the static buffer size in bytes for the main structure.
void getElementVariantValue(const CodecIndex &codec_index, a_util::variant::Variant &value) const
const void * _data
For internal use only.
Definition static_codec.h:313
CodecIndex resolve(size_t leaf_index) const
StaticDecoder(StaticDecoder &&)
ChildElements< DecoderElementAccess< const StaticDecoder > > Elements
Definition static_codec.h:117
const void * getData() const noexcept
Get the current set data.
StaticDecoder & operator=(const StaticDecoder &)=delete
StaticDecoder(const StaticDecoder &)=delete
std::shared_ptr< const StructAccess > _codec_access
For internal use only.
Definition static_codec.h:311
a_util::result::Result getElement(size_t leaf_index, const ddl::StructElement *&legacy_struct_element) const
Element getElement(const CodecIndex &codec_index) const
DecoderElement< DecoderElementAccess< const StaticDecoder > > Element
Definition static_codec.h:70
DataRepresentation getRepresentation() const
T getElementValue(const LeafCodecIndex &leaf_codec_index) const
Definition static_codec.h:190
~StaticDecoder()=default
DTOR.
const ddl::codec::ElementAccessor * _element_accessor
For internal use only.
Definition static_codec.h:317
a_util::variant::Variant getElementVariantValue(const CodecIndex &codec_index) const
void resolve(CodecIndex &codec_index) const
size_t getStaticBufferSize() const
Gets the static buffer size in bytes for the main structure.
size_t getElementCount() const
Element getChildElement(const CodecIndex &parent_codec_index, std::string_view relative_path) const
const Elements & getElements() const
const void * getElementAddress(const CodecIndex &index) const
virtual a_util::result::Result isValid() const
CodecIndex resolve(size_t leaf_index, std::string &element_full_name) const
void getElementRawValue(const CodecIndex &index, void *value, size_t value_size) const
definition of the access_element namespace (codecs)
Definition access_element.h:25
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
Definition struct_element.h:32
static ValueType getValue(const void *data, const size_t data_size, const LeafLayout &leaf_layout)
Definition leaf_value_access.h:789
static void setValue(void *data, const size_t data_size, const LeafLayout &leaf_layout, const ValueType &value)
Definition leaf_value_access.h:820
static ValueType getValue(const DecoderType &decoder, const CodecIndex &codec_index)
Definition value_access.h:168
static void setValue(CodecType &codec, const CodecIndex &codec_index, const ValueType &value)
Definition value_access.h:227