2018-03-18 11:32:45 +00:00
|
|
|
#ifndef OPENMW_MWPHYSICS_PTRHOLDER_H
|
|
|
|
#define OPENMW_MWPHYSICS_PTRHOLDER_H
|
|
|
|
|
2020-12-18 19:40:27 +00:00
|
|
|
#include <mutex>
|
|
|
|
|
2018-03-18 11:32:45 +00:00
|
|
|
#include "../mwworld/ptr.hpp"
|
|
|
|
|
|
|
|
namespace MWPhysics
|
|
|
|
{
|
|
|
|
class PtrHolder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~PtrHolder() {}
|
|
|
|
|
|
|
|
void updatePtr(const MWWorld::Ptr& updated)
|
|
|
|
{
|
2020-12-18 19:40:27 +00:00
|
|
|
std::scoped_lock lock(mMutex);
|
2018-03-18 11:32:45 +00:00
|
|
|
mPtr = updated;
|
|
|
|
}
|
|
|
|
|
|
|
|
MWWorld::Ptr getPtr()
|
|
|
|
{
|
2020-12-18 19:40:27 +00:00
|
|
|
std::scoped_lock lock(mMutex);
|
2018-03-18 11:32:45 +00:00
|
|
|
return mPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
MWWorld::ConstPtr getPtr() const
|
|
|
|
{
|
2020-12-18 19:40:27 +00:00
|
|
|
std::scoped_lock lock(mMutex);
|
2018-03-18 11:32:45 +00:00
|
|
|
return mPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
MWWorld::Ptr mPtr;
|
2020-12-18 19:40:27 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
mutable std::mutex mMutex;
|
2018-03-18 11:32:45 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|