ADTF
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
streammetatypeplain.h
Go to the documentation of this file.
1
7#pragma once
8#include "streamtype.h"
10#include <adtfbase/adtf_base.h>
12#include <type_traits>
13#include <vector>
14#include <array>
15
16namespace adtf
17{
18namespace streaming
19{
20namespace ant
21{
22
31{
33 static constexpr const tChar *const MetaTypeName = "adtf/plaintype";
60 static constexpr const tChar *const PlainTypeProperty = "c-type";
61
66 {
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
117template <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_ ) \
131template <> \
132class stream_type_plain<_thetype_> : public cStreamType \
133{ \
134public: \
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
202namespace lucky
203{
210template<typename T>
211ADTF3_DEPRECATED("Use adtf::ucom::make_object_ptr<stream_type_plain<T>>() instead!")
216}
217
218namespace 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
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
330template<typename T>
332{
333public:
337 {
341 const auto ui8CurrentPlatformOrder = PLATFORM_BYTEORDER;
342 if (ui8CurrentPlatformOrder != PLATFORM_LITTLE_ENDIAN_8)
343 {
344 pProperties->SetProperty(
346 }
347 }
348};
349
357template<typename ValueType, size_t szArraySize, template<typename, size_t> class T>
358class 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
363public:
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(),
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
398template<class ValueType, size_t szArraySize>
399class stream_type_plain<ValueType[szArraySize]> : public stream_type_plain<std::array<ValueType, szArraySize>>
400{
401};
402
408template<typename T>
409ADTF3_DEPRECATED("Use adtf::ucom::make_object_ptr<stream_type_plain<T>>() instead!")
414
415} // namespace penguin
416
418using penguin::stream_meta_type_plain;
419
421using penguin::stream_type_plain;
422
425
426} //namespace streaming
427} //namespace adtf
unsigned long tUInt32
type definition for unsigned integer values (32bit) (platform and compiler independent type).
unsigned char tUInt8
type definition for unsigned integer values (8bit) (platform and compiler independent type).
unsigned int tUInt16
type definition for unsigned integer values (16bit) (platform and compiler independent type).
signed int tInt16
type definition for signed integer values (16bit) (platform and compiler independent type).
signed char tInt8
type definition for signed integer values (8bit) (platform and compiler independent type).
signed long tInt32
type definition for signed integer values (32bit) (platform and compiler independent type).
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.
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).
float tFloat32
type definition for Float32 (32bit float values) (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).
uint64_t tUInt64
type definition for unsigned integer values (64bit) (platform and compiler independent type).
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
#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)
tResult GetConfig(adtf::ucom::iobject_ptr< base::ant::IProperties > &pProperties) override
Get all properties of a Stream Type (read/write)
Generator template to create an instance of a IStreamType class for stream_meta_type_plain ("adtf/pla...
#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
constexpr bool always_false
helper template to get a always false expression.
VALUETYPE get_property(const IConfiguration &oConfiguration, const char *strNameOfValue, VALUETYPE oDefaultValue)
Get the property content converted to the VALUETYPE.
Namespace for all functionality of the ADTF Streaming SDK provided since v3.0.
Namespace for all functionality of the ADTF Streaming SDK provided since v3.11.
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".
Namespace for the ADTF Streaming SDK.
object_ptr< Implementation > make_object_ptr(Args &&... args)
Create an instance of type object_ptr with Implementation as the shared resource.
Namespace for the ADTF uCOM3 SDK.
ant::iobject_ptr< T > iobject_ptr
Alias always bringing the latest version of ant::iobject_ptr into scope.
Namespace for entire ADTF SDK.
#define ADTF_DEFINE_STREAM_TYPE_PLAIN_FOR(_thetype_, _propval_)
Macro to create a class for the plain StreamType instance.
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