14#ifndef DDL_STRUCT_ELEMENT_ACCESS_CLASS_HEADER
15#define DDL_STRUCT_ELEMENT_ACCESS_CLASS_HEADER
36using is_factory = std::is_member_function_pointer<
decltype(&T::getStaticElementCount)>;
38template <
typename T,
typename Enable =
void>
40 static inline size_t getElementCount(
const T& access_type)
42 return access_type.getElementCount();
49 return access_type.getElement(element_idx, element);
54struct Accessor<T, typename std::enable_if<is_factory<T>::value>::type> {
55 static inline size_t getElementCount(
const T& access_type)
57 return access_type.getStaticElementCount();
64 return access_type.getStaticElement(element_idx, element);
70 const std::string& struct_name,
74 if (struct_name.empty()) {
76 return a_util::result::SUCCESS;
79 size_t element_count = detail::Accessor<T>::getElementCount(decoder);
80 std::string prefix = struct_name + post_fix;
81 for (
size_t element_index = 0; element_index < element_count; ++element_index) {
83 if (detail::Accessor<T>::getElement(decoder, element_index, element)) {
86 index = element_index;
87 return a_util::result::SUCCESS;
109 size_t element_count = detail::Accessor<T>::getElementCount(decoder);
110 for (
size_t element_index = 0; element_index < element_count; ++element_index) {
112 if (detail::Accessor<T>::getElement(decoder, element_index, element)) {
113 if (element->
name == element_name) {
114 index = element_index;
115 return a_util::result::SUCCESS;
132 const std::string& struct_name,
135 return detail::findComplexIndex<T>(decoder, struct_name, index,
".");
147 const std::string& array_name,
150 return detail::findComplexIndex<T>(decoder, array_name, index,
"[");
162 const std::string& array_name,
165 size_t element_count = detail::Accessor<T>::getElementCount(decoder);
166 std::string prefix = array_name +
"[";
167 for (index += 1; index < element_count; ++index) {
169 if (!detail::Accessor<T>::getElement(decoder, index, element)) {
170 return a_util::result::SUCCESS;
175 return a_util::result::SUCCESS;
179 return a_util::result::SUCCESS;
192 auto element_index{
static_cast<std::size_t
>(-1)};
194 return res ? decoder.getElementValue(element_index, value) : res;
207 auto element_index{
static_cast<std::size_t
>(-1)};
209 return res ?
codec.setElementValue(element_index, value) : res;
222 auto element_index{
static_cast<std::size_t
>(-1)};
223 if (
findIndex(decoder, element_name, element_index)) {
224 decoder.getElementValue(element_index, result);
238 const std::string& element_name,
241 auto element_index{
static_cast<std::size_t
>(-1)};
243 return res ?
codec.setElementValue(element_index, value) : res;
256 if (decoder.getElementValue(element_index, result)) {
272 auto element_index{
static_cast<std::size_t
>(-1)};
273 if (find_index(decoder, element_name, element_index)) {
274 return decoder.getElementAddress(element_index);
289 auto element_index{
static_cast<std::size_t
>(-1)};
291 return codec.getElementAddress(element_index);
303template <
typename STRUCT,
typename T>
306 auto element_index{
static_cast<std::size_t
>(-1)};
308 return reinterpret_cast<const STRUCT*
>(decoder.getElementAddress(element_index));
320template <
typename STRUCT,
typename T>
323 auto element_index{
static_cast<std::size_t
>(-1)};
325 return reinterpret_cast<STRUCT*
>(
codec.getElementAddress(element_index));
338template <
typename T,
typename CODEC>
340 const std::string& struct_name,
349 return a_util::result::SUCCESS;
359template <
typename T,
typename CODEC>
361 const std::string& struct_name,
362 const T* struct_value)
370 return a_util::result::SUCCESS;
379template <
typename ARRAY_TYPE,
typename T>
382 auto element_index{
static_cast<std::size_t
>(-1)};
383 if (find_array_index(decoder, array_name, element_index)) {
384 return reinterpret_cast<const ARRAY_TYPE*
>(decoder.getElementAddress(element_index));
396template <
typename ARRAY_TYPE,
typename T>
399 auto element_index{
static_cast<std::size_t
>(-1)};
401 return reinterpret_cast<ARRAY_TYPE*
>(
codec.getElementAddress(element_index));
415template <
typename CODEC>
417 const std::string& array_name,
418 const void*& start_address,
421 size_t start_index = 0;
426 size_t end_index = start_index;
431 start_address = decoder.getElementAddress(start_index);
432 if (!start_address) {
436 const void* end_adress = decoder.getElementAddress(end_index);
438 size =
static_cast<const uint8_t*
>(end_adress) -
static_cast<const uint8_t*
>(start_address);
442 size_t start_offset =
static_cast<const uint8_t*
>(start_address) -
443 static_cast<const uint8_t*
>(decoder.getElementAddress(0));
444 size = decoder.getBufferSize(decoder.getRepresentation()) - start_offset;
447 return a_util::result::SUCCESS;
457template <
typename T,
typename CODEC>
459 const std::string& array_name,
462 const void* start_address =
nullptr;
469 return a_util::result::SUCCESS;
481 auto element_index{
static_cast<std::size_t
>(-1)};
487 return codec.setElementValue(element_index, &zero);
491#define DDL_GET_ENUM_CASE(__variant_type, __data_type) \
492 case a_util::variant::VT_##__variant_type: { \
493 __data_type xValue = value.get##__variant_type(); \
494 for (AccessEnumType::const_iterator it = element->p_enum->begin(); \
495 it != element->p_enum->end(); \
497 if (xValue == it->second.as##__variant_type()) { \
515 if (decoder.getElement(element_index, element)) {
516 if (decoder.getElementValue(element_index, value)) {
517 if (element->p_enum) {
549 auto element_index{
static_cast<std::size_t
>(-1)};
550 if (
findIndex(decoder, element_name, element_index)) {
Definition result_type_decl.h:34
VariantType getType() const
Returns the current underlying data type of the instance.
std::string asString() const
#define RETURN_ERROR_DESCRIPTION(_errcode,...)
Definition error_def.h:39
#define DDL_GET_ENUM_CASE(__variant_type, __data_type)
For internal use only.
Definition access_element.h:491
bool copy(void *dest, std::size_t dest_size, const void *source, std::size_t bytes_to_copy)
int compare(const char *left, const char *right)
definition of the access_element namespace (codecs)
Definition access_element.h:25
a_util::result::Result findArrayEndIndex(const T &decoder, const std::string &array_name, size_t &index)
Definition access_element.h:161
const void * getValueAddress(const T &decoder, const std::string &element_name)
Definition access_element.h:270
std::string getValueAsString(const T &decoder, size_t element_index)
Definition access_element.h:511
a_util::result::Result reset(T &codec, const std::string &element_name)
Definition access_element.h:479
const STRUCT * getStructAddress(const T &decoder, const std::string &struct_name)
Definition access_element.h:304
const ARRAY_TYPE * getArrayAddress(const T &decoder, const std::string &array_name)
Definition access_element.h:380
a_util::result::Result getStructValue(const CODEC &decoder, const std::string &struct_name, T *struct_value)
Definition access_element.h:339
a_util::result::Result findArrayIndex(const T &decoder, const std::string &array_name, size_t &index)
Definition access_element.h:146
a_util::result::Result setStructValue(CODEC &codec, const std::string &struct_name, const T *struct_value)
Definition access_element.h:360
a_util::result::Result getArrayValue(const CODEC &decoder, const std::string &array_name, T *array_value)
Definition access_element.h:458
a_util::result::Result findIndex(const T &decoder, const std::string &element_name, size_t &index)
Definition access_element.h:107
a_util::result::Result getValue(const T &decoder, const std::string &element_name, void *value)
Definition access_element.h:190
a_util::result::Result findStructIndex(const T &decoder, const std::string &struct_name, size_t &index)
Definition access_element.h:131
a_util::result::Result setValue(T &codec, const std::string &element_name, const void *value)
Definition access_element.h:205
a_util::result::Result getArray(const CODEC &decoder, const std::string &array_name, const void *&start_address, size_t &size)
Definition access_element.h:416
Namespace for the new faster CodecFactory/Decoder/Codec implementation.
Definition codec.h:22
definition of the ddl namespace
Definition codec.h:21
#define _MAKE_RESULT(_no, _label)
Definition result_info_decl.h:36
Definition struct_element.h:32
std::string name
The full name of the element.
Definition struct_element.h:33