ADTF  3.14.3
rawmemory_intf.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include <adtf_utils.h>
9 
10 namespace adtf
11 {
12 namespace base
13 {
14 namespace ant
15 {
21  class IRawMemory
22  {
23  public:
32  virtual tResult Set(const void* pValue, size_t szSize) = 0;
37  virtual size_t GetSize() const = 0;
42  virtual const void* Get() const = 0;
43  };
44 
86  template <typename T>
88  {
100  inline static tResult Assign(T* pAssignValue,
101  const size_t szStaticSize,
102  const void* pValueToSet,
103  const size_t szSizeToSet);
112  inline static const void* GetPtr(const T* pAssignValue);
121  inline static size_t GetSize(const T* pAssignValue, const size_t szStaticSize);
122  };
125  template <>
126  struct adtf_memory_forward<adtf_util::cMemoryBlock>
127  {
128  public:
130  static tResult Assign(adtf_util::cMemoryBlock* pAssignValue,
131  const size_t /* szStaticSize */,
132  const void* pValueToSet,
133  const size_t szSizeToSet)
134  {
135  return pAssignValue->Set(pValueToSet, szSizeToSet);
136  }
138  static const void* GetPtr(const adtf_util::cMemoryBlock* pAssignValue)
139  {
140  return pAssignValue->GetPtr();
141  }
143  static size_t GetSize(const adtf_util::cMemoryBlock* pAssignValue, const size_t /* szStaticSize */)
144  {
145  return static_cast<size_t>(pAssignValue->GetSize());
146  }
147  };
150  template <>
151  struct adtf_memory_forward<adtf_util::cMemoryPtr>
152  {
153  public:
154  static tResult Assign(adtf_util::cMemoryPtr* pAssignValue,
155  const size_t /* szStaticSize */,
156  const void* pValueToSet,
157  const size_t szSizeToSet)
158  {
159  return pAssignValue->Assign(pValueToSet, szSizeToSet);
160  }
161  static const void* GetPtr(const adtf_util::cMemoryPtr* pAssignValue)
162  {
163  return pAssignValue->GetPtr();
164  }
165  static size_t GetSize(const adtf_util::cMemoryPtr* pAssignValue, const size_t /* szStaticSize */)
166  {
167  return static_cast<size_t>(pAssignValue->GetSize());
168  }
169  };
170 
174  template <>
175  struct adtf_memory_forward<const void>
176  {
177  public:
178  static tResult Assign(const void* /* pAssignValue */,
179  const size_t /* szStaticSize */,
180  const void* /* pValueToSet */,
181  const size_t /* szSizeToSet */)
182  {
183  RETURN_ERROR(ERR_ACCESS_DENIED);
184  }
185  static const void* GetPtr(const void* pAssignValue)
186  {
187  return pAssignValue;
188  }
189  static size_t GetSize(const void* /* pAssignValue */, const size_t szStaticSize)
190  {
191  return szStaticSize;
192  }
193  };
194 
197  template <>
198  struct adtf_memory_forward<void>
199  {
200  private:
201  size_t m_szCurrentSize = g_npos;
202  public:
203  tResult Assign(void* pAssignValue,
204  const size_t szStaticSize,
205  const void* pValueToSet,
206  const size_t szSizeToSet)
207  {
208  if (szSizeToSet <= szStaticSize)
209  {
210  adtf_util::cMemoryBlock::MemCopy(pAssignValue, pValueToSet, szSizeToSet);
211  m_szCurrentSize = szSizeToSet;
212  RETURN_NOERROR;
213  }
214  else
215  {
216  RETURN_ERROR(ERR_MEMORY);
217  }
218  }
219  static const void* GetPtr(const void* pAssignValue)
220  {
221  return pAssignValue;
222  }
223  size_t GetSize(const void* /* pAssignValue */, const size_t szStaticSize) const
224  {
225  if (m_szCurrentSize != g_npos)
226  {
227  return m_szCurrentSize;
228  }
229  return szStaticSize;
230  }
231  };
232 
244  template <typename T, size_t TSIZE = 0>
245  class adtf_memory : public IRawMemory,
246  protected adtf_memory_forward<T>
247  {
249  typedef T _myStorageType;
251 
252  private:
255  adtf_memory() {};
256  adtf_memory(const adtf_memory&) = delete;
257  adtf_memory& operator=(const adtf_memory&) = delete;
258  adtf_memory(adtf_memory&&) = delete;
259  adtf_memory& operator=(adtf_memory&&) = delete;
260 
261  public:
263  explicit adtf_memory(T* pAssignValue)
264  {
265  m_pAssignValue = pAssignValue;
266  }
268  virtual ~adtf_memory()
269  {
270  m_pAssignValue = nullptr;
271  }
272 
273  tResult Set(const void* pValue, size_t szSize)
274  {
275  if (pValue != nullptr)
276  {
277  return _myBase::Assign(m_pAssignValue, TSIZE, pValue, szSize);
278  }
279  else
280  {
281  RETURN_ERROR(ERR_POINTER);
282  }
283  }
284  const void* Get() const
285  {
286  if (m_pAssignValue != nullptr)
287  {
289  }
290  return nullptr;
291  }
292  size_t GetSize() const
293  {
294  if (m_pAssignValue != nullptr)
295  {
296  return _myBase::GetSize(m_pAssignValue, TSIZE);
297  }
298  return size_t(0);
299  }
300  };
301 
302  template <typename T, typename Enable = void>
304 
305  template<typename T>
306  class adtf_memory_buffer<T, typename std::enable_if<!std::is_const<T>::value>::type> :
307  public IRawMemory
308  {
309  private:
310  T* m_pPtr;
311  size_t m_szSize;
312 
313  public:
314  adtf_memory_buffer(T* pPtr, size_t szSize):
315  m_pPtr(pPtr),
316  m_szSize(szSize)
317  {
318  }
319 
320  tResult Set(const void* pValue, size_t szSize) override
321  {
322  if (szSize > GetSize())
323  {
324  RETURN_ERROR(ERR_OUT_OF_RANGE);
325  }
326 
327  adtf_util::cMemoryBlock::MemCopy(m_pPtr, pValue, szSize);
328 
329  RETURN_NOERROR;
330  }
331 
332  size_t GetSize() const override
333  {
334  return m_szSize;
335  }
336 
337  const void* Get() const override
338  {
339  return m_pPtr;
340  }
341  };
342 
343  template <typename T>
344  class adtf_memory_buffer<T, typename std::enable_if<std::is_const<T>::value>::type>:
345  public IRawMemory
346  {
347  private:
348  const T* m_pPtr;
349  size_t m_szSize;
350 
351  public:
352  adtf_memory_buffer(const T* pPtr, size_t szSize):
353  m_pPtr(pPtr),
354  m_szSize(szSize)
355  {
356  }
357 
358  tResult Set(const void* /* pValue */, size_t /* szSize */) override
359  {
360  RETURN_ERROR(ERR_NOACCESS);
361  }
362 
363  size_t GetSize() const override
364  {
365  return m_szSize;
366  }
367 
368  const void* Get() const override
369  {
370  return m_pPtr;
371  }
372  };
373 } //namespace ant
374 
376 using ant::adtf_memory_forward;
378 using ant::adtf_memory;
380 using ant::IRawMemory;
382 using ant::adtf_memory_buffer;
383 
384 } //namespace base
385 } // namespace adtf
386 
393 #define adtf_memory_intf(__utils_memblock__) adtf::base::adtf_memory<adtf_util::cMemoryBlock>(& (__utils_memblock__))
Copyright © Audi Electronics Venture GmbH.
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.
Template class implementation for the IRawMemory interface.
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.
ADTF adtf_util Namespace - Within adtf this is used as adtf::util or adtf_util and also defined as A_...
Namespace for entire ADTF SDK.
static tResult Assign(adtf_util::cMemoryBlock *pAssignValue, const size_t, 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 const void * GetPtr(const adtf_util::cMemoryBlock *pAssignValue)
Gets the memory pointer to the of container class T in parameter pAssignValue.
static size_t GetSize(const adtf_util::cMemoryBlock *pAssignValue, const size_t)
Gets size in bytes of the memory pointer of container class T in parameter pAssignValue.
Concept template class which can only be specialized to use it for adtf_memory<T>.
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.

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