Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

Function.cpp

Go to the documentation of this file.
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         // ok, now try to find the function somewhere
00015         // in the loaded libraries...
00016 
00017         _func = getMap()[name];
00018         if(_func == 0) {
00019             std::string msg("Function: Cannot load function: ");
00020             msg += name;
00021             // err() << msg << std::endl;
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 

Generated on Tue Mar 28 10:13:04 2006 for CAF by doxygen 1.3.4