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 protected:
24 explicit BufferBase(HandleGuard<BufferBase>&& guard)
25 : handle_(std::move(guard))
26 {
27 if (!CVB_CALL_CAPI(CVCIsBuffer(Handle())))
28 throw std::runtime_error("handle must be a buffer");
29 }
30
31 public:
32 BufferBase(const BufferBase& other) = delete;
33 BufferBase& operator=(const BufferBase& other) = delete;
34 BufferBase(BufferBase&& other) = delete;
35 BufferBase& operator=(BufferBase&& other) = delete;
36 virtual ~BufferBase() = default;
37
39
44 void* Handle() const noexcept
45 {
46 return handle_.Handle();
47 }
48
50
53 std::uint8_t* BasePtr() const noexcept
54 {
55 void* pBase = nullptr;
56 CVB_CALL_CAPI(CVCBufferGetBasePtr(Handle(), pBase));
57 return reinterpret_cast<std::uint8_t*>(pBase);
58 }
59
61
67 size_t Size() const noexcept
68 {
69 size_t size = 0;
70 CVB_CALL_CAPI(CVCBufferGetSize(Handle(), size));
71 return size;
72 }
73
75
81 size_t Capacity() const noexcept
82 {
83 size_t capacity = 0;
84 CVB_CALL_CAPI(CVCBufferGetCapacity(Handle(), capacity));
85 return capacity;
86 }
87
88 private:
89 HandleGuard<BufferBase> handle_;
90 };
91
92 using Cvb::BufferBase;
93
94 CVB_END_INLINE_NS
95
96}
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:67
std::uint8_t * BasePtr() const noexcept
Gets the pointer to the start of this buffer.
Definition: buffer_base.hpp:53
size_t Capacity() const noexcept
Gets the allocated size of this buffer in bytes.
Definition: buffer_base.hpp:81
void * Handle() const noexcept
Classic API buffer handle.
Definition: buffer_base.hpp:44
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24