home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / source / theatrix / handler.cpp < prev    next >
C/C++ Source or Header  |  1995-04-26  |  1KB  |  64 lines

  1. #include "theatrix.h"
  2. #include "handler.h"
  3.  
  4.  
  5. class Hand;
  6.  
  7. //-------------------------------------------------------------------
  8. //------------------------------------------ EventHandler -----------
  9. void EventHandler::add(Hand* h,callback cb)
  10.   {
  11.   subscription* addition = new subscription(h, cb);
  12.   slist.AppendEntry(addition);
  13.   }
  14.  
  15. void EventHandler::del(Hand* hand,callback cb)
  16.   {
  17.   subscription* ptr=slist.FirstEntry();
  18.   while (ptr)
  19.     {
  20.     if (ptr->hand==hand && (cb==0 || ptr->cb==cb))
  21.       {
  22.       slist.RemoveEntry();
  23.       delete ptr;
  24.       }
  25.     ptr = slist.NextEntry();
  26.     }
  27.   }
  28.  
  29. void EventHandler::delHand(Hand* h)
  30.   {
  31.   del(h,0);
  32.   }
  33.  
  34. void EventHandler::execute_callbacks(int p1, int p2, int p3)
  35.   {
  36.   Hand* h;
  37.   callback cb;
  38.   subscription *ptr=slist.FirstEntry();
  39.   while (ptr)
  40.     {
  41.     h=ptr->hand;
  42.     cb=ptr->cb;
  43.     ptr=slist.NextEntry(); // take next node address BEFORE callback
  44.     (h->*cb)(p1, p2, p3);  // execute callback
  45.     }
  46.   }
  47.  
  48. void EventHandler::reset()
  49.   {
  50.   subscription *ptr=slist.FirstEntry();
  51.   while (ptr)
  52.     {
  53.     slist.RemoveEntry();
  54.     delete ptr;
  55.     ptr=slist.NextEntry();
  56.     }
  57.   }
  58.  
  59. int EventHandler::getnum()
  60.   {
  61.   return slist.EntryCount();
  62.   }
  63.  
  64.