ADTF  3.16.2
string_intf.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include <adtf_utils.h>
9 #include <string>
10 
11 #include "adtf_base_type_traits.h"
12 
13 namespace adtf
14 {
15 namespace base
16 {
17 namespace ant
18 {
25  class IString
26  {
27  public:
29  static constexpr size_t InvalidPos = g_npos;
37  virtual tResult Set(const char* strValue) = 0;
43  virtual const char* Get() const = 0;
51  virtual size_t GetLength() const = 0;
52  };
53 
61  template <typename T>
63  {
70  inline static const char* GetConstChar(const T* const pValue)
71  {
72  static_assert(penguin::detail::always_false<T>,
73  "Unsupported type T! See documentation which types are supported."
74  "adtf_string<T> only supports std::string and adtf_util::cString types unless you specialize the adtf_string_forward<T> for the type T!");
75  return nullptr;
76  }
82  inline static size_t GetCurrentLength(const T* const pValue)
83  {
84  static_assert(penguin::detail::always_false<T>,
85  "Unsupported type T! See documentation which types are supported."
86  "adtf_string<T> only supports std::string and adtf_util::cString types unless you specialize the adtf_string_forward<T> for the type T!");
87 
88  return size_t(0);
89  }
99  inline static tResult SetValue(T* const pValue, const char* strValue)
100  {
101  static_assert(penguin::detail::always_false<T>,
102  "Unsupported type T! See documentation which types are supported."
103  "adtf_string<T> only supports std::string and adtf_util::cString types unless you specialize the adtf_string_forward<T> for the type T!");
104  return ERR_NOT_IMPL;
105  }
106  };
107 
111  template<>
112  struct adtf_string_forward<std::string>
113  {
115  static const char* GetConstChar(const std::string* const pValue)
116  {
117  return pValue->c_str();
118  }
120  static size_t GetCurrentLength(const std::string* const pValue)
121  {
122  return static_cast<size_t>(pValue->length());
123  }
125  static tResult SetValue(std::string* const pValue, const char* strValue)
126  {
127  pValue->assign(strValue);
129  }
130  };
131 
135  template <>
137  {
138  static const char * GetConstChar(const adtf_util::cString* const pValue)
139  {
140  return pValue->GetPtr();
141  }
142  static size_t GetCurrentLength(const adtf_util::cString* const pValue)
143  {
144  return static_cast<size_t>(pValue->GetLength());
145  }
146  static tResult SetValue(adtf_util::cString* const pValue, const char* strValue)
147  {
148  pValue->Set(strValue);
150  }
151  };
152 
157  template <>
158  struct adtf_string_forward<adtf::util::cFilename>: public adtf_string_forward<adtf::util::cString>
159  {
160  };
161 
165  template <>
166  struct adtf_string_forward < const char >
167  {
168  static const char* GetConstChar(const char* const pValue)
169  {
170  return pValue;
171  }
172  static size_t GetCurrentLength(const char* const pValue)
173  {
174  return static_cast<size_t>(adtf_util::cStringUtil::GetLength(pValue));
175  }
176  static tResult SetValue(const char* const /* pValue */, const char* /* strValue */)
177  {
178  RETURN_ERROR(ERR_ACCESS_DENIED);
179  }
180  };
181 
191  template <typename T>
192  class adtf_string : public IString,
193  protected adtf_string_forward<T>
194  {
198  typedef T value_type;
201 
202  private:
206  adtf_string() = delete;
209  adtf_string(const adtf_string& strValue) = delete;
212  adtf_string(adtf_string&& strValue) = delete;
216  adtf_string& operator=(const adtf_string& strValue) = delete;
220  adtf_string& operator=(adtf_string&& strValue) = delete;
221  public:
224  explicit adtf_string(value_type* pstrAssignValue)
225  {
226  m_pAssignValue = pstrAssignValue;
227  }
230  {
231  m_pAssignValue = nullptr;
232  }
233  tResult Set(const char* strValue) override
234  {
235  if (strValue != nullptr)
236  {
237  return base_type::SetValue(m_pAssignValue, strValue);
238  }
239  else
240  {
241  RETURN_ERROR(ERR_POINTER);
242  }
243  }
244  const char* Get() const override
245  {
246  const tChar* strValue = "";
247  if (m_pAssignValue != nullptr)
248  {
250  }
251  return strValue;
252  }
253  size_t GetLength() const override
254  {
255  if (m_pAssignValue != nullptr)
256  {
258  }
259  return IString::InvalidPos;
260  }
261  };
262 } //namespace ant
263 
264 using ant::adtf_string_forward;
265 using ant::adtf_string;
267 using ant::IString;
268 
269 } //namespace base
270 } // namespace adtf
271 
303 #define adtf_string_intf( __string__) ::adtf::base::adtf_string<typename std::remove_reference<decltype(__string__)>::type>(& (__string__))
304 
307 #define adtf_char_intf( __const_char_ptr__) ::adtf::base::adtf_string<const char>(__const_char_ptr__)
Copyright © Audi Electronics Venture GmbH.
A common result class usable as return value throughout.
The IString interface provides methods for getting and setting strings through abstract interfaces.
Definition: string_intf.h:26
virtual const char * Get() const =0
Gets the pointer to the current associated nullterminated-string.
static constexpr size_t InvalidPos
Invalid Position size.
Definition: string_intf.h:29
virtual size_t GetLength() const =0
Gets the current size of the strng.
virtual tResult Set(const char *strValue)=0
Sets the given null-terminated string to the implementation.
Wrapping template for a rvalue reference of an IString interface for the type T (see Supported types ...
Definition: string_intf.h:194
tResult Set(const char *strValue) override
Sets the given null-terminated string to the implementation.
Definition: string_intf.h:233
adtf_string(adtf_string &&strValue)=delete
move CTOR
adtf_string(value_type *pstrAssignValue)
CTOR with pointer to the value of value_type.
Definition: string_intf.h:224
value_type * m_pAssignValue
pointer to the value
Definition: string_intf.h:204
adtf_string(const adtf_string &strValue)=delete
copy CTOR
adtf_string< T > self_type
self type
Definition: string_intf.h:196
size_t GetLength() const override
Gets the current size of the strng.
Definition: string_intf.h:253
adtf_string & operator=(const adtf_string &strValue)=delete
copy operator
adtf_string_forward< T > base_type
base type
Definition: string_intf.h:200
const char * Get() const override
Gets the pointer to the current associated nullterminated-string.
Definition: string_intf.h:244
adtf_string & operator=(adtf_string &&strValue)=delete
move operator
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:2772
Namespace for entire ADTF SDK.
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
#define RETURN_ERROR(code)
Return specific error code, which requires the calling function's return type to be tResult.
char tChar
The tChar defines the type for platform character set (platform and compiler dependent type).
constexpr tSize g_npos
npos size declaration
static tResult SetValue(std::string *const pValue, const char *strValue)
Sets the given strValue to the string type implementation of the given pValue.
Definition: string_intf.h:125
static size_t GetCurrentLength(const std::string *const pValue)
Retrieves the string size of the given pValue.
Definition: string_intf.h:120
static const char * GetConstChar(const std::string *const pValue)
Retrieves a const char pointer (null-terminated).
Definition: string_intf.h:115
Implementation concept template for user defined adtf_string type support (see Supported types for ad...
Definition: string_intf.h:63
static const char * GetConstChar(const T *const pValue)
Retrieves a const char pointer (null-terminated).
Definition: string_intf.h:70
static size_t GetCurrentLength(const T *const pValue)
Retrieves the string size of the given pValue.
Definition: string_intf.h:82
static tResult SetValue(T *const pValue, const char *strValue)
Sets the given strValue to the string type implementation of the given pValue.
Definition: string_intf.h:99