Is there a way to connect the gain signal directly to another signal?

I was wondering if there is a more convenient way to connect the Boost signal of one class directly to the signal of another class?

For example, imagine a facade class with a bunch of members that provide their own signals. Now suppose the facade wants to expose these signals. I usually end up writing template methods, which I then hook up as signal handlers.

using namespace boost::signal; class A { public: A(){}; virtual ~A(){}; signal<void()> signalA; }; class B { public: B(){}; virtual ~B(){}; signal<void()> signalB; }; class Facade { private: A& a; B& b; public: Facade(A& refA, B& refB) : a(refA), b(refB) { // connect A signal to facadeSignalA a.signalA.connect(boost::bind(&Facade::forwardedSignalA, this)); // connect B signal to facadeSignalB b.signalB.connect(boost::bind(&Facade::forwardedSignalB, this)); } virtual ~Facade() {}; // user visible signals signal<void()> facadeSignalA; signal<void()> facadeSignalB; private: // ugly boilerplate code used to forward signals void forwardedSignalA() { facadeSignalA(); } void forwardedSignalB() { facadeSignalB(); } }; 

Now it is not very elegant and becomes very tiring after. Is there any way to do this without having to write such forwarding methods?

+7
source share
1 answer

Yes, it turns out that you can β€œhook” the signals directly. See this thread . This is undocumented, but it is a very useful feature.

+7
source

All Articles