CVB++ 15.0
buffer_base.hpp
1#pragma once
2
3#include <cassert>
4
5#include "global.hpp"
6
7namespace Cvb
8{
9
10 CVB_BEGIN_INLINE_NS
11
12 template <>
13 inline HandleGuard<BufferBase>::HandleGuard(void *handle) noexcept
14 : HandleGuard<BufferBase>(handle, [](void *handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
15 {
16 }
17
19
20 class BufferBase
21 {
22 public:
23 using GuardType = HandleGuard<BufferBase>;
24
25 protected:
26 explicit BufferBase(HandleGuard<BufferBase> &&guard)
27 : handle_(std::move(guard))
28 {
29 if (!CVB_CALL_CAPI(CVCIsBuffer(Handle())))
30 throw std::runtime_error("handle must be a buffer");
31 }
32
33 public:
34 BufferBase(const BufferBase &other) = delete;
35 BufferBase &operator=(const BufferBase &other) = delete;
36 BufferBase(BufferBase &&other) = delete;
37 BufferBase &operator=(BufferBase &&other) = delete;
38 virtual ~BufferBase() = default;
39
41
46 void *Handle() const noexcept
47 {
48 return handle_.Handle();
49 }
50
52
55 std::uint8_t *BasePtr() const noexcept
56 {
57 void *pBase = nullptr;
58 CVB_CALL_CAPI(CVCBufferGetBasePtr(Handle(), pBase));
59 return reinterpret_cast<std::uint8_t *>(pBase);
60 }
61
63
69 size_t Size() const noexcept
70 {
71 size_t size = 0;
72 CVB_CALL_CAPI(CVCBufferGetSize(Handle(), size));
73 return size;
74 }
75
77
83 size_t Capacity() const noexcept
84 {
85 size_t capacity = 0;
86 CVB_CALL_CAPI(CVCBufferGetCapacity(Handle(), capacity));
87 return capacity;
88 }
89
90 private:
91 HandleGuard<BufferBase> handle_;
92 };
93
94 using Cvb::BufferBase;
95
96 CVB_END_INLINE_NS
97
98} // namespace Cvb
Base class of all buffers.
Definition buffer_base.hpp:21
size_t Size() const noexcept
Gets the actual size of this buffer in bytes.
Definition buffer_base.hpp:69
std::uint8_t * BasePtr() const noexcept
Gets the pointer to the start of this buffer.
Definition buffer_base.hpp:55
size_t Capacity() const noexcept
Gets the allocated size of this buffer in bytes.
Definition buffer_base.hpp:83
void * Handle() const noexcept
Classic API buffer handle.
Definition buffer_base.hpp:46
cvbbool_t ReleaseObject(OBJ &Object)
T move(T... args)
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17