ADTF
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
11namespace adtf
12{
13namespace base
14{
15namespace ant
16{
23{
24public:
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
87template<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 {
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 }
111
119 inline static const void* GetPtr(const T* pAssignValue)
120 {
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 }
126
134 inline static size_t GetSize(const T* pAssignValue, const size_t szStaticSize)
135 {
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
149template<typename T, size_t TSIZE = 0>
150class adtf_memory : public IRawMemory, protected adtf_memory_forward<T>
151{
152 typedef adtf_memory<T, TSIZE> _myType;
153 typedef T _myStorageType;
154 typedef adtf_memory_forward<T> _myBase;
155
156private:
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
165public:
167 explicit adtf_memory(T* pAssignValue)
168 {
169 m_pAssignValue = pAssignValue;
170 }
171
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
206template<typename T, typename Enable = void>
207class adtf_memory_buffer :
208 public IRawMemory
209{
210private:
211 T* m_pPtr;
212 size_t m_szSize;
213
214public:
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
244template<typename T>
245class adtf_memory_buffer<T, typename std::enable_if<std::is_const<T>::value>::type> :
246 public IRawMemory
247{
248private:
249 const T* m_pPtr;
250 size_t m_szSize;
251
252public:
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
276namespace penguin
277{
291template<typename T, typename Enable = void>
292class adtf_memory_trivial_type : public adtf::base::ant::IRawMemory
293{
294public:
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 {
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 }
321
325 size_t GetSize() const override
326 {
327 if(m_pAssignedValue)
328 {
329 return sizeof(T);
330 }
331 return size_t(0);
332 }
333
337 const void* Get() const override
338 {
339 return m_pAssignedValue;
340 }
341
342private:
343 T* m_pAssignedValue = nullptr;
344};
345
346template<typename T>
347class adtf_memory_trivial_type<T, typename std::enable_if<std::is_const<T>::value>::type>
349{
350public:
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 }
367
371 size_t GetSize() const override
372 {
373 if (m_pAssignedValue)
374 {
375 return sizeof(T);
376 }
377 return size_t(0);
378 }
379
383 const void* Get() const override
384 {
385 return m_pAssignedValue;
386 }
387private:
388 T* m_pAssignedValue = nullptr;
389};
390
391
406template<typename T, size_t TSIZE = 0, typename Enable=void>
408{
409 typedef adtf_memory<T, TSIZE, void> _myType;
410 typedef T _myStorageType;
412
413private:
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
422public:
427 explicit adtf_memory(T* pAssignValue):
428 m_pAssignValue(pAssignValue)
429 {
430 }
431
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 }
459
463 const void* Get() const override
464 {
465 if (m_pAssignValue != nullptr)
466 {
468 }
469 return nullptr;
470 }
471
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
494template<typename T>
495class adtf_memory<T, 0, typename std::enable_if<std::is_trivially_copyable<T>::value>::type>
496 : public adtf_memory_trivial_type<T>
497{
498public:
500 typedef T _myStorageType;
501 typedef adtf_memory_trivial_type<T> _myBase;
502
503public:
504 explicit adtf_memory(T* pAssignValue):
505 _myBase(pAssignValue)
506 {
507 }
508};
509
510}
511
519using ant::IRawMemory;
522
523} //namespace base
524
525} // namespace adtf
526
Copyright © Audi Electronics Venture GmbH.
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
#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
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 IRawMemory interface (see Supported types for adtf_memory<T> fo...
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.
const void * Get() const override
Retrieves the content of the assigned value of type T as memory pointer.
Namespace for all functionality of the ADTF Base SDK provided since v3.0.
constexpr bool always_false
helper template to get a always false expression.
Namespace for the ADTF Base SDK.
Namespace for entire ADTF SDK.
Concept template class for non trivial adtf_memory types of type T to specialize the usage of adtf_me...
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.