Projekt

Allgemein

Profil

Aktionen

Wiki

Pending signals:

#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>

#include "/home/deseessm/wp/src/canswitch/liblepto/include/lepto/signal.h" 

class CEventLoop
{
   private:
      static CEventLoop* m_first;
      CEventLoop* m_next=nullptr;

   public:
      CEventLoop()
      {
         if(!m_first)
         {
            m_first=this;
         }
         else
         {
            CEventLoop* p=m_first;
            while( p->m_next)
            {
               p=p->m_next;
            }
            p->m_next=this;
         }
      }
      virtual void eventLoop()
      {
         printf("L %p\n", this);
      }
      static void allEventLoops()
      {
         CEventLoop* p=m_first;
         while(p)
         {
            p->eventLoop();
            p=p->m_next;
         }
      }
};

CEventLoop* CEventLoop::m_first = nullptr;
#if 0
template<class... T>
struct Store1
{
   T...[0] t;
};

template<typename... T>
class Store
{
   //struct { T...[0] t; }data;
   T...[0] t;
};

//consteval
auto first_plus_last(auto... args)
{
    return args...[0] + args...[sizeof...(args) - 1];
}

static_assert(first_plus_last(5) == 10);
static_assert(first_plus_last(5, 4) == 9);
static_assert(first_plus_last(5, 6, 2) == 7);
#endif

class CPendingSignal
{
   public:
      CPendingSignal()
      {};
      virtual void emitSignal(){};
};

template<typename T>
class CPendingSignal1: public CPendingSignal
{
      CSignal<void, T> &m_signal;
      T m_p1;
   public:
      CPendingSignal1(CSignal<void, T>& signal, T i1)
         :m_signal(signal)
         ,m_p1(i1)
      {
      }
      virtual void emitSignal();
};

template<typename T1, typename T2>
class CPendingSignal2: public CPendingSignal
{
      CSignal<void, T1, T2> &m_signal;
      T1 m_p1;
      T2 m_p2;
   public:
      constexpr CPendingSignal2(CSignal<void, T1, T2> &signal, T1 i1, T2 i2)
         :m_signal(signal)
         ,m_p1(i1)
         ,m_p2(i2)
      {
      }
      virtual void emitSignal()
      {
         m_signal.emitSignal(m_p1, m_p2);
      }
};

template<typename T1, typename T2, typename T3>
class CPendingSignal3: public CPendingSignal
{
      CSignal<void, T1, T2, T3> &m_signal;
      T1 m_p1;
      T2 m_p2;
      T3 m_p3;
   public:
      constexpr CPendingSignal3(CSignal<void, T1, T2, T3> &signal, T1 i1, T2 i2, T3 i3)
         :m_signal(signal)
         ,m_p1(i1)
         ,m_p2(i2)
         ,m_p3(i3)
      {
      }
      virtual void emitSignal()
      {
         m_signal.emitSignal(m_p1, m_p2, m_p3);
      }
};

template<typename T>
CPendingSignal* XcreatePendingSignal(T p1)
{
   return( new CPendingSignal1<T>(p1) );
};

template<typename T1, typename T2>
CPendingSignal* XcreatePendingSignal(CSignal<void, T1, T2> &sig, T1 p1, T2 p2)
{
   return( new CPendingSignal2<T1, T2>(sig, p1, p2) );
};

template<typename T1, typename T2, typename T3>
CPendingSignal* XcreatePendingSignal(CSignal<void, T1, T2, T3> &sig, T1 p1, T2 p2, T3 p3)
{
   return( new CPendingSignal3<T1, T2, T3>(sig, p1, p2, p3) );
};

enum EColor{
   white, black, grey, green,
};

void show(int i1, int i2, EColor col)
{
   printf("SIGNAL: %d/%d - %d\n", i1, i2, col);
}

int main( int argc, const char *argv[] )
{
   CEventLoop l1;
   CEventLoop l2;
   CEventLoop l3;

   printf( "Size: %d\n", sizeof(l1) );
   printf( "Size ptr: %d\n", sizeof(argv[0]) );
   printf( "Size pend: %d\n", sizeof(CPendingSignal2<int, int>) );

   CSignal<void, int, int, EColor> sig1;
   sig1.connect( &show );
   CPendingSignal* ps1=XcreatePendingSignal<int, int, EColor>(sig1, 1,2, black);
   //CPendingSignal* ps2=createPendingSignal(sig1, 123,456, 0);
   CPendingSignal* ps2 = sig1.createPendingSignal(123,456, white);

   printf("-------------------\n");
   ps1->emitSignal();
   ps2->emitSignal();

   CEventLoop::allEventLoops();
   return(0);
}

//---fin----------------------------------------------------------------------

Von Maximilian Seesslen vor etwa 2 Monaten aktualisiert · 1 Revisionen