ADTF  3.18.3
streammetatypeplain.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include "streamtype.h"
9 #include <adtfucom3/adtf_ucom3.h>
10 #include <adtfbase/adtf_base.h>
11 #include <adtf_base_deprecated.h>
12 #include <type_traits>
13 #include <vector>
14 #include <array>
15 
16 namespace adtf
17 {
18 namespace streaming
19 {
20 namespace ant
21 {
22 
31 {
33  static constexpr const tChar *const MetaTypeName = "adtf/plaintype";
60  static constexpr const tChar *const PlainTypeProperty = "c-type";
61 
66  {
67  pProperties->SetProperty(adtf::base::property<adtf_util::cString>(PlainTypeProperty, ""));
68  }
69 
86  const adtf::streaming::IStreamType& oTypeExpected)
87  {
89  RETURN_IF_FAILED(oTypeToCheck.GetConfig(pCheckProperties));
91  RETURN_IF_FAILED(oTypeExpected.GetConfig(pExpectedProperties));
92 
93  auto strCheckPlainType = adtf::base::get_property<adtf_util::cString>(*pCheckProperties, PlainTypeProperty);
94  auto strExpectedPlainType = adtf::base::get_property<adtf_util::cString>(*pExpectedProperties, PlainTypeProperty);
95 
96  if (strCheckPlainType != strExpectedPlainType)
97  {
98  RETURN_ERROR_DESC(ERR_FAILED,
99  "The destination plain type '%s' differs from the source plain type '%s'",
100  strCheckPlainType.GetPtr(),
101  strExpectedPlainType.GetPtr());
102  }
103 
105  }
106 };
107 
117 template <typename T>
119 {
120  static_assert(base::penguin::detail::always_false<T>, "Invalid type for stream_type_plain<T> used! "
121  "Use bool, uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t, float, double or plain array T[], std::array, std::vector of them");
122 };
123 
130 #define ADTF_DEFINE_STREAM_TYPE_PLAIN_FOR( _thetype_ , _propval_ ) \
131 template <> \
132 class stream_type_plain<_thetype_> : public cStreamType \
133 { \
134 public: \
135  static constexpr const char *const PlainTypeValue = _propval_; \
136  static constexpr const char* const PlainTypeName = #_thetype_; \
137  stream_type_plain() : cStreamType(stream_meta_type_plain()) \
138  { \
139  adtf::ucom::object_ptr<adtf::base::ant::IProperties> pProperties; \
140  THROW_IF_FAILED(GetConfig(pProperties)); \
141  pProperties->SetProperty(adtf::base::property<adtf_util::cString>(stream_meta_type_plain::PlainTypeProperty, PlainTypeValue)); \
142  pProperties->SetProperty(adtf::base::property<adtf_util::cString>("md_definitions",\
143  adtf_util::cString::Format(R"(<struct name=")" _propval_ R"(" alignment="1" version="1">)" \
144  R"(<element name="value" arraysize="1" type=")" #_thetype_ R"(">)" \
145  R"(<deserialized alignment="1"/>)" \
146  R"(<serialized bytepos="0" byteorder="%s"/>)" \
147  "</element>" \
148  "</struct>", \
149  PLATFORM_BYTEORDER == PLATFORM_BIG_ENDIAN_8 ? "BE" : "LE"))); \
150  pProperties->SetProperty(adtf::base::property<adtf_util::cString>("md_struct", _propval_));\
151  } \
152 }
153 
158 
199 
200 } //namespace ant
201 
202 namespace lucky
203 {
210 template<typename T>
211 ADTF3_DEPRECATED("Use adtf::ucom::make_object_ptr<stream_type_plain<T>>() instead!")
213 {
214  return ucom::ant::make_object_ptr<ant::stream_type_plain<T>>();
215 }
216 }
217 
218 namespace penguin
219 {
229 {
237  static constexpr const char* const ArraySize = "array_size";
238 
244  static constexpr const char* const DataEndianess = "data_endianess";
249  {
251  pProperties->SetProperty(adtf::base::property<size_t>(ArraySize, 1));
252  const auto ui8CurrentPlatformOrder = PLATFORM_BYTEORDER;
253  if (ui8CurrentPlatformOrder != PLATFORM_LITTLE_ENDIAN_8)
254  {
255  pProperties->SetProperty(adtf::base::property<uint8_t>(DataEndianess, ui8CurrentPlatformOrder));
256  }
257  }
258 
277  const adtf::streaming::IStreamType& oTypeExpected)
278  {
280  RETURN_IF_FAILED(oTypeToCheck.GetConfig(pCheckProperties));
282  RETURN_IF_FAILED(oTypeExpected.GetConfig(pExpectedProperties));
283 
284  const auto strCheckPlainType = adtf::base::get_property<adtf_util::cString>(*pCheckProperties, PlainTypeProperty);
285  const auto strExpectedPlainType = adtf::base::get_property<adtf_util::cString>(*pExpectedProperties, PlainTypeProperty);
286 
287  if (strCheckPlainType != strExpectedPlainType)
288  {
289  RETURN_ERROR_DESC(ERR_FAILED,
290  "The checked plain type '%s' differs from the expected plain type '%s'",
291  strCheckPlainType.GetPtr(),
292  strExpectedPlainType.GetPtr());
293  }
294  const auto uiCheckDataEndianess = adtf::base::get_property<uint8_t>(*pCheckProperties, DataEndianess, PLATFORM_LITTLE_ENDIAN_8);
295  const auto uiExpectedDataEndianess
296  = adtf::base::get_property<uint8_t>(*pExpectedProperties, DataEndianess, PLATFORM_LITTLE_ENDIAN_8);
297  if (uiCheckDataEndianess != uiExpectedDataEndianess)
298  {
299  if (strCheckPlainType != "UINT8" && strCheckPlainType != "INT8" && strCheckPlainType != "BOOL" && strCheckPlainType != "UINT8_ARRAY" && strCheckPlainType != "INT8_ARRAY" && strCheckPlainType != "BOOL_ARRAY")
300  {
301  RETURN_ERROR_DESC(ERR_FAILED,
302  "The checked plain type '%s' differs from the expected plain type '%s' in endianess",
303  strCheckPlainType.GetPtr(),
304  strExpectedPlainType.GetPtr());
305  }
306  }
307 
308  const auto uiCheckArraySize = adtf::base::get_property<size_t>(*pCheckProperties, ArraySize, 1);
309  const auto uiExpectedArraySize = adtf::base::get_property<size_t>(*pExpectedProperties, ArraySize, 1);
310  if (uiCheckArraySize < uiExpectedArraySize)
311  {
313  ERR_FAILED,
314  "The checked plain type '%s' array size (%zu) is lower than the expected plain type '%s' array size (%zu)",
315  strCheckPlainType.GetPtr(), uiCheckArraySize, strExpectedPlainType.GetPtr(), uiExpectedArraySize);
316  }
317 
319  }
320 };
321 
330 template<typename T>
332 {
333 public:
336  ant::stream_type_plain<T>()
337  {
341  const auto ui8CurrentPlatformOrder = PLATFORM_BYTEORDER;
342  if (ui8CurrentPlatformOrder != PLATFORM_LITTLE_ENDIAN_8)
343  {
344  pProperties->SetProperty(
346  }
347  }
348 };
349 
357 template<typename ValueType, size_t szArraySize, template<typename, size_t> class T>
358 class stream_type_plain<T<ValueType, szArraySize>> : public cStreamType
359 {
360  static_assert(std::is_arithmetic_v<typename T<ValueType, szArraySize>::value_type>,
361  "std::array can only be used for arithmetic types");
362 
363 public:
366  {
368  THROW_IF_FAILED(GetConfig(pProperties));
369 
370  const adtf_util::cString strPropValue = adtf_util::cString::Format(
371  "%s_ARRAY", ant::stream_type_plain<typename T<ValueType, szArraySize>::value_type>::PlainTypeValue);
372  const adtf_util::cString strPropTypeName(ant::stream_type_plain<typename T<ValueType, szArraySize>::value_type>::PlainTypeName);
374  pProperties->SetProperty(adtf::base::property<size_t>(stream_meta_type_plain::ArraySize, szArraySize));
375 
376  // prepare for ddl usage
377  const adtf_util::cString strMDDefValue = adtf_util::cString::Format(R"(<struct name="%s" alignment="1" version="1">
378  <element name="value" arraysize="%zu" type="%s">
379  <deserialized alignment="1"/>
380  <serialized bytepos="0" byteorder="%s"/>
381  </element>
382 </struct>)", strPropValue.GetPtr(), szArraySize,
383  strPropTypeName.GetPtr(),
384  PLATFORM_BYTEORDER == PLATFORM_BIG_ENDIAN_8 ? "BE" : "LE");
385  pProperties->SetProperty(adtf::base::property<adtf_util::cString>("md_definitions",
386  strMDDefValue));
387  pProperties->SetProperty(adtf::base::property<adtf_util::cString>("md_struct", strPropValue));
388 
389  }
390 };
391 
398 template<class ValueType, size_t szArraySize>
399 class stream_type_plain<ValueType[szArraySize]> : public stream_type_plain<std::array<ValueType, szArraySize>>
400 {
401 };
402 
408 template<typename T>
409 ADTF3_DEPRECATED("Use adtf::ucom::make_object_ptr<stream_type_plain<T>>() instead!")
411 {
412  return ucom::ant::make_object_ptr<penguin::stream_type_plain<T>>();
413 }
414 
415 } // namespace penguin
416 
418 using penguin::stream_meta_type_plain;
419 
421 using penguin::stream_type_plain;
422 
425 
426 } //namespace streaming
427 } //namespace adtf
Copyright © Audi Electronics Venture GmbH.
#define ADTF3_DEPRECATED(_depr_message_)
Mark a function or variable as deprecated.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
uint8_t tUInt8
type definition for unsigned integer values (8bit) (platform and compiler independent type).
char tChar
The tChar defines the type for platform character set (platform and compiler dependent type).
int64_t tInt64
type definition for signed integer values (64bit) (platform and compiler independent type).
int16_t tInt16
type definition for signed integer values (16bit) (platform and compiler independent type).
int32_t tInt32
type definition for signed integer values (32bit) (platform and compiler independent type).
float tFloat32
type definition for Float32 (32bit float values) (platform and compiler independent type).
uint16_t tUInt16
type definition for unsigned integer values (16bit) (platform and compiler independent type).
double tFloat64
type definition for Float64 (64bit double values) (platform and compiler independent type).
bool tBool
The tBool defines the type for the Values tTrue and tFalse (platform and compiler dependent).
uint32_t tUInt32
type definition for unsigned integer values (32bit) (platform and compiler independent type).
int8_t tInt8
type definition for signed integer values (8bit) (platform and compiler independent type).
uint64_t tUInt64
type definition for unsigned integer values (64bit) (platform and compiler independent type).
#define RETURN_ERROR_DESC(_code,...)
Same as RETURN_ERROR(_error) using a printf like parameter list for detailed error description.
#define RETURN_IF_FAILED(s)
Return if expression is failed, which requires the calling function's return type to be tResult.
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Defines access methods for the interface of a Stream Type - see also Stream Type and Stream Meta Type...
virtual tResult GetConfig(ucom::ant::iobject_ptr< base::ant::IProperties > &pProperties)=0
Get all properties of a Stream Type (read/write)
Default StreamType implementation.
Definition: streamtype.h:282
Generator template to create an instance of a ant::IStreamType class for ant::stream_meta_type_plain ...
Generator template to create an instance of a ant::IStreamType class for penguin::stream_meta_type_pl...
Base object pointer to realize binary compatible reference counting in interface methods.
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:163
#define PLATFORM_BIG_ENDIAN_8
defines the big endianess value, that will be retrieved by
Definition: constants.h:121
#define PLATFORM_BYTEORDER
defines a link to __get_platform_byteorder.
Definition: constants.h:124
#define PLATFORM_LITTLE_ENDIAN_8
defines the little endianess value, that will be retrieved by
Definition: constants.h:118
string_base< cStackString > cString
cString implementation for a stack string which works on stack if string is lower than A_UTILS_DEFAUL...
Definition: string.h:2778
ADTF_DEFINE_STREAM_TYPE_PLAIN_FOR(tBool, "BOOL")
defines a stream_type_plain for the c-type bool
ucom::ant::object_ptr< ant::IStreamType > create_adtf_plain_stream_type()
Convenience functionality to create a stream type plain - see Stream Meta Type "adtf/plaintype".
ucom::ant::object_ptr< ant::IStreamType > create_adtf_plain_stream_type()
Convenience functionality to create a stream type plain - see Stream Meta Type "adtf/plaintype".
ant::object_ptr< T > object_ptr
Alias always bringing the latest version of ant::object_ptr into scope.
Definition: object_ptr.h:413
Namespace for entire ADTF SDK.
Copyright © Audi Electronics Venture GmbH.
Use this Stream Meta Type if your sample data will be any of this type: bool, uint8_t,...
static constexpr const tChar *const PlainTypeProperty
c-type Property for plaintype Stream Meta Type
static void SetProperties(const adtf::ucom::iobject_ptr< adtf::base::IProperties > &pProperties)
Property setter for plaintype.
static constexpr const tChar *const MetaTypeName
StreamMetaTypeName for plaintype.
static tResult IsCompatible(const adtf::streaming::IStreamType &oTypeToCheck, const adtf::streaming::IStreamType &oTypeExpected)
Compares the oTypeExpected Stream Type with the oTypeToCheck - see Default Stream Meta Types in ADTF ...
Use this Stream Meta Type if your sample data will be any of this type: bool, uint8_t,...
static constexpr const char *const DataEndianess
Identify the endianess of the content.
static constexpr const char *const ArraySize
Array size for the used type.
static void SetProperties(const adtf::ucom::iobject_ptr< adtf::base::IProperties > &pProperties)
Property setter for plaintype.
static tResult IsCompatible(const adtf::streaming::IStreamType &oTypeToCheck, const adtf::streaming::IStreamType &oTypeExpected)
Compares the oTypeExpected Stream Type with the oTypeToCheck - see Default Stream Meta Types in ADTF ...
#define THROW_IF_FAILED(s)
throws if the expression returns a failed tResult