core/util: move DropEmitter to utils and add generic accessor macros

This commit is contained in:
outfoxxed 2024-07-30 12:19:59 -07:00
parent abc0201f6e
commit 3a8e67e8ab
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
3 changed files with 81 additions and 44 deletions

View file

@ -69,28 +69,3 @@ bool isOpposing(Flags edges);
}; // namespace Edges
Q_DECLARE_OPERATORS_FOR_FLAGS(Edges::Flags);
// NOLINTBEGIN
#define DROP_EMIT(object, func) \
DropEmitter(object, static_cast<void (*)(typeof(object))>([](typeof(object) o) { o->func(); }))
// NOLINTEND
class DropEmitter {
public:
template <class O>
DropEmitter(O* object, void (*signal)(O*))
: object(object)
, signal(*reinterpret_cast<void (*)(void*)>(signal)) {} // NOLINT
DropEmitter() = default;
DropEmitter(DropEmitter&& other) noexcept;
DropEmitter& operator=(DropEmitter&& other) noexcept;
~DropEmitter();
Q_DISABLE_COPY(DropEmitter);
void call();
private:
void* object = nullptr;
void (*signal)(void*) = nullptr;
};