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 return std::make_shared<PFNCBuffer>(std::move(guard), PrivateTag{});
36 }
37
39
46 int PFNCValue() const noexcept
47 {
48 CExports::cvbuint32_t pfncFormat = static_cast<CExports::cvbuint32_t>(Cvb::Pfnc::PfncFormat::InvalidPixelFormat);
49 CVB_CALL_CAPI(CVCBufferGetPFNCValue(Handle(), pfncFormat));
50 return static_cast<int>(pfncFormat);
51 }
52
54
61 int Rank() const noexcept
62 {
63 CExports::cvbdim_t rank = 0;
64 CVB_CALL_CAPI(CVCBufferGetRank(Handle(), rank));
65 return static_cast<int>(rank);
66 }
67
69
79 int Length(int dimension) const
80 {
81 return static_cast<int>(NativeCall<CExports::cvbint64_t>([this, dimension](CExports::cvbint64_t& value)
82 {
83 return CVB_CALL_CAPI(CVCBufferGetLength(Handle(), static_cast<CExports::cvbdim_t>(dimension), value));
84 }));
85 }
86
88
100 std::intptr_t Increment(int dimension) const
101 {
102 return NativeCall<std::intptr_t>([this, dimension](std::intptr_t& ptr)
103 {
104 return CVB_CALL_CAPI(CVCBufferGetIncrement(Handle(), static_cast<CExports::cvbdim_t>(dimension), ptr));
105 });
106 }
107
108 protected:
109 template <class T, class FN>
110 T NativeCall(const FN& fn) const
111 {
112 T value;
113 const auto result = fn(value);
114 if (result < 0)
115 Utilities::SystemInfo::ThrowLastError(result);
116 return value;
117 }
118 };
119
120 CVB_END_INLINE_NS
121
122}
Base class of all buffers.
Definition: buffer_base.hpp:22
void * Handle() const noexcept
Classic API buffer handle.
Definition: buffer_base.hpp:44
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:79
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:61
int PFNCValue() const noexcept
Gets the PFNC value (format identifier) of this buffer.
Definition: pfnc_buffer.hpp:46
std::intptr_t Increment(int dimension) const
Gets the increment to the next element in the given Dimension.
Definition: pfnc_buffer.hpp:100
@ InvalidPixelFormat
Invalid pixel format.
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24