Last active
August 29, 2015 14:23
-
-
Save willir/44b15bb0d498b5139999 to your computer and use it in GitHub Desktop.
LambdaSlot for sigslot library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sigslot/sigslot.h> | |
#include <functional> | |
template <class arg1, class mt_policy = SIGSLOT_DEFAULT_MT_POLICY> | |
class Slot1 : public sigslot::has_slots<mt_policy> { | |
public: | |
template<class Functor> | |
Slot1(const Functor &fun) : mFun(fun) {} | |
Slot1(std::function<void(arg1)> &&fun) : mFun(fun) {} | |
void slot(arg1 val1) { mFun(val1); } | |
template<class mt_policy_for_signal = SIGSLOT_DEFAULT_MT_POLICY> | |
void connect(sigslot::signal1<arg1, mt_policy_for_signal> &signal) { | |
signal.connect(this, &LambdaSlots::Slot1<arg1, mt_policy>::slot); | |
} | |
private: | |
const std::function<void(arg1)> mFun; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sigslot/sigslot.h> | |
#include <functional> | |
/** | |
* Class for creation slot using lambda for sigslot library | |
*/ | |
template <typename ...Args> | |
class LambdaSlots : public sigslot::has_slots<> { | |
public: | |
template<class Functor> | |
LambdaSlots(const Functor &fun) : mFun(fun) {} | |
LambdaSlots(std::function<void(Args...)> &&fun) : mFun(fun) {} | |
void slot(Args... values) { mFun(values...); } | |
template<class Signal> | |
void connect(Signal &signal) { | |
signal.connect(this, &LambdaSlots<Args...>::slot); | |
} | |
private: | |
const std::function<void(Args...)> mFun; | |
}; | |
//------------------------------- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment