CVB++ 15.0
cancellation_token.hpp
1#pragma once
2
3#include "global.hpp"
4
5namespace Cvb
6{
7
8CVB_BEGIN_INLINE_NS
9
10template <>
11inline HandleGuard<CancellationToken>::HandleGuard(void* handle) noexcept
12 : HandleGuard<CancellationToken>(handle, [](void* handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
13{
14}
15
17
20{
21 friend class CancellationTokenSource;
22 struct PrivateTag {};
23
24public:
25
26 CancellationToken(HandleGuard<CancellationToken>&& guard, PrivateTag) noexcept
27 : handle_(std::move(guard))
28 {
29 }
30
32
38 void* Handle() const noexcept
39 {
40 return handle_.Handle();
41 }
42
44
48 bool IsCanceled() const noexcept
49 {
50 CExports::cvbbool_t status = false;
51 CVB_CALL_CAPI(CVCCancellationTokenIsCanceled(Handle(), status));
52 // suppress VC waring
53 return status != 0;
54 }
55
56private:
57
58 HandleGuard<CancellationToken> handle_;
59
60};
61
62CVB_END_INLINE_NS
63
64}
A token to enable cancellation on wait operations.
Definition: cancellation_token.hpp:20
bool IsCanceled() const noexcept
Check if token has been canceled.
Definition: cancellation_token.hpp:48
void * Handle() const noexcept
Classic API image handle.
Definition: cancellation_token.hpp:38
Provides tokens and signals tokens cancellation.
Definition: cancellation_token_source.hpp:20
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24