+++ /dev/null
-
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
-**] All rights reserved.
-*
-* vi:ts=4 sw=4 tw=75
-*
-* Distributable under the terms and conditions of the 2-clause BSD license;
-* see the file COPYING for a complete text of the license.
-*
-**************************************************************************/
-
-#ifndef _MOOF_DISPATCH_HH_
-#define _MOOF_DISPATCH_HH_
-
-#include <string>
-
-#include <boost/bind.hpp>
-#include <boost/function.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/weak_ptr.hpp>
-
-
-namespace Mf {
-
-
-/**
- * Dispatcher of messages to interested parties.
- */
-
-class Dispatch
-{
- class Impl;
- boost::shared_ptr<Impl> mImpl;
-
- void removeTarget(unsigned id);
-
-
-public:
-
- class Handle
- {
- public:
-
- Handle() :
- mId(0) {}
-
- Handle(boost::weak_ptr<Impl> dispatch, unsigned id) :
- mDispatch(dispatch),
- mId(id) {}
-
- Handle(const Handle& handle) :
- mDispatch(handle.mDispatch),
- mId(handle.mId)
- {
- handle.mId = 0;
- }
-
- ~Handle()
- {
- clear();
- }
-
- Handle& operator = (const Handle& handle)
- {
- clear();
- mDispatch = handle.mDispatch;
- mId = handle.mId;
- handle.mId = 0;
- return *this;
- }
-
- unsigned getId() const
- {
- return mId;
- }
-
- void clear();
-
- private:
-
- boost::weak_ptr<Impl> mDispatch;
- mutable unsigned mId;
- };
-
- typedef boost::function<void(void)> Function;
-
-
- Dispatch();
-
- Handle addTarget(const std::string& event, const Function& callback);
- Handle addTarget(const std::string& event, const Function& callback,
- Handle handle);
-
- void dispatch(const std::string& event);
-
- static Dispatch& global();
-};
-
-
-} // namespace Mf
-
-#endif // _MOOF_DISPATCH_HH_
-