ADTF  3.14.3
string_intf.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include <adtf_utils.h>
9 #include <string>
10 
11 namespace adtf
12 {
13 namespace base
14 {
15 namespace ant
16 {
23  class IString
24  {
25  public:
27  static constexpr size_t InvalidPos = g_npos;
35  virtual tResult Set(const char* strValue) = 0;
41  virtual const char* Get() const = 0;
49  virtual size_t GetLength() const = 0;
50  };
51 
58  template <typename T>
60  {
67  inline static const char* GetConstChar(const T* const pValue);
73  inline static size_t GetCurrentLength(const T* const pValue);
83  inline static tResult SetValue(T* const pValue, const char* strValue);
84  };
85 
90  template<>
91  struct adtf_string_forward<std::string>
92  {
94  static const char* GetConstChar(const std::string* const pValue)
95  {
96  return pValue->c_str();
97  }
99  static size_t GetCurrentLength(const std::string* const pValue)
100  {
101  return static_cast<size_t>(pValue->length());
102  }
104  static tResult SetValue(std::string* const pValue, const char* strValue)
105  {
106  pValue->assign(strValue);
107  RETURN_NOERROR;
108  }
109  };
110 
115  template <>
116  struct adtf_string_forward<adtf::util::cString>
117  {
118  static const char * GetConstChar(const adtf_util::cString* const pValue)
119  {
120  return pValue->GetPtr();
121  }
122  static size_t GetCurrentLength(const adtf_util::cString* const pValue)
123  {
124  return static_cast<size_t>(pValue->GetLength());
125  }
126  static tResult SetValue(adtf_util::cString* const pValue, const char* strValue)
127  {
128  pValue->Set(strValue);
129  RETURN_NOERROR;
130  }
131  };
132 
137  template <>
138  struct adtf_string_forward<adtf::util::cFilename>: public adtf_string_forward<adtf::util::cString>
139  {
140  };
141 
146  template <>
147  struct adtf_string_forward < const char >
148  {
149  static const char* GetConstChar(const char* const pValue)
150  {
151  return pValue;
152  }
153  static size_t GetCurrentLength(const char* const pValue)
154  {
155  return static_cast<size_t>(adtf_util::cStringUtil::GetLength(pValue));
156  }
157  static tResult SetValue(const char* const /* pValue */, const char* /* strValue */)
158  {
159  RETURN_ERROR(ERR_ACCESS_DENIED);
160  }
161  };
162 
173  template <typename T>
174  class adtf_string : public IString,
175  protected adtf_string_forward<T>
176  {
180  typedef T value_type;
183 
184  private:
188  adtf_string() = delete;
191  adtf_string(const adtf_string& strValue) = delete;
194  adtf_string(adtf_string&& strValue) = delete;
198  adtf_string& operator=(const adtf_string& strValue) = delete;
202  adtf_string& operator=(adtf_string&& strValue) = delete;
203  public:
206  explicit adtf_string(value_type* pstrAssignValue)
207  {
208  m_pAssignValue = pstrAssignValue;
209  }
212  {
213  m_pAssignValue = nullptr;
214  }
215  tResult Set(const char* strValue) override
216  {
217  if (strValue != nullptr)
218  {
219  return base_type::SetValue(m_pAssignValue, strValue);
220  }
221  else
222  {
223  RETURN_ERROR(ERR_POINTER);
224  }
225  }
226  const char* Get() const override
227  {
228  const tChar* strValue = "";
229  if (m_pAssignValue != nullptr)
230  {
232  }
233  return strValue;
234  }
235  size_t GetLength() const override
236  {
237  if (m_pAssignValue != nullptr)
238  {
240  }
241  return IString::InvalidPos;
242  }
243  };
244 } //namespace ant
245 
246 using ant::adtf_string_forward;
247 using ant::adtf_string;
249 using ant::IString;
250 
251 } //namespace base
252 } // namespace adtf
253 
285 #define adtf_string_intf( __string__) ::adtf::base::adtf_string<typename std::remove_reference<decltype(__string__)>::type>(& (__string__))
286 
289 #define adtf_char_intf( __const_char_ptr__) ::adtf::base::adtf_string<const char>(__const_char_ptr__)
Copyright © Audi Electronics Venture GmbH.
The IString interface provides methods for getting and setting strings through abstract interfaces.
Definition: string_intf.h:24
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:27
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.
Definition: string_intf.h:176
tResult Set(const char *strValue) override
Sets the given null-terminated string to the implementation.
Definition: string_intf.h:215
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:206
value_type * m_pAssignValue
pointer to the value
Definition: string_intf.h:186
adtf_string(const adtf_string &strValue)=delete
copy CTOR
adtf_string< T > self_type
self type
Definition: string_intf.h:178
size_t GetLength() const override
Gets the current size of the strng.
Definition: string_intf.h:235
adtf_string & operator=(const adtf_string &strValue)=delete
copy operator
adtf_string_forward< T > base_type
base type
Definition: string_intf.h:182
const char * Get() const override
Gets the pointer to the current associated nullterminated-string.
Definition: string_intf.h:226
adtf_string & operator=(adtf_string &&strValue)=delete
move operator
Namespace for entire ADTF SDK.
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:104
static size_t GetCurrentLength(const std::string *const pValue)
Retrieves the string size of the given pValue.
Definition: string_intf.h:99
static const char * GetConstChar(const std::string *const pValue)
Retrieves a const char pointer (null-terminated).
Definition: string_intf.h:94
Implementation concept template ehich defines the layout of a forward string class.
Definition: string_intf.h:60
static const char * GetConstChar(const T *const pValue)
Retrieves a const char pointer (null-terminated).
static size_t GetCurrentLength(const T *const pValue)
Retrieves the string size of the given pValue.
static tResult SetValue(T *const pValue, const char *strValue)
Sets the given strValue to the string type implementation of the given pValue.

Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Thu Jun 9 2022 by doxygen 1.9.1)