mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-26 22:00:33 +05:00
signals
This commit is contained in:
parent
25f9069f1e
commit
0ba774b908
@ -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
|
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
|
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
|
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)
|
DESTINATION ${NG_INSTALL_DIR_INCLUDE}/core COMPONENT netgen_devel)
|
||||||
|
|
||||||
if(ENABLE_CPP_CORE_GUIDELINES_CHECK)
|
if(ENABLE_CPP_CORE_GUIDELINES_CHECK)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "logging.hpp"
|
#include "logging.hpp"
|
||||||
#include "mpi_wrapper.hpp"
|
#include "mpi_wrapper.hpp"
|
||||||
#include "profiler.hpp"
|
#include "profiler.hpp"
|
||||||
|
#include "signal.hpp"
|
||||||
#include "symboltable.hpp"
|
#include "symboltable.hpp"
|
||||||
#include "taskmanager.hpp"
|
#include "taskmanager.hpp"
|
||||||
#include "version.hpp"
|
#include "version.hpp"
|
||||||
|
43
libsrc/core/signal.hpp
Normal file
43
libsrc/core/signal.hpp
Normal 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
|
Loading…
Reference in New Issue
Block a user