ADTF  3.18.3
streammetatypestring.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 <cinttypes>
14 
15 namespace adtf
16 {
17 namespace streaming
18 {
19 namespace penguin
20 {
21 
32 {
34  static constexpr const tChar* const MetaTypeName = "adtf/string";
35 
40  static constexpr const tChar* const DataEndianess = "data_endianess";
41 
45  enum class EncodingType
46  {
50  unknown = 0,
55  unspecified = 1,
61  c_char = 2,
65  utf8 = 3,
70  w_char = 4,
74  w_char_16 = w_char,
78  utf16 = 5
79  };
89  static constexpr const tChar* const Encoding = "encoding";
91  static constexpr const tChar* const EncodingValueUnspecified = "unspecified";
93  static constexpr const tChar* const EncodingValueCChar = "c-char";
95  static constexpr const tChar* const EncodingValueUTF8 = "utf8";
97  static constexpr const tChar* const EncodingValueWChar = "w-char";
99  static constexpr const tChar* const EncodingValueUTF16 = "utf16";
100 
105  {
108  }
109 
116  {
118  THROW_IF_FAILED(pStreamType.GetConfig(pProperties));
119  if (pProperties)
120  {
121  return adtf::base::get_property<adtf_util::cString>(*pProperties, Encoding);
122  }
123  else
124  {
125  THROW_ERROR_DESC(ERR_NOT_FOUND, "StreamType has no properties");
126  }
127  }
133  static void SetEncoding(adtf::streaming::IStreamType& pStreamType, const char* strEncodingType)
134  {
136  THROW_IF_FAILED(pStreamType.GetConfig(pProperties));
137  if (pProperties)
138  {
139  THROW_IF_FAILED(adtf::base::set_property<adtf_util::cString>(*pProperties, Encoding, strEncodingType));
140  }
141  else
142  {
143  THROW_ERROR_DESC(ERR_NOT_FOUND, "StreamType has no properties");
144  }
145  }
146 
153  {
154  auto oEncodingType = GetEncoding(pStreamType);
155  if (oEncodingType == EncodingValueCChar)
156  {
157  return EncodingType::c_char;
158  }
159  else if (oEncodingType == EncodingValueUnspecified)
160  {
162  }
163  else if (oEncodingType == EncodingValueUTF8)
164  {
165  return EncodingType::utf8;
166  }
167  else if (oEncodingType == EncodingValueWChar)
168  {
170  }
171  else if (oEncodingType == EncodingValueUTF16)
172  {
173  return EncodingType::utf16;
174  }
175  else
176  {
177  return EncodingType::unknown;
178  }
179  }
185  static void SetEncodingType(adtf::streaming::IStreamType& pStreamType, EncodingType eEncodingType)
186  {
187  switch (eEncodingType)
188  {
190  {
191  THROW_ERROR_DESC(ERR_INVALID_ARG, "EncodingType::unknown can not be set");
192  }
193  break;
195  {
196  SetEncoding(pStreamType, EncodingValueCChar);
197  }
198  break;
199  case EncodingType::utf8:
200  {
201  SetEncoding(pStreamType, EncodingValueUTF8);
202  }
203  break;
205  {
206  SetEncoding(pStreamType, EncodingValueWChar);
207  }
208  break;
209  case EncodingType::utf16:
210  {
211  SetEncoding(pStreamType, EncodingValueUTF16);
212  }
213  break;
215  {
217  }
218  break;
219  }
220  }
221 
242  const adtf::streaming::IStreamType& oTypeExpected)
243  {
245  RETURN_IF_FAILED(oTypeToCheck.GetConfig(pCheckProperties));
247  RETURN_IF_FAILED(oTypeExpected.GetConfig(pExpectedProperties));
248 
249  auto strCheckEncoding = adtf::base::get_property<adtf_util::cString>(*pCheckProperties, Encoding);
250  auto strExpectedEncoding = adtf::base::get_property<adtf_util::cString>(*pExpectedProperties, Encoding);
251  if (strExpectedEncoding != EncodingValueUnspecified && strCheckEncoding != strExpectedEncoding)
252  {
253  RETURN_ERROR_DESC(ERR_FAILED,
254  "The destination stream type string Encoding expects '%s' but '%s' was found!",
255  strCheckEncoding.GetPtr(), strExpectedEncoding.GetPtr());
256  }
257  if (strExpectedEncoding != EncodingValueUnspecified && strCheckEncoding != EncodingValueUTF8
258  && strCheckEncoding != EncodingValueCChar)
259  {
260  const auto nByteOrderCheck
261  = adtf::base::get_property<uint8_t>(*pCheckProperties, DataEndianess, PLATFORM_LITTLE_ENDIAN_8);
262  const auto nByteOrderExpected
263  = adtf::base::get_property<uint8_t>(*pExpectedProperties, DataEndianess, PLATFORM_LITTLE_ENDIAN_8);
264  if (nByteOrderCheck != nByteOrderExpected)
265  {
266  RETURN_ERROR_DESC(ERR_FAILED,
267  "The destination stream type string byte order expects '%" PRIu8 "' but '%" PRIu8 "' was found!",
268  nByteOrderCheck, nByteOrderExpected);
269  }
270  }
272  }
273 };
274 
286 template<typename T>
288 {
289 public:
300  {
301  static_assert(base::penguin::detail::always_false<T>,
302  "Invalid type for stream_type_string<T> used!"
303  "Use supported std::string or std::u16string only");
304  }
305 };
306 
307 template<>
308 class stream_type_string<std::string> : public cStreamType
309 {
310 public:
313  {
315  GetConfig(pProperties);
316  if (pProperties)
317  {
319  }
320  }
321 };
322 
323 template<>
324 class
325 ADTF3_DEPRECATED("std::wstring can only be used if value type is guaranteed for 16Bit encodings. Use "
326  "stream_type_string<std::u16string> instead!")
327 stream_type_string<std::wstring> : public cStreamType
328 {
329 public:
332  {
334  GetConfig(pProperties);
335  if (pProperties)
336  {
338  }
339  }
340 };
341 
342 template<>
343 class stream_type_string<std::u16string> : public cStreamType
344 {
345 public:
348  {
350  GetConfig(pProperties);
351  if (pProperties)
352  {
354  }
355  }
356 };
357 }
358 
361 
364 
365 } //namespace streaming
366 } //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.
char tChar
The tChar defines the type for platform character set (platform and compiler dependent 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 penguin::stream_meta_type_st...
stream_type_string(stream_meta_type_string::EncodingType eEncoding)
Construct a new stream type string object for the "adtf/string" meta type.
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_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
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: std::string,...
static void SetEncoding(adtf::streaming::IStreamType &pStreamType, const char *strEncodingType)
Set the Encoding type as string.
static constexpr const tChar *const EncodingValueCChar
Valid value for Encoding property.
static constexpr const tChar *const EncodingValueUTF8
Valid value for Encoding property.
static EncodingType GetEncodingType(const adtf::streaming::IStreamType &pStreamType)
Get the Encoding Type as part of the enumeration EncodingType.
static constexpr const tChar *const Encoding
encoding Property for string Stream Meta Type
static constexpr const tChar *const DataEndianess
Name for the Property of the data endianess (only necessary for encoding types greater that 8 Bit).
@ w_char
for plain char16_t (16bit) used in c++ programs, where no special encoding information is used (usual...
@ c_char
for plain char (8bit) used in c++ programs, where no special encoding information is used (usually US...
@ unspecified
any type means: for unspecified encodings, where i.e the receiver will determine the encoding while s...
static constexpr const tChar *const EncodingValueUnspecified
Valid value for Encoding property.
static void SetProperties(const adtf::ucom::iobject_ptr< adtf::base::IProperties > &pProperties)
Property setter for plaintype.
static adtf_util::cString GetEncoding(const adtf::streaming::IStreamType &pStreamType)
Get the Encoding Type as string.
static constexpr const tChar *const EncodingValueUTF16
Valid value for Encoding property.
static constexpr const tChar *const EncodingValueWChar
Valid value for Encoding property.
static constexpr const tChar *const MetaTypeName
StreamMetaTypeName for string.
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 ...
static void SetEncodingType(adtf::streaming::IStreamType &pStreamType, EncodingType eEncodingType)
Set the Encoding Type by given eEncodingType enumeration value.
#define THROW_ERROR_DESC(_code,...)
throws a tResult exception
#define THROW_IF_FAILED(s)
throws if the expression returns a failed tResult