Use std::unique_ptr to implement ScopedLoad

This gives correct implementation of move constructor and assignment operators.
crashfix_debugdraw
elsid 2 years ago
parent 209550aa84
commit 8125d51a0f
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -2,6 +2,7 @@
#define COMPONENTS_LOADINGLISTENER_H #define COMPONENTS_LOADINGLISTENER_H
#include <string> #include <string>
#include <memory>
namespace Loading namespace Loading
{ {
@ -33,12 +34,26 @@ namespace Loading
virtual ~Listener() = default; virtual ~Listener() = default;
}; };
struct LoadingOff
{
void operator()(Listener* listener) const
{
if (listener != nullptr)
listener->loadingOff();
}
};
/// @brief Used for stopping a loading sequence when the object goes out of scope /// @brief Used for stopping a loading sequence when the object goes out of scope
struct ScopedLoad struct ScopedLoad
{ {
ScopedLoad(Listener* l) : mListener(l) { mListener->loadingOn(); } std::unique_ptr<Listener, LoadingOff> mListener;
~ScopedLoad() { mListener->loadingOff(); }
Listener* mListener; explicit ScopedLoad(Listener* listener)
: mListener(listener)
{
if (mListener != nullptr)
mListener->loadingOn();
}
}; };
} }

Loading…
Cancel
Save