CVB++ 14.0
buffer_base.hpp
1#pragma once
2
3#include <cassert>
4
5#include "global.hpp"
6
7
8namespace Cvb
9{
10
11 CVB_BEGIN_INLINE_NS
12
13 template <>
14 inline HandleGuard<BufferBase>::HandleGuard(void* handle) noexcept
15 : HandleGuard<BufferBase>(handle, [](void* handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
16 {
17 }
18
20
22 {
23 protected:
24 explicit BufferBase(HandleGuard<BufferBase>&& guard) noexcept
25 : handle_(std::move(guard))
26 {
27 assert(CVB_CALL_CAPI(CVCIsBuffer(Handle())) && "buffer handle must be a buffer");
28 }
29
30 public:
31 virtual ~BufferBase() = default;
32
34
39 void* Handle() const noexcept
40 {
41 return handle_.Handle();
42 }
43
45
48 std::uint8_t* BasePtr() const noexcept
49 {
50 void* pBase = nullptr;
51 CVB_CALL_CAPI(CVCBufferGetBasePtr(Handle(), pBase));
52 return reinterpret_cast<std::uint8_t*>(pBase);
53 }
54
56
62 size_t Size() const noexcept
63 {
64 size_t size = 0;
65 CVB_CALL_CAPI(CVCBufferGetSize(Handle(), size));
66 return size;
67 }
68
70
76 size_t Capacity() const noexcept
77 {
78 size_t capacity = 0;
79 CVB_CALL_CAPI(CVCBufferGetCapacity(Handle(), capacity));
80 return capacity;
81 }
82
83 private:
84 HandleGuard<BufferBase> handle_;
85 };
86
87 using Cvb::BufferBase;
88
89 CVB_END_INLINE_NS
90
91}
Base class of all buffers.
Definition: buffer_base.hpp:22
size_t Size() const noexcept
Gets the actual size of this buffer in bytes.
Definition: buffer_base.hpp:62
std::uint8_t * BasePtr() const noexcept
Gets the pointer to the start of this buffer.
Definition: buffer_base.hpp:48
size_t Capacity() const noexcept
Gets the allocated size of this buffer in bytes.
Definition: buffer_base.hpp:76
void * Handle() const noexcept
Classic API buffer handle.
Definition: buffer_base.hpp:39
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24