home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ Games Programming
/
CPPGAMES.ISO
/
thx
/
source
/
theatrix
/
handler.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-26
|
1KB
|
64 lines
#include "theatrix.h"
#include "handler.h"
class Hand;
//-------------------------------------------------------------------
//------------------------------------------ EventHandler -----------
void EventHandler::add(Hand* h,callback cb)
{
subscription* addition = new subscription(h, cb);
slist.AppendEntry(addition);
}
void EventHandler::del(Hand* hand,callback cb)
{
subscription* ptr=slist.FirstEntry();
while (ptr)
{
if (ptr->hand==hand && (cb==0 || ptr->cb==cb))
{
slist.RemoveEntry();
delete ptr;
}
ptr = slist.NextEntry();
}
}
void EventHandler::delHand(Hand* h)
{
del(h,0);
}
void EventHandler::execute_callbacks(int p1, int p2, int p3)
{
Hand* h;
callback cb;
subscription *ptr=slist.FirstEntry();
while (ptr)
{
h=ptr->hand;
cb=ptr->cb;
ptr=slist.NextEntry(); // take next node address BEFORE callback
(h->*cb)(p1, p2, p3); // execute callback
}
}
void EventHandler::reset()
{
subscription *ptr=slist.FirstEntry();
while (ptr)
{
slist.RemoveEntry();
delete ptr;
ptr=slist.NextEntry();
}
}
int EventHandler::getnum()
{
return slist.EntryCount();
}