Support modular smoke & cleanup.
src/libsmoke/smokebinding.cpp
Sun Jan 10 09:49:36 CET 2010 Tobias Rautenkranz <tobias@rautenkranz.ch>
* Support modular smoke & cleanup.
--- old-smoke/src/libsmoke/smokebinding.cpp 1970-01-01 01:00:00.000000000 +0100
+++ new-smoke/src/libsmoke/smokebinding.cpp 2014-10-30 08:09:24.000000000 +0100
@@ -0,0 +1,87 @@
+#include "smokebinding.h"
+
+#include <QtGlobal>
+#include <QDebug>
+
+namespace cl_smoke
+{
+
+/** @class Binding
+ * @brief The Smoke binding.
+ */
+
+
+/** @typedef Binding::destructed
+ * Callback when a Smoke object is destructed.
+ *
+ * @param class_index Index of the object's class.
+ * @param object pointer to the object
+ */
+
+
+/** @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 smoke the Smoke module
+ * @param destruct destruct callback
+ * @param dispatch method dispatch callback
+ */
+Binding::Binding(Smoke *smoke, destructed destruct,
+ dispatch_method dispatch)
+ : SmokeBinding(smoke),
+ destruct(destruct),
+ dispatch(dispatch)
+{
+ Q_ASSERT(smoke);
+ Q_ASSERT(destruct);
+ Q_ASSERT(dispatch);
+}
+
+/** Invoked when a Smoke object is destructed. */
+void
+Binding::deleted(Smoke::Index, void *object)
+{
+ destruct(object);
+}
+
+/** Invoked when a Smoke method gets called. */
+bool
+Binding::callMethod(Smoke::Index method, void* object,
+ Smoke::Stack stack, bool abstract)
+{
+ int ret = dispatch(this, method, object, stack, abstract);
+ Q_ASSERT( !abstract || ret );
+
+ return ret;
+}
+
+/**
+ * @todo Returning a const char* would be better
+ */
+char*
+Binding::className(Smoke::Index classId)
+{
+ return const_cast<char*>(smoke->classes[classId].className);
+}
+
+/** Gets the Smoke instance associated with the binding.
+ * @return a pointer to the Smoke instance
+ */
+Smoke*
+Binding::get_smoke() const
+{
+ return smoke;
+}
+
+} // namespace cl_smoke