diff options
author | Bryan O'Sullivan <bos@lindenlab.com> | 2009-06-25 11:12:51 -0700 |
---|---|---|
committer | Bryan O'Sullivan <bos@lindenlab.com> | 2009-06-25 11:12:51 -0700 |
commit | 7aec119d84aabbf5fd156e9739984eb767ab262f (patch) | |
tree | 10be71ce5360519c3d67b826dc9cf4c8e7a242cd /indra/llcommon | |
parent | c5368c63680af040b63185d5fb6926195de84d59 (diff) | |
parent | 70d99b2528acb3bc503d3ac799e42d52515b6260 (diff) |
Merge with SVN login-api-3 branch
Diffstat (limited to 'indra/llcommon')
-rw-r--r-- | indra/llcommon/lleventdispatcher.h | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/indra/llcommon/lleventdispatcher.h b/indra/llcommon/lleventdispatcher.h index d75055fd6f..4da0a01c69 100644 --- a/indra/llcommon/lleventdispatcher.h +++ b/indra/llcommon/lleventdispatcher.h @@ -39,28 +39,31 @@ public: /// Accept any C++ callable, typically a boost::bind() expression typedef boost::function<void(const LLSD&)> Callable; - /// Register a @a callable by @a name. The optional @a required parameter - /// is used to validate the structure of each incoming event (see - /// llsd_matches()). + /** + * Register a @a callable by @a name. The optional @a required parameter + * is used to validate the structure of each incoming event (see + * llsd_matches()). + */ void add(const std::string& name, const Callable& callable, const LLSD& required=LLSD()); - /// Special case: a subclass of this class can register a @a method - /// without explicitly specifying the <tt>boost::bind()</tt> expression. - /// The optional @a required parameter is used to validate the structure - /// of each incoming event (see llsd_matches()). + /** + * Special case: a subclass of this class can pass an unbound member + * function pointer without explicitly specifying the + * <tt>boost::bind()</tt> expression. + */ template <class CLASS> void add(const std::string& name, void (CLASS::*method)(const LLSD&), const LLSD& required=LLSD()) { - CLASS* downcast = dynamic_cast<CLASS*>(this); - if (! downcast) - { - addFail(name, typeid(CLASS).name()); - } - else - { - add(name, boost::bind(method, downcast, _1), required); - } + addMethod<CLASS>(name, method, required); + } + + /// Overload for both const and non-const methods + template <class CLASS> + void add(const std::string& name, void (CLASS::*method)(const LLSD&) const, + const LLSD& required=LLSD()) + { + addMethod<CLASS>(name, method, required); } /// Unregister a callable @@ -78,6 +81,19 @@ public: void operator()(const LLSD& event) const; private: + template <class CLASS, typename METHOD> + void addMethod(const std::string& name, const METHOD& method, const LLSD& required) + { + CLASS* downcast = dynamic_cast<CLASS*>(this); + if (! downcast) + { + addFail(name, typeid(CLASS).name()); + } + else + { + add(name, boost::bind(method, downcast, _1), required); + } + } void addFail(const std::string& name, const std::string& classname) const; /// try to dispatch, return @c true if success bool attemptCall(const std::string& name, const LLSD& event) const; |