IDS peak genericC++  v1.4.1
peak_buffer_chunk.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
13 
15 #include <peak/dll_interface/peak_dll_interface_util.hpp>
16 
17 #include <cstddef>
18 #include <cstdint>
19 #include <memory>
20 
21 
22 namespace peak
23 {
24 namespace core
25 {
26 
27 class Buffer;
28 
36 {
37 public:
38  BufferChunk() = delete;
39  ~BufferChunk() = default;
40  BufferChunk(const BufferChunk& other) = delete;
41  BufferChunk& operator=(const BufferChunk& other) = delete;
42  BufferChunk(BufferChunk&& other) = delete;
43  BufferChunk& operator=(BufferChunk&& other) = delete;
44 
54  uint64_t ID() const;
64  void* BasePtr() const;
74  size_t Size() const;
75 
85  std::shared_ptr<Buffer> ParentBuffer() const;
86 
87 private:
88  friend ClassCreator<BufferChunk>;
89  BufferChunk(PEAK_BUFFER_CHUNK_HANDLE bufferChunkHandle, const std::weak_ptr<Buffer>& parentBuffer);
90  PEAK_BUFFER_CHUNK_HANDLE m_backendHandle;
91 
92  std::weak_ptr<Buffer> m_parentBuffer;
93 };
94 
95 } /* namespace core */
96 } /* namespace peak */
97 
98 /* Implementation */
99 namespace peak
100 {
101 namespace core
102 {
103 
105  PEAK_BUFFER_CHUNK_HANDLE bufferChunkHandle, const std::weak_ptr<Buffer>& parentBuffer)
106  : m_backendHandle(bufferChunkHandle)
107  , m_parentBuffer(parentBuffer)
108 {}
109 
110 inline uint64_t BufferChunk::ID() const
111 {
112  return QueryNumericFromCInterfaceFunction<uint64_t>(
113  [&](uint64_t* id) { return PEAK_C_ABI_PREFIX PEAK_BufferChunk_GetID(m_backendHandle, id); });
114 }
115 
116 inline void* BufferChunk::BasePtr() const
117 {
118  return QueryNumericFromCInterfaceFunction<void*>(
119  [&](void** basePtr) { return PEAK_C_ABI_PREFIX PEAK_BufferChunk_GetBasePtr(m_backendHandle, basePtr); });
120 }
121 
122 inline size_t BufferChunk::Size() const
123 {
124  return QueryNumericFromCInterfaceFunction<size_t>(
125  [&](size_t* size) { return PEAK_C_ABI_PREFIX PEAK_BufferChunk_GetSize(m_backendHandle, size); });
126 }
127 
128 inline std::shared_ptr<Buffer> BufferChunk::ParentBuffer() const
129 {
130  return LockOrThrow(m_parentBuffer);
131 }
132 
133 } /* namespace core */
134 } /* namespace peak */
uint64_t ID() const
Returns the ID.
Definition: peak_buffer_chunk.hpp:110
void * BasePtr() const
Returns the base pointer.
Definition: peak_buffer_chunk.hpp:116
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
std::shared_ptr< Buffer > ParentBuffer() const
Returns the parent buffer.
Definition: peak_buffer_chunk.hpp:128
size_t Size() const
Returns the size.
Definition: peak_buffer_chunk.hpp:122
PEAK_C_API PEAK_BufferChunk_GetBasePtr(PEAK_BUFFER_CHUNK_HANDLE bufferChunkHandle, void **basePtr)
Asks the given buffer chunk for its base pointer.
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
struct PEAK_BUFFER_CHUNK * PEAK_BUFFER_CHUNK_HANDLE
Definition: peak_backend.h:389
PEAK_C_API PEAK_BufferChunk_GetID(PEAK_BUFFER_CHUNK_HANDLE bufferChunkHandle, uint64_t *id)
Asks the given buffer chunk for its ID.
BufferChunk & operator=(const BufferChunk &other)=delete
Represents a buffer chunk.
Definition: peak_buffer_chunk.hpp:35
PEAK_C_API PEAK_BufferChunk_GetSize(PEAK_BUFFER_CHUNK_HANDLE bufferChunkHandle, size_t *size)
Asks the given buffer chunk for its size.