#include "smokebinding.h" #include #include namespace cl_smoke { /** @class NoDispatchBinding * @brief The Smoke binding for classes we need no dispatching. * This saves some overhead, since it does not call into Lisp. * Idea stolen from CommonQt ;) * * Dispatches for non extended classes (not of class CXX:CLASS) are between * 20% - 40% (for qt.examples:colliding-mice - qt.examples:class-browser). (18 February 2010) */ /** @typedef NoDispatchBinding::destructed * Callback when a Smoke object is destructed. * * @param class_index Index of the object's class. * @param object pointer to the object */ /** Constructor. * @param destruct destruct callback */ NoDispatchBinding::NoDispatchBinding(destructed destruct) : SmokeBinding(NULL), destruct(destruct) { Q_ASSERT(destruct); } /** Invoked when a Smoke object is destructed. */ void NoDispatchBinding::deleted(Smoke::Index, void *object) { destruct(object); } /** Invoked when a Smoke method gets called. */ bool NoDispatchBinding::callMethod(Smoke::Index method, void* object, Smoke::Stack stack, bool abstract) { Q_ASSERT(!abstract); return false; } /** * @todo Returning a const char* would be better */ char* NoDispatchBinding::className(Smoke::Index classId) { qFatal("className() Not implemented"); } /** @function NoDispatchBinding::get_smoke() * Gets the Smoke instance associated with the binding. * @return a pointer to the Smoke instance */ /** @class Binding * @brief The Smoke binding. */ /** @typedef Binding::dispatch_method * Callback when a Smoke method gets called. * * @param binding Smoke binding of @a object * @param method index of the method * @param object the object for which the method is called * @param args the arguments to the method * @param abstract @c true when the method is abstract and @c false otherwise * * @return @c true when the method call was handled and @c false * when the default method shall be invoked. */ /** Constructor. * @param destruct destruct callback * @param dispatch method dispatch callback */ Binding::Binding(destructed destruct, dispatch_method dispatch) : NoDispatchBinding(destruct), dispatch(dispatch) { Q_ASSERT(dispatch); } /** Invoked when a Smoke method gets called. */ bool Binding::callMethod(Smoke::Index method, void* object, Smoke::Stack stack, bool abstract) { int ret = dispatch(method, object, stack, abstract); Q_ASSERT( !abstract || ret ); return ret; } } // namespace cl_smoke