ADTF
Loading...
Searching...
No Matches
streammetatypestring.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 <cinttypes>
14
15namespace adtf
16{
17namespace streaming
18{
19namespace penguin
20{
21
29{
31 static constexpr const char* const MetaTypeName = "adtf/string";
32
37 static constexpr const char* const DataEndianess = "data_endianess";
38
42 enum class EncodingType
43 {
58 c_char = 2,
62 utf8 = 3,
67 w_char = 4,
76 };
77
86 static constexpr const char* const Encoding = "encoding";
88 static constexpr const char* const EncodingValueUnspecified = "unspecified";
90 static constexpr const char* const EncodingValueCChar = "c-char";
92 static constexpr const char* const EncodingValueUTF8 = "utf8";
94 static constexpr const char* const EncodingValueWChar = "w-char";
96 static constexpr const char* const EncodingValueUTF16 = "utf16";
97
102 {
104 pProperties->SetProperty(adtf::base::property<uint8_t>(DataEndianess, PLATFORM_BYTEORDER));
105 }
106
112 static adtf_util::cString GetEncoding(const adtf::streaming::IStreamType& pStreamType)
113 {
115 THROW_IF_FAILED(pStreamType.GetConfig(pProperties));
116 if (pProperties)
117 {
119 }
120 else
121 {
122 THROW_ERROR_DESC(ERR_NOT_FOUND, "StreamType has no properties");
123 }
124 }
125
130 static void SetEncoding(adtf::streaming::IStreamType& pStreamType, const char* strEncodingType)
131 {
133 THROW_IF_FAILED(pStreamType.GetConfig(pProperties));
134 if (pProperties)
135 {
137 }
138 else
139 {
140 THROW_ERROR_DESC(ERR_NOT_FOUND, "StreamType has no properties");
141 }
142 }
143
150 {
151 auto oEncodingType = GetEncoding(pStreamType);
152 if (oEncodingType == EncodingValueCChar)
153 {
155 }
156 else if (oEncodingType == EncodingValueUnspecified)
157 {
159 }
160 else if (oEncodingType == EncodingValueUTF8)
161 {
162 return EncodingType::utf8;
163 }
164 else if (oEncodingType == EncodingValueWChar)
165 {
167 }
168 else if (oEncodingType == EncodingValueUTF16)
169 {
170 return EncodingType::utf16;
171 }
172 else
173 {
175 }
176 }
177
182 static void SetEncodingType(adtf::streaming::IStreamType& pStreamType, EncodingType eEncodingType)
183 {
184 switch (eEncodingType)
185 {
187 {
188 THROW_ERROR_DESC(ERR_INVALID_ARG, "EncodingType::unknown can not be set");
189 }
190 break;
192 {
193 SetEncoding(pStreamType, EncodingValueCChar);
194 }
195 break;
197 {
198 SetEncoding(pStreamType, EncodingValueUTF8);
199 }
200 break;
202 {
203 SetEncoding(pStreamType, EncodingValueWChar);
204 }
205 break;
207 {
208 SetEncoding(pStreamType, EncodingValueUTF16);
209 }
210 break;
212 {
214 }
215 break;
216 }
217 }
218
233 const adtf::streaming::IStreamType& oTypeExpected)
234 {
236 RETURN_IF_FAILED(oTypeToCheck.GetConfig(pCheckProperties));
238 RETURN_IF_FAILED(oTypeExpected.GetConfig(pExpectedProperties));
239
240 auto strCheckEncoding = adtf::base::get_property<adtf_util::cString>(*pCheckProperties, Encoding);
241 auto strExpectedEncoding = adtf::base::get_property<adtf_util::cString>(*pExpectedProperties, Encoding);
242 if (strExpectedEncoding != EncodingValueUnspecified && strCheckEncoding != strExpectedEncoding)
243 {
244 RETURN_ERROR_DESC(ERR_FAILED,
245 "The destination stream type string Encoding expects '%s' but '%s' was found!",
246 strCheckEncoding.GetPtr(), strExpectedEncoding.GetPtr());
247 }
248 if (strExpectedEncoding != EncodingValueUnspecified && strCheckEncoding != EncodingValueUTF8
249 && strCheckEncoding != EncodingValueCChar)
250 {
251 const auto nByteOrderCheck
252 = adtf::base::get_property<uint8_t>(*pCheckProperties, DataEndianess, PLATFORM_LITTLE_ENDIAN_8);
253 const auto nByteOrderExpected
254 = adtf::base::get_property<uint8_t>(*pExpectedProperties, DataEndianess, PLATFORM_LITTLE_ENDIAN_8);
255 if (nByteOrderCheck != nByteOrderExpected)
256 {
257 RETURN_ERROR_DESC(ERR_FAILED,
258 "The destination stream type string byte order expects '%" PRIu8 "' but '%" PRIu8 "' was found!",
259 nByteOrderCheck, nByteOrderExpected);
260 }
261 }
263 }
264};
265
275template<typename T>
277{
278public:
289 {
291 "Invalid type for stream_type_string<T> used!"
292 "Use supported std::string or std::u16string only");
293 }
294};
295
296template<>
297class stream_type_string<std::string> : public cStreamType
298{
299public:
302 {
304 GetConfig(pProperties);
305 if (pProperties)
306 {
308 }
309 }
310};
311
312template<>
313class
314ADTF3_DEPRECATED("std::wstring can only be used if value type is guaranteed for 16Bit encodings. Use stream_type_string<std::u16string> instead.")
315stream_type_string<std::wstring> : public cStreamType
316{
317public:
320 {
322 GetConfig(pProperties);
323 if (pProperties)
324 {
326 }
327 }
328};
329
330template<>
331class stream_type_string<std::u16string> : public cStreamType
332{
333public:
336 {
338 GetConfig(pProperties);
339 if (pProperties)
340 {
342 }
343 }
344};
345}
346
349
352
353} //namespace streaming
354} //namespace adtf
#define ADTF3_DEPRECATED(_depr_message_)
Definition adtf_base_deprecated.h:27
#define THROW_ERROR_DESC(_code,...)
throws a tResult exception
Definition result.h:85
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 penguin::stream_meta_type_st...
Definition streammetatypestring.h:277
stream_type_string(stream_meta_type_string::EncodingType eEncoding)
Construct a new stream type string object for the "adtf/string" meta type.
Definition streammetatypestring.h:288
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
tResult set_property(IConfiguration &oConfiguration, const char *strNameOfValue, VALUETYPE oValue)
Set the property.
Definition configuration.h:327
Namespace for all functionality of the ADTF Streaming SDK provided since v3.15.
Definition sample_data.h:410
Namespace for the ADTF Streaming SDK.
Definition bindingproxyinport.h:14
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
Use this Stream Meta Type if your sample data will be any of this type: std::string,...
Definition streammetatypestring.h:29
static constexpr const char *const EncodingValueUTF8
Valid value for Encoding property.
Definition streammetatypestring.h:92
static constexpr const char *const EncodingValueUTF16
Valid value for Encoding property.
Definition streammetatypestring.h:96
static constexpr const char *const MetaTypeName
StreamMetaTypeName for string.
Definition streammetatypestring.h:31
static constexpr const char *const EncodingValueWChar
Valid value for Encoding property.
Definition streammetatypestring.h:94
static constexpr const char *const Encoding
encoding Property for string Stream Meta Type
Definition streammetatypestring.h:86
static constexpr const char *const DataEndianess
Name for the Property of the data endianess (only necessary for encoding types greater that 8 Bit).
Definition streammetatypestring.h:37
EncodingType
The supported encoding types.
Definition streammetatypestring.h:43
@ w_char
for plain char16_t (16bit) used in c++ programs, where no special encoding information is used (usual...
Definition streammetatypestring.h:67
@ utf8
utf8
Definition streammetatypestring.h:62
@ w_char_16
for plain char16_t (16bit) used in c++ programs, where no special encoding information is used (usual...
Definition streammetatypestring.h:71
@ utf16
utf16
Definition streammetatypestring.h:75
@ c_char
for plain char (8bit) used in c++ programs, where no special encoding information is used (usually US...
Definition streammetatypestring.h:58
@ unknown
unknown type
Definition streammetatypestring.h:47
@ unspecified
any type means: for unspecified encodings, where i.e the receiver will determine the encoding while s...
Definition streammetatypestring.h:52
static adtf_util::cString GetEncoding(const adtf::streaming::IStreamType &pStreamType)
Get the Encoding Type as string.
Definition streammetatypestring.h:112
static constexpr const char *const EncodingValueUnspecified
Valid value for Encoding property.
Definition streammetatypestring.h:88
static EncodingType GetEncodingType(const adtf::streaming::IStreamType &pStreamType)
Get the Encoding Type as part of the enumeration EncodingType.
Definition streammetatypestring.h:149
static void SetEncodingType(adtf::streaming::IStreamType &pStreamType, EncodingType eEncodingType)
Set the Encoding Type by given eEncodingType enumeration value.
Definition streammetatypestring.h:182
static void SetProperties(const adtf::ucom::iobject_ptr< adtf::base::IProperties > &pProperties)
Definition streammetatypestring.h:101
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 for a su...
Definition streammetatypestring.h:232
static constexpr const char *const EncodingValueCChar
Valid value for Encoding property.
Definition streammetatypestring.h:90
static void SetEncoding(adtf::streaming::IStreamType &pStreamType, const char *strEncodingType)
Set the Encoding type as string.
Definition streammetatypestring.h:130