repos
/
smoke
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
headblob
|
headfilediff
|
filehistory
normal
|
plain
|
shade
|
zebra
Support modular smoke & cleanup.
Annotate for file src/libsmoke/smoke.cpp
2009-04-17 tobias
1
#include "cl_smoke.h"
2010-01-10 tobias
2
#include "smokebinding.h"
2009-04-05 tobias
3
15:36:29 '
4
#include <smoke.h>
'
5
#include <QtGlobal>
'
6
'
7
/** @file
2009-04-17 tobias
8
* @brief C wrapper the Smoke bindings.
2009-04-05 tobias
9
*/
15:36:29 '
10
'
11
using namespace cl_smoke;
'
12
'
13
extern "C" {
'
14
2010-02-19 tobias
15
/** Returns the Smoke module of a Smoke binding.
21:10:24 '
16
* @related cl_smoke::Binding
'
17
* @param binding the Binding
'
18
*
'
19
* @return the Smoke module
'
20
*/
'
21
CL_SMOKE_EXPORT void*
2010-01-10 tobias
22
cl_smoke_get_smoke(smoke_binding binding)
2010-02-19 tobias
23
{
2010-02-18 tobias
24
return get_smoke_binding(binding)->get_smoke();
2010-02-19 tobias
25
}
21:10:24 '
26
2009-04-05 tobias
27
/** Creates a new Smoke binding.
15:36:29 '
28
* The binding is allocated on the heap an can be freed with smoke_destruct().
'
29
* @related cl_smoke::Binding
'
30
* @param smoke pointer to a Smoke module instance
'
31
* @param destruct callback for object destruction
'
32
* @param dispatch method dispatch callback
'
33
*
'
34
* @return a pointer to a new Smoke binding.
'
35
*/
2009-05-11 tobias
36
CL_SMOKE_EXPORT smoke_binding
2010-01-10 tobias
37
cl_smoke_init(void* smoke, void* destruct, void* dispatch)
2009-04-05 tobias
38
{
2010-02-18 tobias
39
return new Binding(static_cast<Smoke*>(smoke),
19:57:00 '
40
reinterpret_cast<Binding::destructed>(destruct),
'
41
reinterpret_cast<Binding::dispatch_method>(dispatch));
2009-04-05 tobias
42
}
15:36:29 '
43
2010-02-18 tobias
44
/** Deletes the smoke binding.
19:57:00 '
45
* @related cl_smoke::Binding
2009-04-05 tobias
46
*/
2009-05-11 tobias
47
CL_SMOKE_EXPORT void
2010-01-10 tobias
48
cl_smoke_destruct(smoke_binding binding)
2009-04-05 tobias
49
{
2010-02-18 tobias
50
delete get_smoke_binding(binding)->get_smoke();
19:57:00 '
51
delete get_smoke_binding(binding);
2009-04-05 tobias
52
}
15:36:29 '
53
2010-02-18 tobias
54
/** Gets a Smoke modules name.
2009-04-05 tobias
55
* @param smoke the Smoke module
15:36:29 '
56
*
'
57
* @return the module name
'
58
*/
2009-05-11 tobias
59
CL_SMOKE_EXPORT const char*
2010-01-10 tobias
60
cl_smoke_get_module_name(void* smoke)
2009-04-05 tobias
61
{
15:36:29 '
62
return get_smoke(smoke)->moduleName();
'
63
}
'
64
2009-06-22 tobias
65
12:18:08 '
66
/** Returns the pointer to the array @a array of @a smoke.
'
67
* @param smoke the Smoke module
'
68
* @param array the array type
'
69
*
'
70
* @return a pointer to the array
'
71
*/
'
72
CL_SMOKE_EXPORT void*
'
73
cl_smoke_array(void* smoke, cl_smoke_module_array array)
'
74
{
'
75
switch (array)
'
76
{
'
77
case classes:
'
78
return get_smoke(smoke)->classes;
'
79
case methods:
'
80
return get_smoke(smoke)->methods;
'
81
case method_maps:
'
82
return get_smoke(smoke)->methodMaps;
'
83
case method_names:
'
84
return get_smoke(smoke)->methodNames;
'
85
case types:
'
86
return get_smoke(smoke)->types;
'
87
case inheritance_list:
'
88
return get_smoke(smoke)->inheritanceList;
'
89
case argument_list:
'
90
return get_smoke(smoke)->argumentList;
'
91
case ambiguous_method_list:
'
92
return get_smoke(smoke)->ambiguousMethodList;
'
93
}
'
94
qFatal("cl_smoke_array(): Unknown smoke_array %d", array);
'
95
}
'
96
'
97
/** Returns the size of the array @a array of @a smoke.
'
98
* The size if inclusive the bound.
'
99
* @param smoke the Smoke module
'
100
* @param array the array type
'
101
*
'
102
* @return the size
'
103
*/
'
104
CL_SMOKE_EXPORT Smoke::Index
'
105
cl_smoke_array_size(void* smoke, cl_smoke_module_array array)
'
106
{
'
107
switch (array)
'
108
{
'
109
case classes:
'
110
return get_smoke(smoke)->numClasses;
'
111
case methods:
'
112
return get_smoke(smoke)->numMethods;
'
113
case method_maps:
'
114
return get_smoke(smoke)->numMethodMaps;
'
115
case method_names:
'
116
return get_smoke(smoke)->numMethodNames;
'
117
case types:
'
118
return get_smoke(smoke)->numTypes;
'
119
case inheritance_list:
'
120
case argument_list:
'
121
case ambiguous_method_list:
'
122
qFatal("cl_smoke_array_size(): size of %d not known.", array);
'
123
}
'
124
qFatal("cl_smoke_array_size(): Unknown smoke_array %d.", array);
'
125
}
'
126
2009-04-05 tobias
127
///////////////////////////
15:36:29 '
128
/// Class
'
129
///////////////////////////
'
130
'
131
/** Finds a class.
'
132
* @param c pointer to write the result to
2010-01-17 tobias
133
* @param smoke the smoke module
2009-04-05 tobias
134
* @param name the name of the class
15:36:29 '
135
*/
2009-05-11 tobias
136
CL_SMOKE_EXPORT void
2010-01-10 tobias
137
cl_smoke_find_class(Smoke::ModuleIndex* c, void* smoke, const char* name)
2009-04-05 tobias
138
{
2010-01-17 tobias
139
*c = get_smoke(smoke)->findClass(name);
2009-04-05 tobias
140
}
15:36:29 '
141
'
142
/** Gets the class ID for a Smoke module.
'
143
* @param smoke the Smoke module
'
144
* @param name the class name
'
145
*
'
146
* @return the class ID in the supplied Smoke module
'
147
*/
2009-05-11 tobias
148
CL_SMOKE_EXPORT Smoke::Index
2010-01-10 tobias
149
cl_smoke_class_id(void* smoke, const char* name)
2009-04-05 tobias
150
{
15:36:29 '
151
Smoke::ModuleIndex m = get_smoke(smoke)->idClass(name, true);
'
152
Q_ASSERT(m.smoke == smoke);
'
153
'
154
return m.index;
'
155
}
'
156
'
157
/** Gets a class
'
158
* @param smoke the smoke binding
'
159
* @param class_index the index of the class
'
160
*
'
161
* @return A pointer to the class into the array of class structs
'
162
*/
2009-05-11 tobias
163
CL_SMOKE_EXPORT const struct Smoke::Class*
2010-01-10 tobias
164
cl_smoke_get_class(void* smoke, Smoke::Index class_index)
2009-04-05 tobias
165
{
2009-06-22 tobias
166
Q_ASSERT(class_index >= 0 && class_index <= get_smoke(smoke)->numClasses);
2009-04-05 tobias
167
return &get_smoke(smoke)->classes[class_index];
15:36:29 '
168
}
'
169
'
170
/** Determines werter a class is from a base class.
'
171
* @param smoke the Smoke module of @a class_index
'
172
* @param class_index the class index
'
173
* @param smoke_base the Smoke module of the base class @a base_index
'
174
* @param base_index the index of the base class
'
175
*
'
176
* @return Returns 0 when the class is not derived from the base class and nonzero value otherwise.
'
177
*/
2009-05-11 tobias
178
CL_SMOKE_EXPORT int
2010-01-10 tobias
179
cl_smoke_is_derived_from(void* smoke, Smoke::Index class_index, void* smoke_base,
08:49:36 '
180
Smoke::Index base_index)
2009-04-05 tobias
181
{
2010-02-03 tobias
182
Q_ASSERT(!smoke_get_class(smoke, class_index)->external);
16:20:56 '
183
Q_ASSERT(!smoke_get_class(smoke_base, base_index)->external);
2009-04-05 tobias
184
2010-01-17 tobias
185
return get_smoke(smoke)->isDerivedFrom(get_smoke(smoke), class_index,
2010-01-10 tobias
186
get_smoke(smoke_base), base_index);
2009-04-05 tobias
187
}
15:36:29 '
188
'
189
//////////////////////////////
'
190
/// Method
'
191
//////////////////////////////
'
192
'
193
/** Finds a method of a class.
'
194
* @param m pointer to write the result to
2010-02-19 tobias
195
* @param smoke the smoke binding
2009-04-05 tobias
196
* @param class_index index of the class
15:36:29 '
197
* @param method_name method name
'
198
*/
2009-05-11 tobias
199
CL_SMOKE_EXPORT void
2010-01-10 tobias
200
cl_smoke_find_method(Smoke::ModuleIndex* m, void* smoke,
2009-04-05 tobias
201
Smoke::Index class_index, const char* method_name)
15:36:29 '
202
{
2010-02-18 tobias
203
*m = get_smoke(smoke)->findMethod(get_smoke(smoke)->className(class_index),
19:57:00 '
204
method_name);
2009-04-05 tobias
205
if(m->index > 0)
2009-06-22 tobias
206
m->index = m->smoke->methodMaps[m->index].method;
2009-04-05 tobias
207
}
15:36:29 '
208
'
209
///////////////////////////
'
210
/// Type
'
211
//////////////////////////
'
212
'
213
/** Gets the index of a type.
'
214
* @param smoke the Smoke module
'
215
* @param name the types name
'
216
*
'
217
* @return the index of the type
'
218
*/
2009-05-11 tobias
219
CL_SMOKE_EXPORT Smoke::Index
2010-01-10 tobias
220
cl_smoke_find_type(void* smoke, const char* name)
2009-04-05 tobias
221
{
15:36:29 '
222
return get_smoke(smoke)->idType(name);
'
223
}
'
224
'
225
/** Casts an object.
'
226
* @param smoke the Smoke module
2010-02-18 tobias
227
* @param object the objec
2009-04-05 tobias
228
* @param from the class index of @a object
15:36:29 '
229
* @param to the class index to cast to
'
230
*
'
231
* @return the casted object
'
232
*/
2009-05-11 tobias
233
CL_SMOKE_EXPORT void*
2010-01-10 tobias
234
cl_smoke_cast(void* smoke, void* object, Smoke::Index from, Smoke::Index to)
2009-04-05 tobias
235
{
2009-06-22 tobias
236
Q_ASSERT(from > 0 && from <= get_smoke(smoke)->numClasses);
12:18:08 '
237
Q_ASSERT(to > 0 && to <= get_smoke(smoke)->numClasses);
2009-04-05 tobias
238
15:36:29 '
239
return get_smoke(smoke)->cast(object, from, to);
'
240
}
'
241
'
242
} // extern "C"