#pragma once #include 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> m_Connections; public: /** * \brief Connect a signal to a function (with the same signature) */ template void Connect(Signal a_Signal, const typename Signal::CallBack::element_type& a_Callback) { auto ptr = std::make_shared::CallBack::element_type>(a_Callback); m_Connections.push_back(a_Signal.ConnectSafe(ptr)); } void Disconnect() { m_Connections.clear(); } }; } // namespace utils } // namespace td