ADTF  3.18.2
rawmemory_base.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include <adtf_utils.h>
9 #include "adtf_base_type_traits.h"
10 
11 namespace adtf
12 {
13 namespace base
14 {
15 namespace ant
16 {
23 {
24 public:
33  virtual tResult Set(const void* pValue, size_t szSize) = 0;
38  virtual size_t GetSize() const = 0;
43  virtual const void* Get() const = 0;
44 };
45 
87 template<typename T>
89 {
101  inline static tResult Assign(T* pAssignValue,
102  const size_t szStaticSize,
103  const void* pValueToSet,
104  const size_t szSizeToSet)
105  {
106  static_assert(penguin::detail::always_false<T>,
107  "Unsupported type T! See documentation which types are supported."
108  "adtf_memory<T> only supports trivial types unless you specialize the adtf_memory_forward<T> for the type T!");
109  return ERR_NOT_IMPL;
110  }
119  inline static const void* GetPtr(const T* pAssignValue)
120  {
121  static_assert(penguin::detail::always_false<T>,
122  "Unsupported type T! See documentation which types are supported."
123  "adtf_memory<T> only supports trivial types unless you specialize the adtf_memory_forward<T> for the type T!");
124  return nullptr;
125  }
134  inline static size_t GetSize(const T* pAssignValue, const size_t szStaticSize)
135  {
136  static_assert(penguin::detail::always_false<T>,
137  "Unsupported type T! See documentation which types are supported."
138  "adtf_memory<T> only supports trivial types unless you specialize the adtf_memory_forward<T> for the type T!");
139  return size_t(0);
140  }
141 };
142 
149 template<typename T, size_t TSIZE = 0>
150 class adtf_memory : public IRawMemory, protected adtf_memory_forward<T>
151 {
153  typedef T _myStorageType;
155 
156 private:
159  adtf_memory() {};
160  adtf_memory(const adtf_memory&) = delete;
161  adtf_memory& operator=(const adtf_memory&) = delete;
162  adtf_memory(adtf_memory&&) = delete;
163  adtf_memory& operator=(adtf_memory&&) = delete;
164 
165 public:
167  explicit adtf_memory(T* pAssignValue)
168  {
169  m_pAssignValue = pAssignValue;
170  }
172  virtual ~adtf_memory()
173  {
174  m_pAssignValue = nullptr;
175  }
176 
177  tResult Set(const void* pValue, size_t szSize)
178  {
179  if (pValue != nullptr)
180  {
181  return _myBase::Assign(m_pAssignValue, TSIZE, pValue, szSize);
182  }
183  else
184  {
185  RETURN_ERROR(ERR_POINTER);
186  }
187  }
188  const void* Get() const
189  {
190  if (m_pAssignValue != nullptr)
191  {
193  }
194  return nullptr;
195  }
196  size_t GetSize() const
197  {
198  if (m_pAssignValue != nullptr)
199  {
200  return _myBase::GetSize(m_pAssignValue, TSIZE);
201  }
202  return size_t(0);
203  }
204 };
205 
206 template<typename T, typename Enable = void>
208  public IRawMemory
209 {
210 private:
211  T* m_pPtr;
212  size_t m_szSize;
213 
214 public:
215  adtf_memory_buffer(T* pPtr, size_t szSize):
216  m_pPtr(pPtr),
217  m_szSize(szSize)
218  {
219  }
220 
221  tResult Set(const void* pValue, size_t szSize) override
222  {
223  if (szSize > GetSize())
224  {
225  RETURN_ERROR(ERR_OUT_OF_RANGE);
226  }
227 
228  adtf_util::cMemoryBlock::MemCopy(m_pPtr, pValue, szSize);
229 
231  }
232 
233  size_t GetSize() const override
234  {
235  return m_szSize;
236  }
237 
238  const void* Get() const override
239  {
240  return m_pPtr;
241  }
242 };
243 
244 template<typename T>
245 class adtf_memory_buffer<T, typename std::enable_if<std::is_const<T>::value>::type> :
246  public IRawMemory
247 {
248 private:
249  const T* m_pPtr;
250  size_t m_szSize;
251 
252 public:
253  adtf_memory_buffer(const T* pPtr, size_t szSize):
254  m_pPtr(pPtr),
255  m_szSize(szSize)
256  {
257  }
258 
259  tResult Set(const void* /* pValue */, size_t /* szSize */) override
260  {
261  RETURN_ERROR(ERR_NOACCESS);
262  }
263 
264  size_t GetSize() const override
265  {
266  return m_szSize;
267  }
268 
269  const void* Get() const override
270  {
271  return m_pPtr;
272  }
273 };
274 } //namespace ant
275 
276 namespace penguin
277 {
291 template<typename T, typename Enable = void>
293 {
294 public:
295  explicit adtf_memory_trivial_type(T* pValuePointer):
296  m_pAssignedValue(pValuePointer)
297  {
298  }
307  tResult Set(const void* pValue, size_t szSize) override
308  {
309  RETURN_IF_POINTER_NULL(pValue);
310  RETURN_IF_POINTER_NULL(m_pAssignedValue);
311  if (szSize == sizeof(T))
312  {
313  adtf_util::cMemoryBlock::MemCopy(m_pAssignedValue, pValue, szSize);
315  }
316  else
317  {
318  RETURN_ERROR(ERR_MEMORY);
319  }
320  }
325  size_t GetSize() const override
326  {
327  if(m_pAssignedValue)
328  {
329  return sizeof(T);
330  }
331  return size_t(0);
332  }
337  const void* Get() const override
338  {
339  return m_pAssignedValue;
340  }
341 
342 private:
343  T* m_pAssignedValue = nullptr;
344 };
345 
346 template<typename T>
347 class adtf_memory_trivial_type<T, typename std::enable_if<std::is_const<T>::value>::type>
349 {
350 public:
351  explicit adtf_memory_trivial_type(T* pValuePointer):
352  m_pAssignedValue(pValuePointer)
353  {
354  }
363  tResult Set(const void* /*pValue*/, size_t /*szSize*/) override
364  {
365  RETURN_ERROR(ERR_POINTER);
366  }
371  size_t GetSize() const override
372  {
373  if (m_pAssignedValue)
374  {
375  return sizeof(T);
376  }
377  return size_t(0);
378  }
383  const void* Get() const override
384  {
385  return m_pAssignedValue;
386  }
387 private:
388  T* m_pAssignedValue = nullptr;
389 };
390 
391 
406 template<typename T, size_t TSIZE = 0, typename Enable=void>
408 {
410  typedef T _myStorageType;
412 
413 private:
416  adtf_memory() {};
417  adtf_memory(const adtf_memory&) = delete;
418  adtf_memory& operator=(const adtf_memory&) = delete;
419  adtf_memory(adtf_memory&&) = delete;
420  adtf_memory& operator=(adtf_memory&&) = delete;
421 
422 public:
427  explicit adtf_memory(T* pAssignValue):
428  m_pAssignValue(pAssignValue)
429  {
430  }
434  virtual ~adtf_memory()
435  {
436  m_pAssignValue = nullptr;
437  }
438 
445  tResult Set(const void* pValue, size_t szSize) override
446  {
447  constexpr auto szSizeToUse = std::conditional<std::is_void<T>::value,
450  if (pValue != nullptr)
451  {
452  return _myBase::Assign(m_pAssignValue, szSizeToUse, pValue, szSize);
453  }
454  else
455  {
457  }
458  }
463  const void* Get() const override
464  {
465  if (m_pAssignValue != nullptr)
466  {
468  }
469  return nullptr;
470  }
476  size_t GetSize() const override
477  {
478  constexpr auto szSizeToUse = std::conditional<std::is_void<T>::value,
481  if (m_pAssignValue != nullptr)
482  {
483  return _myBase::GetSize(m_pAssignValue, szSizeToUse);
484  }
485  return size_t(0);
486  }
487 };
488 
494 template<typename T>
495 class adtf_memory<T, 0, typename std::enable_if<std::is_trivially_copyable<T>::value>::type>
496  : public adtf_memory_trivial_type<T>
497 {
498 public:
500  typedef T _myStorageType;
502 
503 public:
504  explicit adtf_memory(T* pAssignValue):
505  _myBase(pAssignValue)
506  {
507  }
508 };
509 
510 }
511 
519 using ant::IRawMemory;
522 
523 } //namespace base
524 
525 } // namespace adtf
526 
Copyright © Audi Electronics Venture GmbH.
#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.
#define RETURN_IF_POINTER_NULL(_ptr)
Return ERR_POINTER if _ptr is nullptr, which requires the calling function's return type to be tResul...
The IRawMemory interface provides methods for getting and setting memory values through abstract inte...
virtual tResult Set(const void *pValue, size_t szSize)=0
Sets the Raw pointer memory.
virtual size_t GetSize() const =0
Returns the size in bytes of the memory.
virtual const void * Get() const =0
Returns the raw memory pointer.
tResult Set(const void *pValue, size_t szSize) override
Sets the Raw pointer memory.
size_t GetSize() const override
Returns the size in bytes of the memory.
const void * Get() const override
Returns the raw memory pointer.
Legacy template class for adtf_memory usage.
size_t GetSize() const
Returns the size in bytes of the memory.
adtf_memory(T *pAssignValue)
explicit CTOR to create a IRawMemory interface rvalue
T * m_pAssignValue
Reference pointer to the T constructed with explict adtf_memory.
tResult Set(const void *pValue, size_t szSize)
Sets the Raw pointer memory.
const void * Get() const
Returns the raw memory pointer.
Template class implementation for the IRawMemory interface for trivial types.
tResult Set(const void *pValue, size_t szSize) override
Sets the Raw pointer memory.
size_t GetSize() const override
Returns the size in bytes of the memory.
const void * Get() const override
Returns the raw memory pointer.
Template class implementation for the ant::IRawMemory interface (see Supported types for adtf_memory<...
adtf_memory(T *pAssignValue)
explicit CTOR to create a IRawMemory interface rvalue
tResult Set(const void *pValue, size_t szSize) override
Sets the content of the assigned value of type T to the given memory.
size_t GetSize() const override
Retrieves the size of the content of the assigned value of type T.
T * m_pAssignValue
Reference pointer to the T constructed with explict adtf_memory.
const void * Get() const override
Retrieves the content of the assigned value of type T as memory pointer.
Namespace for entire ADTF SDK.
Concept template class for non trivial penguin::adtf_memory types of type T to specialize the usage o...
static tResult Assign(T *pAssignValue, const size_t szStaticSize, const void *pValueToSet, const size_t szSizeToSet)
Sets (copy) the memory value pValueToSet of size in bytes szSizeToSet to the of container class T in ...
static size_t GetSize(const T *pAssignValue, const size_t szStaticSize)
Gets size in bytes of the memory pointer of container class T in parameter pAssignValue.
static const void * GetPtr(const T *pAssignValue)
Gets the memory pointer to the of container class T in parameter pAssignValue.
helper template to retrieve the given size as expression.
helper template to retrieve the given size as expression.