/ src / lib /
src/lib/qlist.h
1 #ifndef CL_SMOKE_QT_QLIST_H
2 #define CL_SMOKE_QT_QLIST_H
3
4 #include "cl_smoke_qt.h"
5
6 #include <QList>
7
8 /** @file
9 */
10
11 /** Defines a C wrapper for the QList<@a TYPE>.
12 * @param TYPE the type of the elements of the QList
13 */
14 #define DEFINE_QLIST_WRAPPER(TYPE) \
15 DEFINE_QLIST_WRAPPER_3(TYPE, TYPE, VALUE)
16
17 /** Defines a C wrapper for the QList<@a TYPE*>,
18 * where @a TYPE is the of the pointer.
19 *
20 * @param NAME the name used for the wrapper functions.
21 * @param TYPE the type of the elements
22 */
23 #define DEFINE_QLIST_WRAPPER_PTR(TYPE) \
24 DEFINE_QLIST_WRAPPER_3(TYPE, TYPE*, PTR)
25
26 /** @internal */
27 #define DEFINE_QLIST_WRAPPER_3(NAME, TYPE, PTR_VALUE) \
28 DEFINE_QLIST_WRAPPER_ALL_PART(NAME, TYPE) \
29 DEFINE_QLIST_WRAPPER_ ## PTR_VALUE ## _PART(NAME, TYPE) \
30
31
32 /** @internal
33 * size, free and make_list. */
34 #define DEFINE_QLIST_WRAPPER_ALL_PART(NAME, TYPE) \
35 CL_SMOKE_QT_EXPORT void \
36 cl_smoke_free_list_ ## NAME (void* list) \
37 { \
38 delete static_cast<QList< TYPE >*>(list); \
39 } \
40 \
41 CL_SMOKE_QT_EXPORT void* \
42 cl_smoke_make_list_ ## NAME () \
43 { \
44 return new QList< TYPE >(); \
45 } \
46 \
47
48 /** @internal
49 * At and append for pointer types
50 */
51 #define DEFINE_QLIST_WRAPPER_PTR_PART(NAME, TYPE) \
52 CL_SMOKE_QT_EXPORT const void* \
53 cl_smoke_list_ ## NAME ## _at(const void* list, int index) \
54 { \
55 const QList< TYPE >* qlist = static_cast<const QList< TYPE > *>(list); \
56 return qlist->at(index); \
57 } \
58 \
59 CL_SMOKE_QT_EXPORT void \
60 cl_smoke_list_ ## NAME ## _append(void* list, void* data) \
61 { \
62 static_cast<QList< TYPE >*>(list) \
63 ->append(static_cast<TYPE>(data)); \
64 } \
65
66 /** @internal
67 * At and append for value types.
68 */
69 #define DEFINE_QLIST_WRAPPER_VALUE_PART(NAME, TYPE) \
70 CL_SMOKE_QT_EXPORT const void* \
71 cl_smoke_list_ ## NAME ## _at(const void* list, int index) \
72 { \
73 const QList< TYPE >* qlist = static_cast<const QList< TYPE > *>(list); \
74 return new TYPE(qlist->at(index)); \
75 } \
76 \
77 CL_SMOKE_QT_EXPORT void \
78 cl_smoke_list_ ## NAME ## _append(void* list, void* data) \
79 { \
80 static_cast<QList< TYPE >*>(list) \
81 ->append(*static_cast<TYPE*>(data)); \
82 } \
83
84 #endif // CL_SMOKE_QT_QLIST_H