/ src / lib /
/src/lib/qstringlist.cpp
1 #include "cl_smoke_qt.h"
2
3 #include <QStringList>
4 #include <QtDebug>
5
6 /** @file
7 * @brief QStringList conversion. */
8
9 extern "C" {
10
11 /** Returns the number of items of @a string_list.
12 * @param string_list the QStringList
13 *
14 * @return the number of items
15 */
16 CL_SMOKE_QT_EXPORT int
17 cl_smoke_string_list_size(const void* string_list)
18 {
19 Q_ASSERT(string_list);
20 return static_cast<const QStringList*>(string_list)->size();
21 }
22
23 /** Returns the byte array of @a string_list at position @a index.
24 * @param string_list the QStringList
25 * @param index the index of the string
26 *
27 * @return a new allocated byte-array
28 */
29 CL_SMOKE_QT_EXPORT void*
30 cl_smoke_string_list_at(const void* string_list, int index)
31 {
32 Q_ASSERT(string_list);
33 const QStringList* list = static_cast<const QStringList*>(string_list);
34
35 Q_ASSERT(0 <= index && index < list->size());
36
37 return new QByteArray(list->at(index).toLocal8Bit());
38 }
39
40 /** Free a QStringList.
41 * @param string_list the QStringList to free
42 */
43 CL_SMOKE_QT_EXPORT void
44 cl_smoke_free_string_list(void* string_list)
45 {
46 delete static_cast<QStringList*>(string_list);
47 }
48
49 /** Allocates a new QStringList.
50 *
51 * @return a new QStringList
52 */
53 CL_SMOKE_QT_EXPORT void*
54 cl_smoke_make_string_list()
55 {
56 return new QStringList();
57 }
58
59 /** Appends @a string to @a string_list
60 * @param string_list the QStringList
61 * @param data the string
62 * @param length the length of @a data
63 */
64 CL_SMOKE_QT_EXPORT void
65 cl_smoke_string_list_append(void* string_list, const char* data, int length)
66 {
67 static_cast<QStringList*>(string_list)->append(QString::fromLocal8Bit(data, length));
68 }
69
70 } // extern "C"