CVB++ 15.0
pfnc_buffer.hpp
1#pragma once
2
3#include "buffer_base.hpp"
4
5#include "pfnc_format.hpp"
6
7namespace Cvb
8{
9
10 CVB_BEGIN_INLINE_NS
11
13
14 class PFNCBuffer : public BufferBase
15 {
16 protected:
17 struct PrivateTag
18 {
19 };
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
53 int PFNCValue() const noexcept
54 {
55 CExports::cvbuint32_t pfncFormat = static_cast<CExports::cvbuint32_t>(Cvb::Pfnc::PfncFormat::InvalidPixelFormat);
56 CVB_CALL_CAPI(CVCBufferGetPFNCValue(Handle(), pfncFormat));
57 return static_cast<int>(pfncFormat);
58 }
59
61
68 int Rank() const noexcept
69 {
70 CExports::cvbdim_t rank = 0;
71 CVB_CALL_CAPI(CVCBufferGetRank(Handle(), rank));
72 return static_cast<int>(rank);
73 }
74
76
86 int Length(int dimension) const
87 {
88 return static_cast<int>(NativeCall<CExports::cvbint64_t>([this, dimension](CExports::cvbint64_t &value) {
89 return CVB_CALL_CAPI(CVCBufferGetLength(Handle(), static_cast<CExports::cvbdim_t>(dimension), value));
90 }));
91 }
92
94
106 std::intptr_t Increment(int dimension) const
107 {
108 return NativeCall<std::intptr_t>([this, dimension](std::intptr_t &ptr) {
109 return CVB_CALL_CAPI(CVCBufferGetIncrement(Handle(), static_cast<CExports::cvbdim_t>(dimension), ptr));
110 });
111 }
112
113 protected:
114 template <class T, class FN>
115 T NativeCall(const FN &fn) const
116 {
117 T value;
118 const auto result = fn(value);
119 if (result < 0)
120 Utilities::SystemInfo::ThrowLastError(result);
121 return value;
122 }
123 };
124
125 CVB_END_INLINE_NS
126
127} // namespace Cvb
void * Handle() const noexcept
Classic API buffer handle.
Definition buffer_base.hpp:46
int Length(int dimension) const
Gets the number of elements in the given Dimension.
Definition pfnc_buffer.hpp:86
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:68
int PFNCValue() const noexcept
Gets the PFNC value (format identifier) of this buffer.
Definition pfnc_buffer.hpp:53
std::intptr_t Increment(int dimension) const
Gets the increment to the next element in the given Dimension.
Definition pfnc_buffer.hpp:106
T make_shared(T... args)
T move(T... args)
@ InvalidPixelFormat
Invalid pixel format.
Definition pfnc_format.hpp:1050
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::shared_ptr< PFNCBuffer > PFNCBufferPtr
Convenience shared pointer for PFNCBuffer.
Definition global.hpp:70