From: Charles McGarvey Date: Tue, 8 Sep 2009 16:09:04 +0000 (-0600) Subject: dispatcher alias methods X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=f72400af4fa3e7b54dab154b5a2b6503a6f9af18;p=chaz%2Fyoink dispatcher alias methods --- diff --git a/src/Moof/Dispatcher.hh b/src/Moof/Dispatcher.hh index a152691..da82f38 100644 --- a/src/Moof/Dispatcher.hh +++ b/src/Moof/Dispatcher.hh @@ -55,7 +55,11 @@ public: class Dispatcher { + class Impl; + boost::shared_ptr impl_; + public: + typedef void* Handler; typedef boost::function Function; @@ -72,13 +76,35 @@ public: void removeHandler(Handler id); void dispatch(const std::string& message, const Notification* param = 0); - -private: - class Impl; - boost::shared_ptr impl_; }; +namespace dispatcher { + +inline Dispatcher::Handler addHandler(const std::string& message, + const Dispatcher::Function& callback) +{ + Dispatcher::getInstance().addHandler(message, callback); +} + +inline Dispatcher::Handler addHandler(const std::string& message, + const Dispatcher::Function& callback, Dispatcher::Handler id) +{ + 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_ diff --git a/src/YoinkApp.cc b/src/YoinkApp.cc index 7ec807b..86816e5 100644 --- a/src/YoinkApp.cc +++ b/src/YoinkApp.cc @@ -109,7 +109,7 @@ YoinkApp::YoinkApp(int argc, char* argv[]) : music("NightFusion"), punchSound("RobotPunch") { - Mf::Dispatcher::getInstance().addHandler("video.context_recreated", + Mf::dispatcher::addHandler("video.context_recreated", boost::bind(&YoinkApp::contextRecreated, this, _1), this); setupGL(); @@ -144,7 +144,7 @@ YoinkApp::~YoinkApp() delete font; delete testScene; - Mf::Dispatcher::getInstance().removeHandler(this); + Mf::dispatcher::removeHandler(this); } @@ -419,7 +419,7 @@ void YoinkApp::handleEvent(const Mf::Event& event) } else if (event.key.keysym.sym == SDLK_t) { - Mf::Dispatcher::getInstance().dispatch("video.context_recreated"); + Mf::dispatcher::dispatch("video.context_recreated"); break; } else if (event.key.keysym.sym == SDLK_p)