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