CVB++ 15.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 public:
24
25 using GuardType = HandleGuard<BufferBase>;
26
27 protected:
28 explicit BufferBase(HandleGuard<BufferBase>&& guard)
29 : handle_(std::move(guard))
30 {
31 if (!CVB_CALL_CAPI(CVCIsBuffer(Handle())))
32 throw std::runtime_error("handle must be a buffer");
33 }
34
35 public:
36 BufferBase(const BufferBase& other) = delete;
37 BufferBase& operator=(const BufferBase& other) = delete;
38 BufferBase(BufferBase&& other) = delete;
39 BufferBase& operator=(BufferBase&& other) = delete;
40 virtual ~BufferBase() = default;
41
43
48 void* Handle() const noexcept
49 {
50 return handle_.Handle();
51 }
52
54
57 std::uint8_t* BasePtr() const noexcept
58 {
59 void* pBase = nullptr;
60 CVB_CALL_CAPI(CVCBufferGetBasePtr(Handle(), pBase));
61 return reinterpret_cast<std::uint8_t*>(pBase);
62 }
63
65
71 size_t Size() const noexcept
72 {
73 size_t size = 0;
74 CVB_CALL_CAPI(CVCBufferGetSize(Handle(), size));
75 return size;
76 }
77
79
85 size_t Capacity() const noexcept
86 {
87 size_t capacity = 0;
88 CVB_CALL_CAPI(CVCBufferGetCapacity(Handle(), capacity));
89 return capacity;
90 }
91
92 private:
93 HandleGuard<BufferBase> handle_;
94 };
95
96 using Cvb::BufferBase;
97
98 CVB_END_INLINE_NS
99
100}
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:71
std::uint8_t * BasePtr() const noexcept
Gets the pointer to the start of this buffer.
Definition: buffer_base.hpp:57
size_t Capacity() const noexcept
Gets the allocated size of this buffer in bytes.
Definition: buffer_base.hpp:85
void * Handle() const noexcept
Classic API buffer handle.
Definition: buffer_base.hpp:48
Root namespace for the Image Manager interface.
Definition: c_barcode.h:15