CVB++ 15.0
handle_only.hpp
1#pragma once
2
3#include <memory>
4
5#include "exception.hpp"
6#include "global.hpp"
7
8namespace Cvb
9{
10 CVB_BEGIN_INLINE_NS
11
12 template <>
13 inline HandleGuard<HandleOnly>::HandleGuard(void *handle) noexcept
14 : HandleGuard<HandleOnly>(handle, [](void *handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
15 {
16 }
17
19
20 class HandleOnly final
21 {
22
23 public:
25
31 void *Handle() const noexcept
32 {
33 return handle_.Handle();
34 }
35
37
44 static std::shared_ptr<HandleOnly> FromHandle(HandleGuard<HandleOnly> &&guard)
45 {
46 if (!guard.Handle())
47 throw std::runtime_error("handle must not be null");
48
49 return std::shared_ptr<HandleOnly>(new HandleOnly(std::move(guard)));
50 }
51
52 private:
53 explicit HandleOnly(HandleGuard<HandleOnly> &&guard) noexcept
54 : handle_(std::move(guard))
55 {
56 }
57
58 HandleGuard<HandleOnly> handle_;
59 };
60
61 CVB_END_INLINE_NS
62} // namespace Cvb
HandleOnly class is as it says a handle only.
Definition handle_only.hpp:21
static std::shared_ptr< HandleOnly > FromHandle(HandleGuard< HandleOnly > &&guard)
Creates a handle only from a classic API handle.
Definition handle_only.hpp:44
void * Handle() const noexcept
Classic API node handle.
Definition handle_only.hpp:31
cvbbool_t ReleaseObject(OBJ &Object)
T move(T... args)
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17