CVB++ 15.0
pfnc_buffer.hpp
1#pragma once
2
3#include "buffer_base.hpp"
4
5#include "pfnc_format.hpp"
6
7
8namespace Cvb
9{
10
11 CVB_BEGIN_INLINE_NS
12
14
16 : public BufferBase
17 {
18 protected:
19 struct PrivateTag {};
20
21 public:
22 PFNCBuffer(HandleGuard<BufferBase>&& guard, PrivateTag)
23 : BufferBase(std::move(guard))
24 {
25 if (!CVB_CALL_CAPI(CVCIsPfncBuffer(Handle())))
26 throw std::runtime_error("handle must be a pfnc buffer");
27 }
28
30 /*
31 * \param [in] guard Life time guard for C-API handle.
32 */
33 static PFNCBufferPtr FromHandle(HandleGuard<BufferBase>&& guard)
34 {
35 if (!guard.Handle())
36 throw std::runtime_error("handle must not be null");
37 return std::make_shared<PFNCBuffer>(std::move(guard), PrivateTag{});
38 }
39
40 template <class T>
41 static PFNCBufferPtr FromHandle(HandleGuard<BufferBase> &&guard)
42 {
43 static_assert(std::is_base_of<PFNCBuffer, T>::value, "CVB: Type must be derived from PFNCBuffer");
44 return FromHandle(std::move(guard));
45 }
46
48
55 int PFNCValue() const noexcept
56 {
57 CExports::cvbuint32_t pfncFormat = static_cast<CExports::cvbuint32_t>(Cvb::Pfnc::PfncFormat::InvalidPixelFormat);
58 CVB_CALL_CAPI(CVCBufferGetPFNCValue(Handle(), pfncFormat));
59 return static_cast<int>(pfncFormat);
60 }
61
63
70 int Rank() const noexcept
71 {
72 CExports::cvbdim_t rank = 0;
73 CVB_CALL_CAPI(CVCBufferGetRank(Handle(), rank));
74 return static_cast<int>(rank);
75 }
76
78
88 int Length(int dimension) const
89 {
90 return static_cast<int>(NativeCall<CExports::cvbint64_t>([this, dimension](CExports::cvbint64_t& value)
91 {
92 return CVB_CALL_CAPI(CVCBufferGetLength(Handle(), static_cast<CExports::cvbdim_t>(dimension), value));
93 }));
94 }
95
97
109 std::intptr_t Increment(int dimension) const
110 {
111 return NativeCall<std::intptr_t>([this, dimension](std::intptr_t& ptr)
112 {
113 return CVB_CALL_CAPI(CVCBufferGetIncrement(Handle(), static_cast<CExports::cvbdim_t>(dimension), ptr));
114 });
115 }
116
117 protected:
118 template <class T, class FN>
119 T NativeCall(const FN& fn) const
120 {
121 T value;
122 const auto result = fn(value);
123 if (result < 0)
124 Utilities::SystemInfo::ThrowLastError(result);
125 return value;
126 }
127 };
128
129 CVB_END_INLINE_NS
130
131}
Base class of all buffers.
Definition: buffer_base.hpp:22
void * Handle() const noexcept
Classic API buffer handle.
Definition: buffer_base.hpp:48
PFNC buffer class implementing a pfnc buffer.
Definition: pfnc_buffer.hpp:17
int Length(int dimension) const
Gets the number of elements in the given Dimension.
Definition: pfnc_buffer.hpp:88
static PFNCBufferPtr FromHandle(HandleGuard< BufferBase > &&guard)
Creates a pfnc buffer from a classic API handle.
Definition: pfnc_buffer.hpp:33
int Rank() const noexcept
Gets the number of dimensions of this buffer.
Definition: pfnc_buffer.hpp:70
int PFNCValue() const noexcept
Gets the PFNC value (format identifier) of this buffer.
Definition: pfnc_buffer.hpp:55
std::intptr_t Increment(int dimension) const
Gets the increment to the next element in the given Dimension.
Definition: pfnc_buffer.hpp:109
@ InvalidPixelFormat
Invalid pixel format.
Root namespace for the Image Manager interface.
Definition: c_barcode.h:15