CVB++ 14.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:
24
26
32 void* Handle() const noexcept
33 {
34 return handle_.Handle();
35 }
36
38
45 static std::shared_ptr<HandleOnly> FromHandle(HandleGuard<HandleOnly>&& guard)
46 {
47 if (!guard.Handle())
48 throw std::runtime_error("handle must not be null");
49
50 return std::shared_ptr<HandleOnly>(new HandleOnly(std::move(guard)));
51 }
52
53
54 private:
55
56 HandleOnly(HandleGuard<HandleOnly>&& guard) noexcept
57 : handle_(std::move(guard))
58 {
59 }
60
61 HandleGuard<HandleOnly> handle_;
62
63 };
64
65 CVB_END_INLINE_NS
66}
67
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:45
void * Handle() const noexcept
Classic API node handle.
Definition: handle_only.hpp:32
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24