initial import
src/lib
Sun Apr 5 19:56:16 CEST 2009 Tobias Rautenkranz <tobias@rautenkranz.ch>
* initial import
diff -rN -u old-qt.core/src/lib/CMakeLists.txt new-qt.core/src/lib/CMakeLists.txt
--- old-qt.core/src/lib/CMakeLists.txt 1970-01-01 01:00:00.000000000 +0100
+++ new-qt.core/src/lib/CMakeLists.txt 2014-11-11 13:36:47.000000000 +0100
@@ -0,0 +1,7 @@
+find_package(Qt4)
+set(QT_DONT_USE_QTGUI true)
+include(${QT_USE_FILE})
+
+set(QT_SMOKE_SOURCES qt-smoke.cpp qstring.cpp qstringlist.cpp lisp-object.cpp)
+add_library(qt-smoke-extra MODULE ${QT_SMOKE_SOURCES})
+target_link_libraries(qt-smoke-extra ${QT_LIBRARIES})
diff -rN -u old-qt.core/src/lib/lisp-object.cpp new-qt.core/src/lib/lisp-object.cpp
--- old-qt.core/src/lib/lisp-object.cpp 1970-01-01 01:00:00.000000000 +0100
+++ new-qt.core/src/lib/lisp-object.cpp 2014-11-11 13:36:46.000000000 +0100
@@ -0,0 +1,179 @@
+#include "lisp-object.h"
+
+#include <QtGlobal>
+#include <QtDebug>
+
+namespace cl_smoke {
+namespace qt {
+
+/** @struct lisp_object::data
+ * @internal
+ * Holds a reference ID for a lisp object and calls
+ * the destructor callback when it is deleted.
+ */
+
+/** @typedef lisp_object::destructor
+ * Destructor.
+ * @param id The ID
+ */
+
+lisp_object::destructor lisp_object::destruct = NULL;
+
+
+/** Constructor. */
+lisp_object::data::data()
+: id(id),
+ is_set(false)
+{ }
+
+/** Constructor.
+ * @param id The ID.
+ */
+lisp_object::data::data(int id)
+: id(id),
+ is_set(true)
+{ }
+
+/** Destructor. */
+lisp_object::data::~data()
+{
+ Q_ASSERT_X(lisp_object::destruct, __func__,
+ "call setup_lisp_object() first.");
+
+ if (this->is_set)
+ (*lisp_object::destruct)(this->id);
+}
+
+/** @class lisp_object
+ * @brief Holds a reference ID to a lisp object.
+ *
+ * The registered destructor callback is called when
+ * the last instance for a specific lisp object is deleted.
+ *
+ * Used for lisp objects in QVariants and signal/slots.
+ */
+
+/** Constructor. */
+lisp_object::lisp_object()
+ : d(new data())
+{ }
+
+/** Constructor.
+ * @param id the ID
+ */
+lisp_object::lisp_object(int id)
+ : d(new data(id))
+{ }
+
+/** Constructor.
+ * @param other the lisp_object to copy
+ */
+lisp_object::lisp_object(const lisp_object& other)
+ : d(other.d)
+{ }
+
+/** @fn lisp_object::id() const
+ * Gets the ID.
+ *
+ * @return the ID
+ */
+
+/** @fn lisp_object::set() const
+ * Determines werter the ID is set.
+ *
+ * @return @c true when the id is set and @c false otherwise.
+ */
+
+/** Sets a new ID.
+ * @param id the ID
+ */
+void
+lisp_object::set_id(int id)
+{
+ Q_ASSERT(this->set() ? id != this->id() : true);
+
+ d = new data(id);
+}
+
+} // namespace qt
+} // namespace cl_smoke
+
+using namespace cl_smoke::qt;
+
+/** Initialize the lisp_object.
+ * @relates cl_smoke::qt::lisp_object
+ * @param destruct destructor callback
+ *
+ * @return the QMetaType ID of lisp_object
+ */
+int
+qt_smoke_setup_lisp_object(void* destruct)
+{
+ Q_ASSERT(destruct != NULL);
+ lisp_object::destruct = reinterpret_cast<lisp_object::destructor>(destruct);
+
+ return qRegisterMetaType<lisp_object>();
+}
+
+/** Gets the ID of @a object.
+ * @relates cl_smoke::qt::lisp_object
+ * @param object the lisp_object.
+ *
+ * @return the ID
+ */
+int
+qt_smoke_lisp_object_id(const void* object)
+{
+ return static_cast<const lisp_object*>(object)->id();
+}
+
+
+/** Determines werter the ID of @a object is set.
+ * @relates cl_smoke::qt::lisp_object
+ * @param object the object
+ *
+ * @return @c true when the ID is set and @c false otherwise.
+ */
+int
+qt_smoke_lisp_object_set(const void* object)
+{
+ return static_cast<const lisp_object*>(object)->set();
+}
+
+/** Makes a new lisp_object.
+ * @relates cl_smoke::qt::lisp_object
+ * @param id the ID
+ *
+ * @return A new lisp_object instance.
+ */
+void*
+qt_smoke_make_lisp_object(int id)
+{
+ return new lisp_object(id);
+}
+
+/** Deletes a lisp_object.
+ * @relates cl_smoke::qt::lisp_object
+ * @param object the lisp_object
+ */
+void*
+qt_smoke_free_lisp_object(void* object)
+{
+ delete static_cast<lisp_object*>(object);
+}
+
+#include <QVariant>
+/** Gets the lisp_object of a QVariant.
+ * @relates cl_smoke::qt::lisp_object
+ * @param variant the QVariant
+ *
+ * @return a new lisp_object.
+ */
+void*
+qt_smoke_lisp_object_value(const void* variant)
+{
+ const QVariant* qvariant = static_cast<const QVariant*>(variant);
+ Q_ASSERT(QVariant::UserType == qvariant->type());
+
+ new lisp_object(qvariant->value<lisp_object>());
+}
diff -rN -u old-qt.core/src/lib/lisp-object.h new-qt.core/src/lib/lisp-object.h
--- old-qt.core/src/lib/lisp-object.h 1970-01-01 01:00:00.000000000 +0100
+++ new-qt.core/src/lib/lisp-object.h 2014-11-11 13:36:47.000000000 +0100
@@ -0,0 +1,82 @@
+#ifndef LISP_OBJECT_H
+#define LISP_OBJECT_H
+
+#include <QMetaType>
+#include <QSharedData>
+#include <QExplicitlySharedDataPointer>
+#include <smoke.h>
+
+
+extern "C"
+{
+ int
+ qt_smoke_setup_lisp_object(void* destruct);
+
+ int
+ qt_smoke_lisp_object_id(const void* object);
+
+ int
+ qt_smoke_lisp_object_set(const void* object);
+
+ void*
+ qt_smoke_make_lisp_object(int id);
+
+ void*
+ qt_smoke_free_lisp_object(void* object);
+
+ void*
+ qt_smoke_lisp_object_value(const void* variant);
+}
+
+namespace cl_smoke {
+namespace qt {
+
+class lisp_object
+{
+ public:
+ typedef void (*destructor)(int id);
+
+ lisp_object();
+
+ lisp_object(int id);
+
+ lisp_object(const lisp_object& other);
+
+ inline int
+ id() const
+ { Q_ASSERT(this->set()); return d->id; }
+
+ void
+ set_id(int id);
+
+ inline bool
+ set() const
+ { return d->is_set; }
+
+ friend int
+ ::qt_smoke_setup_lisp_object(void* destruct);
+
+ private:
+ struct data : public QSharedData
+ {
+ data();
+ data(int id);
+ ~data();
+ int id;
+ bool is_set;
+
+ private:
+ Q_DISABLE_COPY(data)
+ };
+
+ QExplicitlySharedDataPointer<data> d;
+
+ static destructor destruct;
+};
+
+} // namespace qt
+} // namespace cl_smoke
+
+Q_DECLARE_METATYPE(cl_smoke::qt::lisp_object);
+
+#endif // LISP_OBJECT_H
diff -rN -u old-qt.core/src/lib/qstring.cpp new-qt.core/src/lib/qstring.cpp
--- old-qt.core/src/lib/qstring.cpp 1970-01-01 01:00:00.000000000 +0100
+++ new-qt.core/src/lib/qstring.cpp 2014-11-11 13:36:47.000000000 +0100
@@ -0,0 +1,44 @@
+#include <QString>
+#include <QtDebug>
+
+/** @file
+ * @brief QString conversion. */
+
+extern "C" {
+
+/** Converts a QString to a QByteArray.
+ * @param qstring Pointer to a QString
+ *
+ * @return a pointer to a newly allocated char array.
+ */
+void*
+qt_smoke_qstring_to_byte_array(const void* qstring)
+{
+ Q_ASSERT(qstring);
+ const QString* string = static_cast<const QString*>(qstring);
+
+ return new QByteArray(string->toLocal8Bit());
+}
+
+/** Frees an QString.
+ * @param qstring the QString to free
+ */
+void
+qt_smoke_free_qstring(void* qstring)
+{
+ delete static_cast<QString*>(qstring);
+}
+
+/** Converts a string to a QString.
+ * @param data a char array
+ * @param length the length of @a data
+ *
+ * @return a newly allocated QString
+ */
+void*
+qt_smoke_string_to_qstring(const char* data, int length)
+{
+ return new QString(QString::fromLocal8Bit(data, length));
+}
+
+} // extern "C"
diff -rN -u old-qt.core/src/lib/qstringlist.cpp new-qt.core/src/lib/qstringlist.cpp
--- old-qt.core/src/lib/qstringlist.cpp 1970-01-01 01:00:00.000000000 +0100
+++ new-qt.core/src/lib/qstringlist.cpp 2014-11-11 13:36:47.000000000 +0100
@@ -0,0 +1,69 @@
+#include <QStringList>
+#include <QtDebug>
+#include <cstring>
+
+/** @file
+ * @brief QStringList conversion. */
+
+extern "C" {
+
+/** Returns the number of items of @a string_list.
+ * @param string_list the QStringList
+ *
+ * @return the number of items
+ */
+int
+qt_smoke_string_list_size(const void* string_list)
+{
+ Q_ASSERT(string_list);
+ return static_cast<const QStringList*>(string_list)->size();
+}
+
+/** Returns the byte array of @a string_list at position @a index.
+ * @param string_list the QStringList
+ * @param index the index of the string
+ *
+ * @return a new allocated byte-array
+ */
+void*
+qt_smoke_string_list_at(const void* string_list, int index)
+{
+ Q_ASSERT(string_list);
+ const QStringList* list = static_cast<const QStringList*>(string_list);
+
+ Q_ASSERT(0 <= index && index < list->size());
+
+ return new QByteArray(list->at(index).toLocal8Bit());
+}
+
+/** Free a QStringList.
+ * @param string_list the QStringList to free
+ */
+void
+qt_smoke_free_string_list(void* string_list)
+{
+ delete static_cast<QStringList*>(string_list);
+}
+
+/** Allocates a new QStringList.
+ *
+ * @return a new QStringList
+ */
+void*
+qt_smoke_make_string_list()
+{
+ return new QStringList();
+}
+
+/** Appends @a string to @a string_list
+ * @param string_list the QStringList
+ * @param data the string
+ * @param length the length of @a data
+ */
+void
+qt_smoke_string_list_append(void* string_list, const char* data, int length)
+{
+ static_cast<QStringList*>(string_list)->append(QString::fromLocal8Bit(data, length));
+}
+
+} // extern "C"
diff -rN -u old-qt.core/src/lib/qt-smoke.cpp new-qt.core/src/lib/qt-smoke.cpp
--- old-qt.core/src/lib/qt-smoke.cpp 1970-01-01 01:00:00.000000000 +0100
+++ new-qt.core/src/lib/qt-smoke.cpp 2014-11-11 13:36:47.000000000 +0100
@@ -0,0 +1,26 @@
+#include <qnamespace.h>
+#include <QEvent>
+#include <QtDebug>
+
+/** @file
+ * @brief Qt support functions */
+
+extern "C" {
+
+/** Registers a callback to be invoked for every QEvent.
+ * @see QCoreApplication::notifyInternal
+ *
+ * @param callback the callback
+ *
+ * @return @c true on success and @c false when the callback table is full.
+ */
+int
+qt_smoke_register_event_notify(void* callback)
+{
+ Q_ASSERT(callback);
+
+ return QInternal::registerCallback(QInternal::EventNotifyCallback,
+ reinterpret_cast<qInternalCallback>(callback));
+}
+
+} // extern "C"