33 lines
695 B
C++
33 lines
695 B
C++
#pragma once
|
|
|
|
#include <td/misc/Signal.h>
|
|
|
|
namespace td {
|
|
namespace utils {
|
|
|
|
/**
|
|
* \brief Wrapper class to automatically disconnect from a Signal on object destruction
|
|
* \note You should inherit this class privately
|
|
* \sa Signal
|
|
*/
|
|
class SlotGuard {
|
|
private:
|
|
std::vector<std::unique_ptr<Connection>> m_Connections;
|
|
|
|
public:
|
|
/**
|
|
* \brief Connect a signal to a function (with the same signature)
|
|
*/
|
|
template <typename... Args>
|
|
void Connect(Signal<Args...> a_Signal, const typename Signal<Args...>::CallBack& a_Callback) {
|
|
m_Connections.push_back(a_Signal.ConnectSafe(a_Callback));
|
|
}
|
|
|
|
void Disconnect() {
|
|
m_Connections.clear();
|
|
}
|
|
};
|
|
|
|
} // namespace utils
|
|
} // namespace td
|