]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Dispatcher.hh
new lua scripting for scene loading
[chaz/yoink] / src / Moof / Dispatcher.hh
index a152691a8184d170d62890df2fb72dbc51959dc2..bbce87872e67e1afdcf0b0c21b19f9ff56a83fd3 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <string>
 
+#include <boost/bind.hpp>
 #include <boost/function.hpp>
 #include <boost/shared_ptr.hpp>
 
@@ -45,7 +46,7 @@ namespace Mf {
 class Notification
 {
 public:
-       virtual ~Notification();
+       virtual ~Notification() {};
 };
 
 
@@ -55,7 +56,14 @@ public:
 
 class Dispatcher
 {
+       class Impl;
+       boost::shared_ptr<Impl> impl_;
+
 public:
+
+       // TODO - the Handler would be even better as an object which automagically
+       // removes itself from the dispatcher on destruction, so users don't have to
+       // worry about forgetting
        typedef void* Handler;
        typedef boost::function<void(const Notification*)> Function;
 
@@ -72,13 +80,36 @@ public:
        void removeHandler(Handler id);
 
        void dispatch(const std::string& message, const Notification* param = 0);
-
-private:
-       class Impl;
-       boost::shared_ptr<Impl> impl_;
 };
 
 
+namespace dispatcher {
+
+inline Dispatcher::Handler addHandler(const std::string& message,
+               const Dispatcher::Function& callback)
+{
+       return Dispatcher::getInstance().addHandler(message, callback);
+}
+
+inline Dispatcher::Handler addHandler(const std::string& message,
+               const Dispatcher::Function& callback, Dispatcher::Handler id)
+{
+       return Dispatcher::getInstance().addHandler(message, callback, id);
+}
+
+inline void removeHandler(Dispatcher::Handler id)
+{
+       Dispatcher::getInstance().removeHandler(id);
+}
+
+inline void dispatch(const std::string& message, const Notification* param = 0)
+{
+       Dispatcher::getInstance().dispatch(message, param);
+}
+
+} // namespace dispatch
+
+
 } // namespace Mf
 
 #endif // _MOOF_DISPATCHER_HH_
This page took 0.021221 seconds and 4 git commands to generate.