/ src / libsmoke /
src/libsmoke/smokebinding.cpp
1 #include "smokebinding.h"
2
3 #include <QtGlobal>
4 #include <QDebug>
5
6 namespace cl_smoke
7 {
8
9 /** @class NoDispatchBinding
10 * @brief The Smoke binding for classes we need no dispatching.
11 * This saves some overhead, since it does not call into Lisp.
12 * Idea stolen from CommonQt ;)
13 *
14 * Dispatches for non extended classes (not of class CXX:CLASS) are between
15 * 20% - 40% (for qt.examples:colliding-mice - qt.examples:class-browser). (18 February 2010)
16 */
17
18 /** @typedef NoDispatchBinding::destructed
19 * Callback when a Smoke object is destructed.
20 *
21 * @param class_index Index of the object's class.
22 * @param object pointer to the object
23 */
24
25 /** Constructor.
26 * @param destruct destruct callback
27 */
28 NoDispatchBinding::NoDispatchBinding(destructed destruct)
29 : SmokeBinding(NULL),
30 destruct(destruct)
31 {
32 Q_ASSERT(destruct);
33 }
34
35 /** Invoked when a Smoke object is destructed. */
36 void
37 NoDispatchBinding::deleted(Smoke::Index, void *object)
38 {
39 destruct(object);
40 }
41
42 /** Invoked when a Smoke method gets called. */
43 bool
44 NoDispatchBinding::callMethod(Smoke::Index method, void* object,
45 Smoke::Stack stack, bool abstract)
46 {
47 Q_ASSERT(!abstract);
48 return false;
49 }
50
51 /**
52 * @todo Returning a const char* would be better
53 */
54 char*
55 NoDispatchBinding::className(Smoke::Index classId)
56 {
57 qFatal("className() Not implemented");
58 }
59
60 /** @function NoDispatchBinding::get_smoke()
61 * Gets the Smoke instance associated with the binding.
62 * @return a pointer to the Smoke instance
63 */
64
65 /** @class Binding
66 * @brief The Smoke binding.
67 */
68
69 /** @typedef Binding::dispatch_method
70 * Callback when a Smoke method gets called.
71 *
72 * @param binding Smoke binding of @a object
73 * @param method index of the method
74 * @param object the object for which the method is called
75 * @param args the arguments to the method
76 * @param abstract @c true when the method is abstract and @c false otherwise
77 *
78 * @return @c true when the method call was handled and @c false
79 * when the default method shall be invoked.
80 */
81
82 /** Constructor.
83 * @param destruct destruct callback
84 * @param dispatch method dispatch callback
85 */
86 Binding::Binding(destructed destruct, dispatch_method dispatch)
87 : NoDispatchBinding(destruct),
88 dispatch(dispatch)
89 {
90 Q_ASSERT(dispatch);
91 }
92
93
94 /** Invoked when a Smoke method gets called. */
95 bool
96 Binding::callMethod(Smoke::Index method, void* object,
97 Smoke::Stack stack, bool abstract)
98 {
99 int ret = dispatch(method, object, stack, abstract);
100 Q_ASSERT( !abstract || ret );
101
102 return ret;
103 }
104
105 } // namespace cl_smoke