ADTF  3.18.2
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 
14 namespace adtf
15 {
16 namespace streaming
17 {
18 namespace penguin
19 {
20 
31 {
33  static constexpr const tChar* const MetaTypeName = "adtf/string";
34 
39  static constexpr const tChar* const DataEndianess = "data_endianess";
40 
44  enum class EncodingType
45  {
49  unknown = 0,
54  unspecified = 1,
60  c_char = 2,
64  utf8 = 3,
69  w_char = 4,
73  w_char_16 = w_char,
77  utf16 = 5
78  };
88  static constexpr const tChar* const Encoding = "encoding";
90  static constexpr const tChar* const EncodingValueUnspecified = "unspecified";
92  static constexpr const tChar* const EncodingValueCChar = "c-char";
94  static constexpr const tChar* const EncodingValueUTF8 = "utf8";
96  static constexpr const tChar* const EncodingValueWChar = "w-char";
98  static constexpr const tChar* const EncodingValueUTF16 = "utf16";
99 
104  {
107  }
108 
115  {
117  THROW_IF_FAILED(pStreamType.GetConfig(pProperties));
118  if (pProperties)
119  {
120  return adtf::base::get_property<adtf_util::cString>(*pProperties, Encoding);
121  }
122  else
123  {
124  THROW_ERROR_DESC(ERR_NOT_FOUND, "StreamType has no properties");
125  }
126  }
132  static void SetEncoding(adtf::streaming::IStreamType& pStreamType, const char* strEncodingType)
133  {
135  THROW_IF_FAILED(pStreamType.GetConfig(pProperties));
136  if (pProperties)
137  {
138  THROW_IF_FAILED(adtf::base::set_property<adtf_util::cString>(*pProperties, Encoding, strEncodingType));
139  }
140  else
141  {
142  THROW_ERROR_DESC(ERR_NOT_FOUND, "StreamType has no properties");
143  }
144  }
145 
152  {
153  auto oEncodingType = GetEncoding(pStreamType);
154  if (oEncodingType == EncodingValueCChar)
155  {
156  return EncodingType::c_char;
157  }
158  else if (oEncodingType == EncodingValueUnspecified)
159  {
161  }
162  else if (oEncodingType == EncodingValueUTF8)
163  {
164  return EncodingType::utf8;
165  }
166  else if (oEncodingType == EncodingValueWChar)
167  {
169  }
170  else if (oEncodingType == EncodingValueUTF16)
171  {
172  return EncodingType::utf16;
173  }
174  else
175  {
176  return EncodingType::unknown;
177  }
178  }
184  static void SetEncodingType(adtf::streaming::IStreamType& pStreamType, EncodingType eEncodingType)
185  {
186  switch (eEncodingType)
187  {
189  {
190  THROW_ERROR_DESC(ERR_INVALID_ARG, "EncodingType::unknown can not be set");
191  }
192  break;
194  {
195  SetEncoding(pStreamType, EncodingValueCChar);
196  }
197  break;
198  case EncodingType::utf8:
199  {
200  SetEncoding(pStreamType, EncodingValueUTF8);
201  }
202  break;
204  {
205  SetEncoding(pStreamType, EncodingValueWChar);
206  }
207  break;
208  case EncodingType::utf16:
209  {
210  SetEncoding(pStreamType, EncodingValueUTF16);
211  }
212  break;
214  {
216  }
217  break;
218  }
219  }
220 
241  const adtf::streaming::IStreamType& oTypeExpected)
242  {
244  RETURN_IF_FAILED(oTypeToCheck.GetConfig(pCheckProperties));
246  RETURN_IF_FAILED(oTypeExpected.GetConfig(pExpectedProperties));
247 
248  auto strCheckEncoding = adtf::base::get_property<adtf_util::cString>(*pCheckProperties, Encoding);
249  auto strExpectedEncoding = adtf::base::get_property<adtf_util::cString>(*pExpectedProperties, Encoding);
250  if (strExpectedEncoding != EncodingValueUnspecified && strCheckEncoding != strExpectedEncoding)
251  {
252  RETURN_ERROR_DESC(ERR_FAILED,
253  "The destination stream type string Encoding expects '%s' but '%s' was found!",
254  strCheckEncoding.GetPtr(), strExpectedEncoding.GetPtr());
255  }
256  if (strExpectedEncoding != EncodingValueUnspecified && strCheckEncoding != EncodingValueUTF8
257  && strCheckEncoding != EncodingValueCChar)
258  {
259  const auto nByteOrderCheck
260  = adtf::base::get_property<uint8_t>(*pCheckProperties, DataEndianess, PLATFORM_LITTLE_ENDIAN_8);
261  const auto nByteOrderExpected
262  = adtf::base::get_property<uint8_t>(*pExpectedProperties, DataEndianess, PLATFORM_LITTLE_ENDIAN_8);
263  if (nByteOrderCheck != nByteOrderExpected)
264  {
265  RETURN_ERROR_DESC(ERR_FAILED,
266  "The destination stream type string byte order expects '%d' but '%d' was found!",
267  nByteOrderCheck, nByteOrderExpected);
268  }
269  }
271  }
272 };
273 
285 template<typename T>
287 {
288 public:
299  {
300  static_assert(base::penguin::detail::always_false<T>,
301  "Invalid type for stream_type_string<T> used!"
302  "Use supported std::string or std::u16string only");
303  }
304 };
305 
306 template<>
307 class stream_type_string<std::string> : public cStreamType
308 {
309 public:
312  {
314  GetConfig(pProperties);
315  if (pProperties)
316  {
318  }
319  }
320 };
321 
322 template<>
323 class
324 ADTF3_DEPRECATED("std::wstring can only be used if value type is guaranteed for 16Bit encodings. Use "
325  "stream_type_string<std::u16string> instead!")
326 stream_type_string<std::wstring> : public cStreamType
327 {
328 public:
331  {
333  GetConfig(pProperties);
334  if (pProperties)
335  {
337  }
338  }
339 };
340 
341 template<>
342 class stream_type_string<std::u16string> : public cStreamType
343 {
344 public:
347  {
349  GetConfig(pProperties);
350  if (pProperties)
351  {
353  }
354  }
355 };
356 }
357 
360 
363 
364 } //namespace streaming
365 } //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