Bifrost SDK
Bifrost SDK documentation
StopToken.h
Go to the documentation of this file.
1//-
2// =============================================================================
3// Copyright 2024 Autodesk, Inc. All rights reserved.
4//
5// Use of this software is subject to the terms of the Autodesk license
6// agreement provided at the time of installation or download, or which
7// otherwise accompanies this software in either electronic or hard copy form.
8// =============================================================================
9
10//+
11
13
14#ifndef AMINO_CORE_STOP_TOKEN_H
15#define AMINO_CORE_STOP_TOKEN_H
16
18
20
21#include <Amino/Core/internal/PImpl.h>
22#include <Amino/Core/internal/StopCallbackDetails.h>
23
24#define AMINO_API AMINO_CORE_SHARED_DECL
25namespace Amino {
26
27//=============================================================================
28// CLASS NoStopState_t
29//=============================================================================
30
35 explicit NoStopState_t() = default;
36};
37
38//=============================================================================
39// CLASS StopToken
40//=============================================================================
41
45class StopToken {
46public:
51 AMINO_API StopToken() noexcept;
52
55
58
61
63 AMINO_API StopToken& operator=(StopToken&& o) noexcept;
64
66 AMINO_API StopToken& operator=(StopToken const& o);
67
70 friend bool operator==(StopToken const& lhs, StopToken const& rhs) {
71 return lhs.internal_equals(rhs);
72 }
73 friend bool operator!=(StopToken const& lhs, StopToken const& rhs) {
74 return !lhs.internal_equals(rhs);
75 }
77
81
86 AMINO_API bool stopPossible() const;
87
88private:
90
92 AMINO_API bool internal_equals(StopToken const& o) const;
93
95 Internal::PImpl<StopToken, 1> m_impl;
96
98};
99
100//=============================================================================
101// CLASS StopSource
102//=============================================================================
103
108public:
111
116
119
122
125
128
131
134 friend bool operator==(StopSource const& lhs, StopSource const& rhs) {
135 return lhs.internal_equals(rhs);
136 }
137 friend bool operator!=(StopSource const& lhs, StopSource const& rhs) {
138 return !lhs.internal_equals(rhs);
139 }
141
144 AMINO_API StopToken getToken() const noexcept;
145
150 AMINO_API void requestStop() noexcept;
151
154
160
161private:
163
165 AMINO_API bool internal_equals(StopSource const& o) const;
166
168 Internal::PImpl<StopSource, 1> m_impl;
169
171};
172
173//==============================================================================
174// CLASS StopCallback
175//==============================================================================
176
180template <typename Callback>
181class StopCallback : private Internal::StopCallbackImpl<Callback> {
182public:
185 template <typename C>
186 StopCallback(StopToken const& token, C&& cb)
187 : Internal::StopCallbackImpl<Callback>{token, std::forward<C>(cb)} {}
188
189 template <typename C>
190 StopCallback(StopToken&& token, C&& cb)
191 : Internal::StopCallbackImpl<Callback>{
192 std::move(token), std::forward<C>(cb)} {}
194
197 StopCallback(StopCallback const&) = delete;
198 StopCallback(StopCallback&&) noexcept = delete;
199 StopCallback& operator=(StopCallback const&) = delete;
200 StopCallback& operator=(StopCallback&&) noexcept = delete;
202
204 ~StopCallback() = default;
205};
206
207//------------------------------------------------------------------------------
208//
211template <typename Callback>
212StopCallback(StopToken const&, Callback) -> StopCallback<Callback>;
213template <typename Callback>
214StopCallback(StopToken&&, Callback) -> StopCallback<Callback>;
216
217} // namespace Amino
218#undef AMINO_API
219
220#endif
Definition of macros for symbol visibility.
#define AMINO_API
Definition: StopToken.h:24
Forward declaration of classes in StopToken.h.
Definition: HostData.h:33
A tag type to indicate that a StopSource should be created without a valid state (such StopSource can...
Definition: StopToken.h:34
A token that can be used to check if a stop has been requested.
Definition: StopToken.h:45
AMINO_CORE_SHARED_DECL bool stopRequested() const
Check if a stop has been requested on the StopSource that was used to create this StopToken.
AMINO_CORE_SHARED_DECL bool stopPossible() const
Check if a stop can be requested on the StopSource that was used to create this StopToken.
friend bool operator!=(StopToken const &lhs, StopToken const &rhs)
Equality operators.
Definition: StopToken.h:73
AMINO_CORE_SHARED_DECL StopToken() noexcept
Default constructor (constructs an invalid StopToken that can't be stopped).
A source that can be used to request a stop.
Definition: StopToken.h:107
AMINO_CORE_SHARED_DECL StopSource & operator=(StopSource const &o)
Copy assignment operator.
AMINO_CORE_SHARED_DECL bool stopRequested() const
Check if a stop has been requested for this StopSource.
AMINO_CORE_SHARED_DECL StopSource(NoStopState_t) noexcept
Construct a non-stoppable StopSource.
AMINO_CORE_SHARED_DECL StopToken getToken() const noexcept
Get a StopToken that can be used to check if a stop has been requested from this StopSource.
AMINO_CORE_SHARED_DECL StopSource()
Default constructor (constructs a valid StopSource).
AMINO_CORE_SHARED_DECL StopSource(StopSource const &o)
Copy constructor.
AMINO_CORE_SHARED_DECL ~StopSource()
Destructor.
AMINO_CORE_SHARED_DECL StopSource & operator=(StopSource &&o) noexcept
Move assignment operator.
friend bool operator==(StopSource const &lhs, StopSource const &rhs)
Equality operators.
Definition: StopToken.h:134
AMINO_CORE_SHARED_DECL void requestStop() noexcept
Request a stop.
AMINO_CORE_SHARED_DECL StopSource(StopSource &&o) noexcept
Move constructor.
friend bool operator!=(StopSource const &lhs, StopSource const &rhs)
Equality operators.
Definition: StopToken.h:137
AMINO_CORE_SHARED_DECL bool stopPossible() const
Check if a stop can be requested for this StopSource.
A callback that can be attached to a StopToken.
Definition: StopToken.h:181
StopCallback(StopCallback &&) noexcept=delete
StopCallback is not copyable nor movable.
StopCallback(StopToken &&token, C &&cb)
Constructor.
Definition: StopToken.h:190
StopCallback(StopToken const &token, C &&cb)
Constructor.
Definition: StopToken.h:186
StopCallback(StopCallback const &)=delete
StopCallback is not copyable nor movable.