FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
JSCallback.h
1 /**********************************************************\
2  Original Author: Georg Fritzsche
3 
4  Created: Aug 2, 2010
5  License: Dual license model; choose one of two:
6  New BSD License
7  http://www.opensource.org/licenses/bsd-license.php
8  - or -
9  GNU Lesser General Public License, version 2.1
10  http://www.gnu.org/licenses/lgpl-2.1.html
11 
12  Copyright 2010 Georg Fritzsche, Firebreath development team
13  \**********************************************************/
14 
15 #pragma once
16 #ifndef JSCALLBACK_H
17 #define JSCALLBACK_H
18 
19 #include "JSAPIAuto.h"
20 
21 namespace FB
22 {
23  FB_FORWARD_PTR(JSCallback);
24  class JSCallback : public FB::JSAPIAuto
25  {
26  public:
27  JSCallback(const FB::CallMethodFunctor& func)
28  : m_jsapi()
29  {
30  registerMethod("", func);
31  }
32 
33  JSCallback(const FB::CallMethodFunctor& func, FB::JSAPIPtr jsapi)
34  : m_jsapi(jsapi)
35  {
36  registerMethod("", func);
37  }
38 
39  protected:
40  FB::JSAPIPtr m_jsapi;
41  };
42 
43  template<class T, class F>
44  FB::JSAPIPtr make_callback(const T& instance, F member_function, bool strong_reference = true)
45  {
46  if (strong_reference) {
47  return FB::JSAPIPtr(new JSCallback(FB::make_method(instance.get(), member_function), instance));
48  } else {
49  return FB::JSAPIPtr(new JSCallback(FB::make_method(instance.get(), member_function)));
50  }
51  }
52 }
53 
54 #endif
55 
boost::function< variant(const std::vector< variant > &)> CallMethodFunctor
Defines an alias representing a method functor used by FB::JSAPIAuto, created by FB::make_method().
Definition: APITypes.h:286
boost::shared_ptr< FB::JSAPI > JSAPIPtr
Defines an alias for a JSAPI shared_ptr (you should never use a JSAPI* directly)
Definition: APITypes.h:94
JSAPI class with automatic argument type enforcement.
Definition: JSAPIAuto.h:94