This commit is contained in:
Christopher Lackner 2019-08-16 12:52:37 +02:00
parent 25f9069f1e
commit 0ba774b908
3 changed files with 45 additions and 1 deletions

View File

@ -49,7 +49,7 @@ target_link_libraries(ngcore PUBLIC netgen_mpi PRIVATE ${CMAKE_THREAD_LIBS_INIT}
install(FILES ngcore.hpp archive.hpp type_traits.hpp version.hpp ngcore_api.hpp logging.hpp
exception.hpp symboltable.hpp paje_trace.hpp utils.hpp profiler.hpp mpi_wrapper.hpp
array.hpp taskmanager.hpp concurrentqueue.h localheap.hpp python_ngcore.hpp flags.hpp
xbool.hpp
xbool.hpp signal.hpp
DESTINATION ${NG_INSTALL_DIR_INCLUDE}/core COMPONENT netgen_devel)
if(ENABLE_CPP_CORE_GUIDELINES_CHECK)

View File

@ -9,6 +9,7 @@
#include "logging.hpp"
#include "mpi_wrapper.hpp"
#include "profiler.hpp"
#include "signal.hpp"
#include "symboltable.hpp"
#include "taskmanager.hpp"
#include "version.hpp"

43
libsrc/core/signal.hpp Normal file
View File

@ -0,0 +1,43 @@
#ifndef NGCORE_SIGNALS_HPP
#define NGCORE_SIGNALS_HPP
#include <list>
#include <functional>
namespace ngcore
{
template<typename ... ParameterTypes>
class Signal
{
private:
std::list<std::function<bool(ParameterTypes...)>> funcs;
bool is_emitting;
public:
Signal() : is_emitting(true) {}
template<typename Cls, typename FUNC>
void connect(Cls* self, FUNC f)
{
auto ptr = self->weak_from_this();
auto func = [ptr, f](ParameterTypes... args)
{
if (ptr.expired())
return false;
f(args...);
return true;
};
funcs.push_back(func);
}
inline void emit(ParameterTypes ...args)
{
if(is_emitting)
funcs.remove_if([&](auto& f){ return !f(args...); });
}
inline void setEmitting(bool emitting) { is_emitting = emitting; }
inline bool getEmitting() const { return is_emitting; }
};
} // namespace ngcore
#endif // NGCORE_SIGNALS_HPP