mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 19:41:51 +00:00
add observer_handler class
This commit is contained in:
parent
b3feb5945b
commit
3beafe953f
6 changed files with 72 additions and 13 deletions
|
|
@ -3,20 +3,39 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "util/observer_handler.hpp"
|
||||
|
||||
namespace util {
|
||||
/// @brief Keeps shared pointers alive until destruction
|
||||
class ObjectsKeeper {
|
||||
std::vector<std::shared_ptr<void>> ptrs;
|
||||
std::vector<observer_handler> handlers;
|
||||
public:
|
||||
ObjectsKeeper() = default;
|
||||
|
||||
ObjectsKeeper(const ObjectsKeeper&) = delete;
|
||||
|
||||
ObjectsKeeper(ObjectsKeeper&& keeper) noexcept
|
||||
: ptrs(std::move(keeper.ptrs)),
|
||||
handlers(std::move(keeper.handlers)) {
|
||||
}
|
||||
|
||||
ObjectsKeeper& operator=(ObjectsKeeper&& keeper) noexcept = default;
|
||||
|
||||
virtual ~ObjectsKeeper() {
|
||||
}
|
||||
|
||||
virtual void keepAlive(std::shared_ptr<void> ptr) {
|
||||
ptrs.push_back(ptr);
|
||||
ptrs.push_back(std::move(ptr));
|
||||
}
|
||||
|
||||
virtual void keepAlive(observer_handler&& ptr) {
|
||||
handlers.emplace_back(std::move(ptr));
|
||||
}
|
||||
|
||||
virtual void clearKeepedObjects() {
|
||||
ptrs.clear();
|
||||
handlers.clear();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue