//Event driver
#include "cl_event.h"
void EVENT_DRIVER::init()
{
ev.clear();
todo.clear();
src.clear();
dst.clear();
code.clear();
}
void EVENT_DRIVER::reg(string name, string func)
{
deque d;
d = ev[name];
d.push_back(func);
ev[name] = d;
}
string EVENT_DRIVER::get_name() //returns name of EVENT
{
if(!todo.empty()) {
return todo[0];
} else {
return "";
}
}
string EVENT_DRIVER::get_src()
{
if(!src.empty()) {
return src[0];
} else {
return "";
}
}
string EVENT_DRIVER::get_dst()
{
if(!dst.empty()) {
return dst[0];
} else {
return "";
}
}
deque EVENT_DRIVER::get()
{
string name = "";
if(!todo.empty()) {
name = todo[0];
todo.pop_front();
src.pop_front();
code.pop_front();
}
return ev[name];
}
int EVENT_DRIVER::get_code()
{
if(!code.empty()) {
return code[0];
} else {
return 0;
}
}
int EVENT_DRIVER::todo_empty()
{
return todo.empty();
}
void EVENT_DRIVER::add(string name)
{
todo.push_back(name);
src.push_back("");
dst.push_back("");
code.push_back(0);
}
void EVENT_DRIVER::add(string name, string source)
{
todo.push_back(name);
src.push_back(source);
dst.push_back("");
code.push_back(0);
}
void EVENT_DRIVER::add(string name, string source, string dest)
{
todo.push_back(name);
src.push_back(source);
dst.push_back(dest);
code.push_back(0);
}
void EVENT_DRIVER::add(int c)
{
todo.push_back("");
src.push_back("");
dst.push_back("");
code.push_back(c);
}
void EVENT_DRIVER::execute(LUA_WRAPPER *lw)
{
string e;
deque d;
deque::iterator i;
while(!todo_empty()) {
e = get_name();
d = get();
for(i=d.begin(); i!=d.end(); i++) {
// message("Executing: %s",i->c_str());
lw->exec((char*)i->c_str());
}
}
}
int EVENT_DRIVER::pop_code()
{
int i;
i = get_code();
get();
return i;
}
Generated by: georgik on armada on Sat Jul 24 07:07:15 2004, using kdoc 2.0a54. |