66 if constexpr (std::is_same_v<
Token,
decltype(callback())>) {
68 }
else if constexpr (std::is_convertible_v<
decltype(callback()),
Token>) {
69 return Token(callback());
70 }
else if constexpr (std::is_same_v<void,
decltype(callback())>) {
106 template <
typename Transition>
113 : self_(std::make_shared<model<
Transition>>(std::move(callback))) {}
115 template <
typename T,
typename... Args>
117 : self_(std::make_shared<model<T>>(std::forward<Args>(args)...)) {}
124 friend Token fire(
const Callback &callback) {
125 return callback.self_->fire_();
128 return callback.self_->get_log_();
130 friend bool isSynchronous(
const Callback &callback) {
131 return callback.self_->is_synchronous_();
133 friend void cancel(
const Callback &callback) {
134 return callback.self_->cancel_();
136 friend void pause(
const Callback &callback) {
137 return callback.self_->pause_();
139 friend void resume(
const Callback &callback) {
140 return callback.self_->resume_();
142 auto getEndTime()
const {
143 return self_->end_t_.load(std::memory_order_relaxed);
148 virtual ~concept_t() =
default;
149 virtual Token fire_()
const = 0;
150 virtual Eventlog get_log_()
const = 0;
151 virtual void cancel_()
const = 0;
152 virtual void pause_()
const = 0;
153 virtual void resume_()
const = 0;
154 virtual bool is_synchronous_()
const = 0;
155 mutable std::atomic<Clock::time_point> end_t_{Clock::time_point::min()};
165 template <
typename Transition>
166 struct model final : concept_t {
167 explicit model(Transition &&t) : transition_(std::move(t)) {}
168 template <
typename... Args>
169 model(Args &&...args) : transition_(std::forward<Args>(args)...) {}
171 Token fire_()
const override {
172 auto res =
fire(transition_);
173 end_t_.store(Clock::now(), std::memory_order_relaxed);
176 Eventlog get_log_()
const override {
return getLog(transition_); }
177 void cancel_()
const override {
return cancel(transition_); }
178 bool is_synchronous_()
const override {
return isSynchronous(transition_); }
179 void pause_()
const override {
return pause(transition_); }
180 void resume_()
const override {
return resume(transition_); }
184 std::shared_ptr<const concept_t> self_;
Token fire(const T &callback)
Generates a Token based on what kind of information the Callback returns.
Definition callback.h:65
Eventlog getLog(const T &)
Get the Log object. By default it returns an empty vector.
Definition callback.h:83
bool isSynchronous(const T &)
Checks if the callback is synchronous. Synchronous callbacks are immediately executed inside the Petr...
Definition callback.h:22
void resume(const T &)
Templates a resume action for a Callback. By default it does nothing and not resume the Callback.
Definition callback.h:53
void cancel(const T &)
The default cancel implementation is naive. It only returns a user-exit state and does nothing to the...
Definition callback.h:35
void pause(const T &)
Implements a pause action for a Callback. By default it does nothing and not pause the Callback.
Definition callback.h:44
Callback(Transition callback)
Construct a new Callback object.
Definition callback.h:112
Tokens are elements that can reside in places. Tokens can have a color which makes them distinguishab...
Definition colors.hpp:107
Definition colors.hpp:201
std::vector< Event > Eventlog
Definition types.h:32
std::string Transition
Definition types.h:14