00001 #ifndef CAFE_FUNCTION_HPP__ 00002 #define CAFE_FUNCTION_HPP__ 00003 00004 #include <map> 00005 #include "cafe/Processor.hpp" 00006 00007 namespace cafe { 00008 00009 class Event; 00010 00023 class Function : public Processor { 00024 public: 00025 typedef bool (*FUNC)(cafe::Event&); 00026 00027 public: 00028 Function(const char *name); 00029 Function(const std::string& name, FUNC func); 00030 00031 // overrides Processor interface 00032 virtual bool processEvent(Event &event); 00033 00034 // Helper class to register a function 00035 class Register { 00036 public: 00037 Register(const char *name, FUNC func); 00038 }; 00039 00040 private: 00041 FUNC _func; 00042 00043 friend class Function::Register; 00044 00045 typedef std::map<std::string,FUNC> Map; 00046 static Map& getMap(); 00047 00048 public: 00049 ClassDef(Function, 0); 00050 }; 00051 } 00052 00053 #define CAFE_FUNCTION(func) namespace { cafe::Function::Register reg_##func(#func,func); } 00054 00055 #endif // CAFE_FUNCTION_HPP__
1.3.4