0

I have a class containing a large number (~100 or more) signals with varying signatures:

class MyClass
{
public:
    boost::signals2::signal<void()>& Signal1();
    boost::signals2::signal<int()>& Signal2();
    boost::signals2::signal<void(std::string&)>& Signal3();
    // etc.
    // etc.
};

(Yes, its "yahw" - yet another HWND wrapper. Please refrain from commenting on the meaning of this plan ;-) )

Of course the signals are sparsely used, and I don't want to have data member for each unused signal.

Question:
How do I efficiently manage the creation and destruction of actually required signal instances?
My general idea is to add the signal to a map when the 1st slots connects, and to remove the signal when the last slot disconnects. However, boost::signals2::signal::connect etc. are not virtual, so inheriting a custom signal class does not work the naive way. How can I track slots connecting / disconnecting?

cdoubleplusgood
  • 1,309
  • 1
  • 11
  • 12
  • Did you figure something out yet for this? –  Sep 23 '13 at 14:13
  • @KevinCadieux: Kind of... I wrote a type erasure wrapper for the signals to put them in a map; the map is created on the 1st connect and deleted when the last slot disconnects. The unpleasant thing is that I have to dynamic_cast when getting a signal from the map, specifying the correct function signature. Oh, and I expose a connect / disconnect method for each signal, but the actual signal is not available in the window class so I can track the slots. – cdoubleplusgood Sep 23 '13 at 15:26
  • Which version of C++ are you using? –  Sep 23 '13 at 15:44

0 Answers0