ADTF
Loading...
Searching...
No Matches
rawmemory_base.h
Go to the documentation of this file.
1
7#pragma once
8#include <adtf_utils.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
89template<typename T>
91{
104 inline static tResult
105 Assign(T* pAssignValue, const size_t szStaticSize, const void* pValueToSet, const size_t szSizeToSet)
106 {
108 "Unsupported type T! See documentation which types are supported."
109 "adtf_memory<T> only supports trivial types unless you specialize the adtf_memory_forward<T> for "
110 "the type T!");
111 return ERR_NOT_IMPL;
112 }
113
121 inline static const void* GetPtr(const T* pAssignValue)
122 {
124 "Unsupported type T! See documentation which types are supported."
125 "adtf_memory<T> only supports trivial types unless you specialize the adtf_memory_forward<T> for "
126 "the type T!");
127 return nullptr;
128 }
129
137 inline static size_t GetSize(const T* pAssignValue, const size_t szStaticSize)
138 {
140 "Unsupported type T! See documentation which types are supported."
141 "adtf_memory<T> only supports trivial types unless you specialize the adtf_memory_forward<T> for "
142 "the type T!");
143 return size_t(0);
144 }
145};
146
154template<typename T, size_t TSIZE = 0>
155class adtf_memory : public IRawMemory, protected adtf_memory_forward<T>
156{
157 typedef adtf_memory<T, TSIZE> _myType;
158 typedef T _myStorageType;
159 typedef adtf_memory_forward<T> _myBase;
160
161private:
163 T* m_pAssignValue;
164 adtf_memory() {};
165 adtf_memory(const adtf_memory&) = delete;
166 adtf_memory& operator=(const adtf_memory&) = delete;
167 adtf_memory(adtf_memory&&) = delete;
168 adtf_memory& operator=(adtf_memory&&) = delete;
169
170public:
172 explicit adtf_memory(T* pAssignValue)
173 {
174 m_pAssignValue = pAssignValue;
175 }
176
177 virtual ~adtf_memory()
178 {
179 m_pAssignValue = nullptr;
180 }
181
182 tResult Set(const void* pValue, size_t szSize)
183 {
184 if (pValue != nullptr)
185 {
186 return _myBase::Assign(m_pAssignValue, TSIZE, pValue, szSize);
187 }
188 else
189 {
190 RETURN_ERROR(ERR_POINTER);
191 }
192 }
193 const void* Get() const
194 {
195 if (m_pAssignValue != nullptr)
196 {
197 return _myBase::GetPtr(m_pAssignValue);
198 }
199 return nullptr;
200 }
201 size_t GetSize() const
202 {
203 if (m_pAssignValue != nullptr)
204 {
205 return _myBase::GetSize(m_pAssignValue, TSIZE);
206 }
207 return size_t(0);
208 }
209};
210
214template<typename T, typename Enable = void>
215class adtf_memory_buffer : public IRawMemory
216{
217private:
218 T* m_pPtr;
219 size_t m_szSize;
220
221public:
222 adtf_memory_buffer(T* pPtr, size_t szSize): m_pPtr(pPtr), m_szSize(szSize)
223 {
224 }
225
226 tResult Set(const void* pValue, size_t szSize) override
227 {
228 if (szSize > GetSize())
229 {
230 RETURN_ERROR(ERR_OUT_OF_RANGE);
231 }
232
233 adtf_util::cMemoryBlock::MemCopy(m_pPtr, pValue, szSize);
234
236 }
237
238 size_t GetSize() const override
239 {
240 return m_szSize;
241 }
242
243 const void* Get() const override
244 {
245 return m_pPtr;
246 }
247};
248
252template<typename T>
253class adtf_memory_buffer<T, typename std::enable_if<std::is_const<T>::value>::type> : public IRawMemory
254{
255private:
256 const T* m_pPtr;
257 size_t m_szSize;
258
259public:
260 adtf_memory_buffer(const T* pPtr, size_t szSize): m_pPtr(pPtr), m_szSize(szSize)
261 {
262 }
263
264 tResult Set(const void* /* pValue */, size_t /* szSize */) override
265 {
266 RETURN_ERROR(ERR_NOACCESS);
267 }
268
269 size_t GetSize() const override
270 {
271 return m_szSize;
272 }
273
274 const void* Get() const override
275 {
276 return m_pPtr;
277 }
278};
279} // namespace ant
280
281namespace penguin
282{
294template<typename T, typename Enable = void>
295class adtf_memory_trivial_type : public adtf::base::ant::IRawMemory
296{
297public:
298 explicit adtf_memory_trivial_type(T* pValuePointer): m_pAssignedValue(pValuePointer)
299 {
300 }
309 tResult Set(const void* pValue, size_t szSize) override
310 {
312 RETURN_IF_POINTER_NULL(m_pAssignedValue);
313 if (szSize == sizeof(T))
314 {
315 adtf_util::cMemoryBlock::MemCopy(m_pAssignedValue, pValue, szSize);
317 }
318 else
319 {
320 RETURN_ERROR(ERR_MEMORY);
321 }
322 }
323
327 size_t GetSize() const override
328 {
329 if (m_pAssignedValue)
330 {
331 return sizeof(T);
332 }
333 return size_t(0);
334 }
335
339 const void* Get() const override
340 {
341 return m_pAssignedValue;
342 }
343
344private:
345 T* m_pAssignedValue = nullptr;
346};
347
351template<typename T>
352class adtf_memory_trivial_type<T, typename std::enable_if<std::is_const<T>::value>::type> :
354{
355public:
356 explicit adtf_memory_trivial_type(T* pValuePointer): m_pAssignedValue(pValuePointer)
357 {
358 }
367 tResult Set(const void* /*pValue*/, size_t /*szSize*/) override
368 {
369 RETURN_ERROR(ERR_POINTER);
370 }
371
375 size_t GetSize() const override
376 {
377 if (m_pAssignedValue)
378 {
379 return sizeof(T);
380 }
381 return size_t(0);
382 }
383
387 const void* Get() const override
388 {
389 return m_pAssignedValue;
390 }
391
392private:
393 T* m_pAssignedValue = nullptr;
394};
395
410template<typename T, size_t TSIZE = 0, typename Enable = void>
412{
413 typedef adtf_memory<T, TSIZE, void> _myType;
414 typedef T _myStorageType;
416
417private:
419 T* m_pAssignValue;
420 adtf_memory() {};
421 adtf_memory(const adtf_memory&) = delete;
422 adtf_memory& operator=(const adtf_memory&) = delete;
423 adtf_memory(adtf_memory&&) = delete;
424 adtf_memory& operator=(adtf_memory&&) = delete;
425
426public:
431 explicit adtf_memory(T* pAssignValue): m_pAssignValue(pAssignValue)
432 {
433 }
434
437 virtual ~adtf_memory()
438 {
439 m_pAssignValue = nullptr;
440 }
441
448 tResult Set(const void* pValue, size_t szSize) override
449 {
450 constexpr auto szSizeToUse =
451 std::conditional<std::is_void<T>::value, adtf::base::penguin::detail::get_const_size<TSIZE>,
453 if (pValue != nullptr)
454 {
455 return _myBase::Assign(m_pAssignValue, szSizeToUse, pValue, szSize);
456 }
457 else
458 {
460 }
461 }
462
466 const void* Get() const override
467 {
468 if (m_pAssignValue != nullptr)
469 {
470 return _myBase::GetPtr(m_pAssignValue);
471 }
472 return nullptr;
473 }
474
479 size_t GetSize() const override
480 {
481 constexpr auto szSizeToUse =
482 std::conditional<std::is_void<T>::value, adtf::base::penguin::detail::get_const_size<TSIZE>,
484 if (m_pAssignValue != nullptr)
485 {
486 return _myBase::GetSize(m_pAssignValue, szSizeToUse);
487 }
488 return size_t(0);
489 }
490};
491
497template<typename T>
498class adtf_memory<T, 0, typename std::enable_if<std::is_trivially_copyable<T>::value>::type> :
500{
501public:
503 typedef T _myStorageType;
504 typedef adtf_memory_trivial_type<T> _myBase;
505
506public:
507 explicit adtf_memory(T* pAssignValue): _myBase(pAssignValue)
508 {
509 }
510};
511
512} // namespace penguin
513
521using ant::IRawMemory;
524
525} // namespace base
526
527} // namespace adtf
Definition for type traits helper Copyright © Audi Electronics Venture GmbH. All rights reserved.
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:736
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Definition result.h:29
#define RETURN_ERROR(code)
Return specific error code, which requires the calling function's return type to be tResult.
Definition result.h:42
#define RETURN_IF_POINTER_NULL(_ptr)
Return ERR_POINTER if _ptr is nullptr, which requires the calling function's return type to be tResul...
Definition result.h:49
Definition rawmemory_base.h:23
virtual size_t GetSize() const =0
virtual tResult Set(const void *pValue, size_t szSize)=0
virtual const void * Get() const =0
tResult Set(const void *, size_t) override
Definition rawmemory_base.h:264
Template class implementation for the IRawMemory interface.
Definition rawmemory_base.h:216
const void * Get() const override
Definition rawmemory_base.h:243
tResult Set(const void *pValue, size_t szSize) override
Definition rawmemory_base.h:226
size_t GetSize() const override
Definition rawmemory_base.h:238
const void * Get() const
Definition rawmemory_base.h:193
size_t GetSize() const
Definition rawmemory_base.h:201
adtf_memory(T *pAssignValue)
explicit CTOR to create a IRawMemory interface rvalue
Definition rawmemory_base.h:172
virtual ~adtf_memory()
DTOR.
Definition rawmemory_base.h:177
tResult Set(const void *pValue, size_t szSize)
Definition rawmemory_base.h:182
Definition rawmemory_base.h:296
tResult Set(const void *pValue, size_t szSize) override
Definition rawmemory_base.h:309
size_t GetSize() const override
Definition rawmemory_base.h:327
const void * Get() const override
Definition rawmemory_base.h:339
Definition rawmemory_base.h:412
const void * Get() const override
Retrieves the content of the assigned value of type T as memory pointer.
Definition rawmemory_base.h:466
virtual ~adtf_memory()
DTOR.
Definition rawmemory_base.h:437
size_t GetSize() const override
Retrieves the size of the content of the assigned value of type T.
Definition rawmemory_base.h:479
tResult Set(const void *pValue, size_t szSize) override
Sets the content of the assigned value of type T to the given memory.
Definition rawmemory_base.h:448
adtf_memory(T *pAssignValue)
explicit CTOR to create a IRawMemory interface rvalue
Definition rawmemory_base.h:431
Namespace for all functionality of the ADTF Base SDK provided since v3.0.
Definition adtf_class_version.h:16
constexpr bool always_false
helper template to get a always false expression.
Definition adtf_base_type_traits.h:23
Namespace for the ADTF Base SDK.
Definition adtf_base_type_traits.h:13
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14
Definition rawmemory_base.h:91
static size_t GetSize(const T *pAssignValue, const size_t szStaticSize)
Definition rawmemory_base.h:137
static tResult Assign(T *pAssignValue, const size_t szStaticSize, const void *pValueToSet, const size_t szSizeToSet)
Definition rawmemory_base.h:105
static const void * GetPtr(const T *pAssignValue)
Definition rawmemory_base.h:121
helper template to retrieve the given size as expression.
Definition adtf_base_type_traits.h:31
helper template to retrieve the given size as expression.
Definition adtf_base_type_traits.h:41