MultiSignals

Files CCore/inc/MultiSignal.h CCore/src/MultiSignal.cpp

MultiSignal is a group of signals. They are combined using the class Optional. This construction is useful if you have an object with number of signals, but only a small subset of them are practically used. Only a signal being subscribed is constructed as an object.

MultiSignal

Particular signals are identified by slot numbers.


class MultiSignal : NoCopy
 {
   ....
   
  public:
  
   explicit MultiSignal(ulen max_slot);
   
   ~MultiSignal();

   template <unsigned slot,class ... TT>
   void assert(TT... tt);
   
   template <unsigned slot,class ... TT>
   Signal<TT...> & take();
 };

max_slot is a maximum slot number.

assert() asserts the given signal. You must always use the same combination of the slot and the argument type list in all methods. If the signal has not been constructed the method has no effect.

take() takes particular signal. If the signal has not been constructed, it is constructed.

It is recommended to hide the class MultiSignal behind some facade class.


class SignallingClass
 {
   MultiSignal msignal;

   ....

  public:

   SignallingClass() : msignal(99) {}

   // 100 signals

   void assertSignal0(int a) { msignal.assert<0,int>(a); }

   Signal<int> & takeSignal0() { return msignal.take<0,int>(); } 

   void assertSignal1(int a,int b) { msignal.assert<1,int,int>(a,b); }

   Signal<int,int> & takeSignal1() { return msignal.take<1,int,int>(); } 

   ....
 };

DeferMultiSignal

DeferMultiSignal extends the MultiSignal by two methods. They can be used to post a signal assertion into a DeferCall processing loop. Remember, arguments are copied and used later.


class DeferMultiSignal : public MultiSignal
 {
   ....
   
  public:
  
   explicit DeferMultiSignal(unsigned max_slot);
   
   ~DeferMultiSignal();
   
   template <unsigned slot,class ... TT>
   void post(const TT & ... tt);
   
   template <unsigned slot,class ... TT>
   void post_first(const TT & ... tt);
   
   template <unsigned slot,class ... TT>
   void try_post(const TT & ... tt);
   
   template <unsigned slot,class ... TT>
   void try_post_first(const TT & ... tt);
 };