00001
00002 #include "cafe/Function.hpp"
00003
00004 #include <iostream>
00005 #include <sstream>
00006 #include <stdexcept>
00007 #include <cstdlib>
00008
00009 namespace cafe {
00010
00011 Function::Function(const char *name)
00012 : Processor(name)
00013 {
00014
00015
00016
00017 _func = getMap()[name];
00018 if(_func == 0) {
00019 std::string msg("Function: Cannot load function: ");
00020 msg += name;
00021
00022 throw std::runtime_error(msg);
00023 }
00024 }
00025
00026 Function::Function(const std::string& name, bool (*func)(Event&))
00027 : Processor(name.c_str()),
00028 _func(func)
00029 {
00030 }
00031
00032
00033 bool Function::processEvent(cafe::Event& event)
00034 {
00035 if(_func) {
00036 return _func(event);
00037 } else {
00038 err() << "cafe::Function: FATAL: function not found: " << name() << std::endl;
00039 abort();
00040 }
00041 }
00042
00043 Function::Map& Function::getMap()
00044 {
00045 static Map s_map;
00046 return s_map;
00047 }
00048
00049
00050 Function::Register::Register(const char *name, FUNC func)
00051 {
00052 getMap()[name] = func;
00053 }
00054 }
00055
00056 ClassImp(cafe::Function)
00057