Mercurial > projects > qtd
comparison d2/qt/core/QVariant.d @ 361:beaf4a2974d7
Autogeneration of QMetaType. First attempts at fixing qRegisterMetaType etc
author | Max Samukha <maxter@maxter.com> |
---|---|
date | Wed, 09 Jun 2010 11:08:56 +0300 |
parents | 96a75b1e5b26 |
children | a032df77b6ab |
comparison
equal
deleted
inserted
replaced
360:49d0a43433e7 | 361:beaf4a2974d7 |
---|---|
88 LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type | 88 LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type |
89 } | 89 } |
90 | 90 |
91 // Functions | 91 // Functions |
92 | 92 |
93 private template getMetaId() | 93 private int getMetaId(T)(string name) |
94 { | 94 { |
95 const char[] getMetaId = " | 95 static shared int sharedId; |
96 int i = qtd_MetatypeId(toStringz(name)); | 96 static int id; |
97 if(i <= 0) | 97 if (id == 0) |
98 i = qRegisterMetaType!(T)(name);"; | 98 { |
99 synchronized(qtdMoLock) | |
100 { | |
101 if (sharedId == 0) | |
102 sharedId = qRegisterMetaType!T(name); | |
103 } | |
104 id = sharedId; | |
105 } | |
106 return id; | |
99 } | 107 } |
100 | 108 |
101 static public QVariant fromValue(T)(T obj) | 109 static public QVariant fromValue(T)(T obj) |
102 { | 110 { |
103 QVariant var; | 111 QVariant var; |
104 static if (is(T == class) || is(T == interface)) | 112 static if (is(T == class) || is(T == interface)) |
105 { | 113 { |
106 string name = obj.classinfo.name; | 114 string name = obj.classinfo.name; |
107 mixin(getMetaId!()); | 115 // TODO: Still hacky. No need to pass name to id getter. |
108 var = new QVariant(i, cast(void*)(obj)); | 116 var = new QVariant(getMetaId!T(name), cast(void*)(obj)); |
109 } | 117 } |
110 else static if (isDynamicArrayType!(T) || isStaticArrayType!(T) ) | 118 else static if (isDynamicArrayType!(T) || isStaticArrayType!(T) ) |
111 { | 119 { |
112 string name = typeid(ElementTypeOfArray!(T)).toString ~ "[]"; | 120 string name = typeid(ElementTypeOfArray!(T)).toString ~ "[]"; |
113 mixin(getMetaId!()); | 121 auto darray = new DArrayToC; |
114 auto darray = new DArrayToC; | 122 darray.array = obj.dup; |
115 darray.array = obj.dup; | 123 var = new QVariant(getMetaId!T(name), cast(void*)(darray)); |
116 var = new QVariant(i, cast(void*)(darray)); | 124 } |
117 } | 125 else |
118 else | 126 { |
119 { | 127 string name = typeid(T).toString; |
120 string name = typeid(T).toString; | 128 auto data = new T; |
121 mixin(getMetaId!()); | 129 *data = obj; |
122 auto data = new T; | 130 var = new QVariant(getMetaId!T(name), cast(void*)(data)); |
123 *data = obj; | 131 } |
124 var = new QVariant(i, cast(void*)(data)); | 132 return var; |
125 } | |
126 return var; | |
127 } | 133 } |
128 | 134 |
129 static public QVariant opCall(T)(T obj) | 135 static public QVariant opCall(T)(T obj) |
130 { | 136 { |
131 return fromValue(obj); | 137 return fromValue(obj); |
132 } | 138 } |
133 | 139 |
134 public this() { | 140 public this() { |
135 void* __qt_return_value = qtd_QVariant_QVariant(); | 141 void* __qt_return_value = qtd_QVariant_QVariant(); |
136 super(__qt_return_value); | 142 super(__qt_return_value); |
302 public this(ulong ull) { | 308 public this(ulong ull) { |
303 void* __qt_return_value = qtd_QVariant_QVariant_ulong(ull); | 309 void* __qt_return_value = qtd_QVariant_QVariant_ulong(ull); |
304 super(__qt_return_value); | 310 super(__qt_return_value); |
305 } | 311 } |
306 | 312 |
313 // TODO: No need for run time name. Reimplement. | |
307 private final bool canConvertImpl(string name) | 314 private final bool canConvertImpl(string name) |
308 { | 315 { |
309 int i = qtd_MetatypeId(toStringz(name)); | 316 int i = QMetaType.type(toStringz(name)); |
310 assert(i > 0); | 317 assert(i > 0); |
311 return qtd_QVariant_canConvert(__nativeId, i); | 318 return qtd_QVariant_canConvert(__nativeId, i); |
312 } | 319 } |
313 | 320 |
321 // TODO: reimplement | |
314 public final bool canConvert(Type)() { | 322 public final bool canConvert(Type)() { |
315 static if ( is(Type == QBitArray) ) | 323 static if ( is(Type == QBitArray) ) |
316 return canConvertImpl("QBitArray"); | 324 return canConvertImpl("QBitArray"); |
317 else static if ( is(Type == bool) ) | 325 else static if ( is(Type == bool) ) |
318 return canConvertImpl("bool"); | 326 return canConvertImpl("bool"); |
319 else static if ( is(Type == QByteArray) ) | 327 else static if ( is(Type == QByteArray) ) |
320 return canConvertImpl("QByteArray"); | 328 return canConvertImpl("QByteArray"); |
321 else static if ( is(Type == QDate) ) | 329 else static if ( is(Type == QDate) ) |
322 return canConvertImpl("QDate"); | 330 return canConvertImpl("QDate"); |
323 else static if ( is(Type == QDateTime) ) | 331 else static if ( is(Type == QDateTime) ) |
324 return canConvertImpl("QDateTime"); | 332 return canConvertImpl("QDateTime"); |
325 else static if ( is(Type == double) ) | 333 else static if ( is(Type == double) ) |
326 return canConvertImpl("double"); | 334 return canConvertImpl("double"); |
327 else static if ( is(Type == int) ) | 335 else static if ( is(Type == int) ) |
328 return canConvertImpl("int"); | 336 return canConvertImpl("int"); |
329 else static if ( is(Type == QLine) ) | 337 else static if ( is(Type == QLine) ) |
330 return canConvertImpl("QLine"); | 338 return canConvertImpl("QLine"); |
331 else static if ( is(Type == QLineF) ) | 339 else static if ( is(Type == QLineF) ) |
332 return canConvertImpl("QLineF"); | 340 return canConvertImpl("QLineF"); |
333 else static if ( is(Type == QLocale) ) | 341 else static if ( is(Type == QLocale) ) |
334 return canConvertImpl("QLocale"); | 342 return canConvertImpl("QLocale"); |
335 else static if ( is(Type == long) ) | 343 else static if ( is(Type == long) ) |
336 return canConvertImpl("long"); | 344 return canConvertImpl("long"); |
337 else static if ( is(Type == QPoint) ) | 345 else static if ( is(Type == QPoint) ) |
338 return canConvertImpl("QPoint"); | 346 return canConvertImpl("QPoint"); |
339 else static if ( is(Type == QPointF) ) | 347 else static if ( is(Type == QPointF) ) |
340 return canConvertImpl("QPointF"); | 348 return canConvertImpl("QPointF"); |
341 else static if ( is(Type == QRect) ) | 349 else static if ( is(Type == QRect) ) |
342 return canConvertImpl("QRect"); | 350 return canConvertImpl("QRect"); |
343 else static if ( is(Type == QRectF) ) | 351 else static if ( is(Type == QRectF) ) |
344 return canConvertImpl("QRectF"); | 352 return canConvertImpl("QRectF"); |
345 else static if ( is(Type == QRegExp) ) | 353 else static if ( is(Type == QRegExp) ) |
346 return canConvertImpl("QRegExp"); | 354 return canConvertImpl("QRegExp"); |
347 else static if ( is(Type == QSize) ) | 355 else static if ( is(Type == QSize) ) |
348 return canConvertImpl("QSize"); | 356 return canConvertImpl("QSize"); |
349 else static if ( is(Type == QSizeF) ) | 357 else static if ( is(Type == QSizeF) ) |
350 return canConvertImpl("QSizeF"); | 358 return canConvertImpl("QSizeF"); |
351 else static if ( is(Type == string) ) | 359 else static if ( is(Type == string) ) |
352 return canConvertImpl("QString"); | 360 return canConvertImpl("QString"); |
353 else static if ( is(Type == QTime) ) | 361 else static if ( is(Type == QTime) ) |
354 return canConvertImpl("QTime"); | 362 return canConvertImpl("QTime"); |
355 else static if ( is(Type == uint) ) | 363 else static if ( is(Type == uint) ) |
356 return canConvertImpl("unsigned int"); // TODO: | 364 return canConvertImpl("unsigned int"); // TODO: |
357 else static if ( is(Type == ulong) ) | 365 else static if ( is(Type == ulong) ) |
358 return canConvertImpl("unsigned long long"); // TODO: | 366 return canConvertImpl("unsigned long long"); // TODO: |
359 else static if ( is(Type == QUrl) ) | 367 else static if ( is(Type == QUrl) ) |
360 return canConvertImpl("QUrl"); | 368 return canConvertImpl("QUrl"); |
361 else | 369 else |
362 { | 370 { |
363 static if( is( Type == class ) || is( Type == interface ) ) | 371 static if( is( Type == class ) || is( Type == interface ) ) |
364 { | 372 { |
365 Object object = cast(Object)qtd_QVariant_data(__nativeId); | 373 Object object = cast(Object)qtd_QVariant_data(__nativeId); |
366 if(object) | 374 if(object) |
367 return cast(Type)(object) !is null; | 375 return cast(Type)(object) !is null; |
368 return false; | 376 return false; |
369 } | 377 } |
370 else static if (isDynamicArrayType!(Type) || isStaticArrayType!(Type) ) | 378 else static if (isDynamicArrayType!(Type) || isStaticArrayType!(Type) ) |
371 { | 379 { |
372 auto array = cast(DArrayToC*)qtd_QVariant_data(__nativeId); | 380 auto array = cast(DArrayToC*)qtd_QVariant_data(__nativeId); |
373 return cast(Type)(array.array) !is null; | 381 return cast(Type)(array.array) !is null; |
374 } | 382 } |
375 else | 383 else |
376 { | 384 { |
377 int i = qtd_MetatypeId(toStringz(typeid(Type).toString)); | 385 int i = QMetaType.type(toStringz(typeid(Type).toString)); |
378 return qtd_QVariant_canConvert(__nativeId, i); | 386 return qtd_QVariant_canConvert(__nativeId, i); |
379 } | 387 } |
380 } | 388 } |
381 } | 389 } |
382 | 390 |
383 public final Type value(Type)() { | 391 public final Type value(Type)() { |
384 static if ( is(Type == QBitArray) ) | 392 static if ( is(Type == QBitArray) ) |
385 return toBitArra; | 393 return toBitArray; |
386 else static if ( is(Type == bool) ) | 394 else static if ( is(Type == bool) ) |
387 return toBool; | 395 return toBool; |
388 else static if ( is(Type == QByteArray) ) | 396 else static if ( is(Type == QByteArray) ) |
389 return toByteArray; | 397 return toByteArray; |
390 else static if ( is(Type == QDate) ) | 398 else static if ( is(Type == QDate) ) |
610 } | 618 } |
611 | 619 |
612 protected override void __deleteNative() { | 620 protected override void __deleteNative() { |
613 qtd_QVariant_destructor(__nativeId); | 621 qtd_QVariant_destructor(__nativeId); |
614 } | 622 } |
615 | 623 |
616 public alias void __isValueType; | 624 public alias void __isValueType; |
617 | 625 |
618 public alias void __isQtType_QVariant; | 626 public alias void __isQtType_QVariant; |
619 | 627 |
620 struct QTypeInfo | 628 struct QTypeInfo |
621 { | 629 { |
622 enum bool isComplex = true; | 630 enum bool isComplex = true; |
623 enum bool isStatic = false; | 631 enum bool isStatic = false; |
624 enum bool isLarge = true; | 632 enum bool isLarge = true; |
625 enum bool isPointer = false; | 633 enum bool isPointer = false; |
626 enum bool isDummy = false; | 634 enum bool isDummy = false; |
627 } | 635 } |
628 | 636 |
629 static void* __constructNativeCopy(const void* orig) { | 637 static void* __constructNativeCopy(const void* orig) { |
630 return qtd_QVariant_QVariant_QVariant(cast(void*)orig); | 638 return qtd_QVariant_QVariant_QVariant(cast(void*)orig); |
631 } | 639 } |
632 | 640 |
633 static void* __constructPlacedNativeCopy(const void* orig, void* place) { | 641 static void* __constructPlacedNativeCopy(const void* orig, void* place) { |
634 return qtd_QVariant_placed_copy(orig, place); | 642 return qtd_QVariant_placed_copy(orig, place); |
635 } | 643 } |
636 | 644 |
637 public static void __deleteNativeObject(void* ptr) { | 645 public static void __deleteNativeObject(void* ptr) { |
638 qtd_QVariant_destructor(ptr); | 646 qtd_QVariant_destructor(ptr); |
639 } | 647 } |
640 | 648 |
641 public static void __callNativeDestructor(void* ptr) { | 649 public static void __callNativeDestructor(void* ptr) { |
642 qtd_QVariant_call_destructor(ptr); | 650 qtd_QVariant_call_destructor(ptr); |
643 } | 651 } |
644 // Injected code in class | 652 // Injected code in class |
645 } | 653 } |