1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-21 18:40:01 +00:00

Use std::unique_ptr to implement ScopedLoad

This gives correct implementation of move constructor and assignment operators.
This commit is contained in:
elsid 2022-08-06 16:55:09 +02:00
parent 209550aa84
commit 8125d51a0f
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

View File

@ -2,6 +2,7 @@
#define COMPONENTS_LOADINGLISTENER_H
#include <string>
#include <memory>
namespace Loading
{
@ -33,12 +34,26 @@ namespace Loading
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
struct ScopedLoad
{
ScopedLoad(Listener* l) : mListener(l) { mListener->loadingOn(); }
~ScopedLoad() { mListener->loadingOff(); }
Listener* mListener;
std::unique_ptr<Listener, LoadingOff> mListener;
explicit ScopedLoad(Listener* listener)
: mListener(listener)
{
if (mListener != nullptr)
mListener->loadingOn();
}
};
}