mirror of
https://github.com/enduro2d/enduro2d.git
synced 2026-01-06 11:51:00 +07:00
DEFER: add dismiss functional
This commit is contained in:
@@ -13,49 +13,54 @@ namespace e2d
|
|||||||
namespace impl
|
namespace impl
|
||||||
{
|
{
|
||||||
template < typename F >
|
template < typename F >
|
||||||
class defer_impl final : noncopyable {
|
class defer_impl : noncopyable {
|
||||||
public:
|
public:
|
||||||
explicit defer_impl(F f)
|
explicit defer_impl(F f)
|
||||||
: f_(std::move(f)) {}
|
: f_(std::move(f)) {}
|
||||||
|
|
||||||
~defer_impl() noexcept {
|
virtual ~defer_impl() noexcept {
|
||||||
f_();
|
if ( !dismissed_ ) {
|
||||||
}
|
|
||||||
private:
|
|
||||||
F f_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template < typename F >
|
|
||||||
class error_defer_impl final : noncopyable {
|
|
||||||
public:
|
|
||||||
explicit error_defer_impl(F f)
|
|
||||||
: f_(std::move(f))
|
|
||||||
, exceptions_(std::uncaught_exceptions()) {}
|
|
||||||
|
|
||||||
~error_defer_impl() noexcept {
|
|
||||||
if ( exceptions_ != std::uncaught_exceptions() ) {
|
|
||||||
f_();
|
f_();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dismiss() noexcept {
|
||||||
|
dismissed_ = true;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
F f_;
|
||||||
|
bool dismissed_{};
|
||||||
|
};
|
||||||
|
|
||||||
|
template < typename F >
|
||||||
|
class error_defer_impl final : public defer_impl<F> {
|
||||||
|
public:
|
||||||
|
explicit error_defer_impl(F f)
|
||||||
|
: defer_impl<F>(std::move(f))
|
||||||
|
, exceptions_(std::uncaught_exceptions()) {}
|
||||||
|
|
||||||
|
~error_defer_impl() noexcept final {
|
||||||
|
if ( exceptions_ == std::uncaught_exceptions() ) {
|
||||||
|
this->dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
F f_{};
|
|
||||||
int exceptions_{};
|
int exceptions_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
template < typename F >
|
template < typename F >
|
||||||
class return_defer_impl final : noncopyable {
|
class return_defer_impl final : public defer_impl<F> {
|
||||||
public:
|
public:
|
||||||
explicit return_defer_impl(F f)
|
explicit return_defer_impl(F f)
|
||||||
: f_(std::move(f))
|
: defer_impl<F>(std::move(f))
|
||||||
, exceptions_(std::uncaught_exceptions()) {}
|
, exceptions_(std::uncaught_exceptions()) {}
|
||||||
|
|
||||||
~return_defer_impl() noexcept {
|
~return_defer_impl() noexcept final {
|
||||||
if ( exceptions_ == std::uncaught_exceptions() ) {
|
if ( exceptions_ != std::uncaught_exceptions() ) {
|
||||||
f_();
|
this->dismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
F f_{};
|
|
||||||
int exceptions_{};
|
int exceptions_{};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user