mirror of
https://github.com/NGSolve/netgen.git
synced 2025-02-03 16:50:34 +05:00
simple signal without smart pointers
This commit is contained in:
parent
696620828f
commit
29f0a5d647
@ -2,6 +2,7 @@
|
|||||||
#define NGCORE_SIGNALS_HPP
|
#define NGCORE_SIGNALS_HPP
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <map>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
namespace ngcore
|
namespace ngcore
|
||||||
@ -43,6 +44,36 @@ namespace ngcore
|
|||||||
}
|
}
|
||||||
inline bool GetEmitting() const { return is_emitting; }
|
inline bool GetEmitting() const { return is_emitting; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class SimpleSignal
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::map<void*,std::function<void()>> funcs;
|
||||||
|
public:
|
||||||
|
SimpleSignal() = default;
|
||||||
|
|
||||||
|
template<typename FUNC>
|
||||||
|
void Connect(void* var, FUNC f)
|
||||||
|
{
|
||||||
|
funcs[var] = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Remove(void* var)
|
||||||
|
{
|
||||||
|
funcs.erase(var);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Emit()
|
||||||
|
{
|
||||||
|
for (auto [key,f] : funcs)
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace ngcore
|
} // namespace ngcore
|
||||||
|
|
||||||
#endif // NGCORE_SIGNALS_HPP
|
#endif // NGCORE_SIGNALS_HPP
|
||||||
|
Loading…
Reference in New Issue
Block a user