1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.core.typeinfo;
15 
16 import std.traits;
17 import std.meta;
18 
19 enum QTypeInfoFlags {
20     Q_COMPLEX_TYPE = 0,
21     Q_PRIMITIVE_TYPE = 0x1,
22     Q_STATIC_TYPE = 0,
23     Q_MOVABLE_TYPE = 0x2,               // ### Qt6: merge movable and relocatable once QList no longer depends on it
24     Q_DUMMY_TYPE = 0x4,
25     Q_RELOCATABLE_TYPE = 0x8
26 };
27 /*static foreach(name; __traits(allMembers, QTypeInfoFlags))
28 {
29     mixin("enum " + name + " = QTypeInfoFlags." + name + ";");
30 }*/
31 enum Q_MOVABLE_TYPE = QTypeInfoFlags.Q_MOVABLE_TYPE;
32 enum Q_PRIMITIVE_TYPE = QTypeInfoFlags.Q_PRIMITIVE_TYPE;
33 enum Q_RELOCATABLE_TYPE = QTypeInfoFlags.Q_RELOCATABLE_TYPE;
34 
35 template is_integral(T)
36 {
37     enum is_integral = isIntegral!T || isBoolean!T || isSomeChar!T;
38 }
39 
40 template qIsTrivial(T)
41 {
42     enum qIsTrivial = is(T==enum) || is_integral!T;
43 }
44 
45 template qIsRelocatable(T)
46 {
47     enum qIsRelocatable = is(T==enum) || is_integral!T;
48 }
49 
50 template QTypeInfo(T)
51 {
52     static if(is(T == R*, R) || is(T == class))
53     {
54         enum isRelocatable = true;
55         enum isComplex = false;
56         enum isStatic = false;
57     }
58     else static if(is(T == int) || is(T == uint) || is(T == double))
59     {
60         enum isRelocatable = true;
61         enum isComplex = false;
62         enum isStatic = false;
63     }
64     else static if(is(T == enum))
65     {
66         enum isRelocatable = true;
67         enum isComplex = false;
68         enum isStatic = true;
69     }
70     else static if(getUDAs!(T, QTypeInfoFlags).length)
71     {
72         enum combinedFlags = (){
73             QTypeInfoFlags r;
74             foreach(flag; getUDAs!(T, QTypeInfoFlags))
75             {
76                 r |= flag;
77             }
78             return r;
79         }();
80         enum isComplex = (combinedFlags & Q_PRIMITIVE_TYPE) == 0 && !qIsTrivial!T;
81         enum isStatic = (combinedFlags & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0;
82         enum isRelocatable = !isStatic || ((combinedFlags) & Q_RELOCATABLE_TYPE) || qIsRelocatable!T;
83     }
84     else
85     {
86         enum isRelocatable = qIsRelocatable!T;
87         enum isComplex = !qIsTrivial!T;
88         enum isStatic = true;
89     }
90     enum isLarge = T.sizeof > (void*).sizeof;
91     
92     //pragma(msg, T.stringof, " ", isRelocatable, isComplex, isStatic, isLarge);
93 }
94 alias QTypeInfoQuery = QTypeInfo;