ADTF
Loading...
Searching...
No Matches
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
29{
31 static constexpr const tChar *const MetaTypeName = "adtf/plaintype";
58 static constexpr const tChar *const PlainTypeProperty = "c-type";
59
64 {
66 }
67
78 const adtf::streaming::IStreamType& oTypeExpected)
79 {
81 RETURN_IF_FAILED(oTypeToCheck.GetConfig(pCheckProperties));
83 RETURN_IF_FAILED(oTypeExpected.GetConfig(pExpectedProperties));
84
85 auto strCheckPlainType = adtf::base::get_property<adtf_util::cString>(*pCheckProperties, PlainTypeProperty);
86 auto strExpectedPlainType = adtf::base::get_property<adtf_util::cString>(*pExpectedProperties, PlainTypeProperty);
87
88 if (strCheckPlainType != strExpectedPlainType)
89 {
90 RETURN_ERROR_DESC(ERR_FAILED,
91 "The destination plain type '%s' differs from the source plain type '%s'",
92 strCheckPlainType.GetPtr(),
93 strExpectedPlainType.GetPtr());
94 }
95
97 }
98};
99
109template <typename T>
111{
112 static_assert(base::penguin::detail::always_false<T>, "Invalid type for stream_type_plain<T> used! "
113 "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");
114};
115
122#define ADTF_DEFINE_STREAM_TYPE_PLAIN_FOR( _thetype_ , _propval_ ) \
123template <> \
124class stream_type_plain<_thetype_> : public cStreamType \
125{ \
126public: \
127 static constexpr const char *const PlainTypeValue = _propval_; \
128 static constexpr const char* const PlainTypeName = #_thetype_; \
129 stream_type_plain() : cStreamType(stream_meta_type_plain()) \
130 { \
131 adtf::ucom::object_ptr<adtf::base::ant::IProperties> pProperties; \
132 THROW_IF_FAILED(GetConfig(pProperties)); \
133 pProperties->SetProperty(adtf::base::property<adtf_util::cString>(stream_meta_type_plain::PlainTypeProperty, PlainTypeValue)); \
134 pProperties->SetProperty(adtf::base::property<adtf_util::cString>("md_definitions",\
135 adtf_util::cString::Format(R"(<struct name=")" _propval_ R"(" alignment="1" version="1">)" \
136 R"(<element name="value" arraysize="1" type=")" #_thetype_ R"(">)" \
137 R"(<deserialized alignment="1"/>)" \
138 R"(<serialized bytepos="0" byteorder="%s"/>)" \
139 "</element>" \
140 "</struct>", \
141 PLATFORM_BYTEORDER == PLATFORM_BIG_ENDIAN_8 ? "BE" : "LE"))); \
142 pProperties->SetProperty(adtf::base::property<adtf_util::cString>("md_struct", _propval_));\
143 } \
144}
145
150
191
192} //namespace ant
193
194namespace lucky
195{
203template<typename T>
204ADTF3_DEPRECATED("Use adtf::ucom::make_object_ptr<stream_type_plain<T>>() instead.")
209}
210
211namespace penguin
212{
220{
228 static constexpr const char* const ArraySize = "array_size";
229
235 static constexpr const char* const DataEndianess = "data_endianess";
240 {
242 pProperties->SetProperty(adtf::base::property<size_t>(ArraySize, 1));
243 const auto ui8CurrentPlatformOrder = PLATFORM_BYTEORDER;
244 if (ui8CurrentPlatformOrder != PLATFORM_LITTLE_ENDIAN_8)
245 {
246 pProperties->SetProperty(adtf::base::property<uint8_t>(DataEndianess, ui8CurrentPlatformOrder));
247 }
248 }
249
262 const adtf::streaming::IStreamType& oTypeExpected)
263 {
265 RETURN_IF_FAILED(oTypeToCheck.GetConfig(pCheckProperties));
267 RETURN_IF_FAILED(oTypeExpected.GetConfig(pExpectedProperties));
268
269 const auto strCheckPlainType = adtf::base::get_property<adtf_util::cString>(*pCheckProperties, PlainTypeProperty);
270 const auto strExpectedPlainType = adtf::base::get_property<adtf_util::cString>(*pExpectedProperties, PlainTypeProperty);
271
272 if (strCheckPlainType != strExpectedPlainType)
273 {
274 RETURN_ERROR_DESC(ERR_FAILED,
275 "The checked plain type '%s' differs from the expected plain type '%s'",
276 strCheckPlainType.GetPtr(),
277 strExpectedPlainType.GetPtr());
278 }
279 const auto uiCheckDataEndianess = adtf::base::get_property<uint8_t>(*pCheckProperties, DataEndianess, PLATFORM_LITTLE_ENDIAN_8);
280 const auto uiExpectedDataEndianess
281 = adtf::base::get_property<uint8_t>(*pExpectedProperties, DataEndianess, PLATFORM_LITTLE_ENDIAN_8);
282 if (uiCheckDataEndianess != uiExpectedDataEndianess)
283 {
284 if (strCheckPlainType != "UINT8" && strCheckPlainType != "INT8" && strCheckPlainType != "BOOL" && strCheckPlainType != "UINT8_ARRAY" && strCheckPlainType != "INT8_ARRAY" && strCheckPlainType != "BOOL_ARRAY")
285 {
286 RETURN_ERROR_DESC(ERR_FAILED,
287 "The checked plain type '%s' differs from the expected plain type '%s' in endianess",
288 strCheckPlainType.GetPtr(),
289 strExpectedPlainType.GetPtr());
290 }
291 }
292
293 const auto uiCheckArraySize = adtf::base::get_property<size_t>(*pCheckProperties, ArraySize, 1);
294 const auto uiExpectedArraySize = adtf::base::get_property<size_t>(*pExpectedProperties, ArraySize, 1);
295 if (uiCheckArraySize < uiExpectedArraySize)
296 {
298 ERR_FAILED,
299 "The checked plain type '%s' array size (%zu) is lower than the expected plain type '%s' array size (%zu)",
300 strCheckPlainType.GetPtr(), uiCheckArraySize, strExpectedPlainType.GetPtr(), uiExpectedArraySize);
301 }
302
304 }
305};
306
313template<typename T>
315{
316public:
320 {
324 const auto ui8CurrentPlatformOrder = PLATFORM_BYTEORDER;
325 if (ui8CurrentPlatformOrder != PLATFORM_LITTLE_ENDIAN_8)
326 {
327 pProperties->SetProperty(
329 }
330 }
331};
332
340template<typename ValueType, size_t szArraySize, template<typename, size_t> class T>
341class stream_type_plain<T<ValueType, szArraySize>> : public cStreamType
342{
343 static_assert(std::is_arithmetic_v<typename T<ValueType, szArraySize>::value_type>,
344 "std::array can only be used for arithmetic types");
345
346public:
349 {
351 THROW_IF_FAILED(GetConfig(pProperties));
352
353 const adtf_util::cString strPropValue = adtf_util::cString::Format(
354 "%s_ARRAY", ant::stream_type_plain<typename T<ValueType, szArraySize>::value_type>::PlainTypeValue);
355 const adtf_util::cString strPropTypeName(ant::stream_type_plain<typename T<ValueType, szArraySize>::value_type>::PlainTypeName);
357 pProperties->SetProperty(adtf::base::property<size_t>(stream_meta_type_plain::ArraySize, szArraySize));
358
359 // prepare for ddl usage
360 const adtf_util::cString strMDDefValue = adtf_util::cString::Format(R"(<struct name="%s" alignment="1" version="1">
361 <element name="value" arraysize="%zu" type="%s">
362 <deserialized alignment="1"/>
363 <serialized bytepos="0" byteorder="%s"/>
364 </element>
365</struct>)", strPropValue.GetPtr(), szArraySize,
366 strPropTypeName.GetPtr(),
367 PLATFORM_BYTEORDER == PLATFORM_BIG_ENDIAN_8 ? "BE" : "LE");
368 pProperties->SetProperty(adtf::base::property<adtf_util::cString>("md_definitions",
369 strMDDefValue));
370 pProperties->SetProperty(adtf::base::property<adtf_util::cString>("md_struct", strPropValue));
371
372 }
373};
374
381template<class ValueType, size_t szArraySize>
382class stream_type_plain<ValueType[szArraySize]> : public stream_type_plain<std::array<ValueType, szArraySize>>
383{
384};
385
392template<typename T>
393ADTF3_DEPRECATED("Use adtf::ucom::make_object_ptr<stream_type_plain<T>>() instead.")
398
399} // namespace penguin
400
402using penguin::stream_meta_type_plain;
403
405using penguin::stream_type_plain;
406
409
410} //namespace streaming
411} //namespace adtf
#define ADTF3_DEPRECATED(_depr_message_)
Definition adtf_base_deprecated.h:27
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:736
#define RETURN_ERROR_DESC(_code,...)
Same as RETURN_ERROR(_error) using a printf like parameter list for detailed error description.
Definition result.h:44
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Definition result.h:29
#define THROW_IF_FAILED(s)
throws if the expression returns a failed tResult
Definition result.h:88
Definition properties_v2.h:283
Defines access methods for the interface of a Stream Type.
Definition streamtype_intf.h:96
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 ant::IStreamType class for ant::stream_meta_type_plain ...
Definition streammetatypeplain.h:111
stream_type_plain()
CTOR.
Definition streammetatypeplain.h:318
Definition object_ptr.h:384
constexpr bool always_false
helper template to get a always false expression.
Definition adtf_base_type_traits.h:23
VALUETYPE get_property(const IConfiguration &oConfiguration, const char *strNameOfValue, VALUETYPE oDefaultValue)
Get the property content converted to the VALUETYPE.
Definition configuration.h:291
Namespace for all functionality of the ADTF Streaming SDK provided since v3.0.
Definition bindingproxyoutport.h:16
Namespace for all functionality of the ADTF Streaming SDK provided since v3.11.
Definition streammetatypeaudio.h:76
ucom::ant::object_ptr< ant::IStreamType > create_adtf_plain_stream_type()
Definition streammetatypeplain.h:205
ucom::ant::object_ptr< ant::IStreamType > create_adtf_plain_stream_type()
Definition streammetatypeplain.h:394
Namespace for the ADTF Streaming SDK.
Definition bindingproxyinport.h:14
object_ptr< Implementation > make_object_ptr(Args &&... args)
Create an instance of type object_ptr with Implementation as the shared resource.
Definition object_ptr_utilities.h:129
Namespace for the ADTF uCOM SDK.
Definition adtf_system.h:324
ant::iobject_ptr< T > iobject_ptr
Alias always bringing the latest version of ant::iobject_ptr into scope.
Definition object_ptr_intf.h:437
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14
#define ADTF_DEFINE_STREAM_TYPE_PLAIN_FOR(_thetype_, _propval_)
Definition streammetatypeplain.h:122
Use this Stream Meta Type if your sample data will be any of this type: bool, uint8_t,...
Definition streammetatypeplain.h:29
static constexpr const tChar *const MetaTypeName
StreamMetaTypeName for plaintype.
Definition streammetatypeplain.h:31
static void SetProperties(const adtf::ucom::iobject_ptr< adtf::base::IProperties > &pProperties)
Definition streammetatypeplain.h:63
static tResult IsCompatible(const adtf::streaming::IStreamType &oTypeToCheck, const adtf::streaming::IStreamType &oTypeExpected)
Compares the oTypeExpected Stream Type with the oTypeToCheck.
Definition streammetatypeplain.h:77
static constexpr const tChar *const PlainTypeProperty
c-type Property for plaintype Stream Meta Type
Definition streammetatypeplain.h:58
Use this Stream Meta Type if your sample data will be any of this type: bool, uint8_t,...
Definition streammetatypeplain.h:220
static constexpr const char *const ArraySize
Array size for the used type.
Definition streammetatypeplain.h:228
static constexpr const char *const DataEndianess
Identify the endianess of the content. This is relevant for all value types greater than 1 byte.
Definition streammetatypeplain.h:235
static tResult IsCompatible(const adtf::streaming::IStreamType &oTypeToCheck, const adtf::streaming::IStreamType &oTypeExpected)
Compares the oTypeExpected Stream Type with the oTypeToCheck.
Definition streammetatypeplain.h:261
static void SetProperties(const adtf::ucom::iobject_ptr< adtf::base::IProperties > &pProperties)
Definition streammetatypeplain.h:239