root/trunk/Serial/utill.d

Revision 591, 1.0 kB (checked in by BCS, 3 years ago)

Added support for 3rd party types and arrays

Line 
1 module utill;
2
3 template ArrayDepth(T)
4 {
5     static if(is(T B == B[]))
6         const int ArrayDepth = 1 + ArrayDepth!(B);
7     else
8         const int ArrayDepth = 0;
9 }
10
11 static assert(0 == ArrayDepth!(int));
12 static assert(1 == ArrayDepth!(int[]));
13 static assert(2 == ArrayDepth!(int[][]));
14
15
16
17 template NameFromType(T, char[] suffix)
18 {
19     static if(is(T B == B[])) const char[] NameFromType = NameFromType!(B, "A" ~ suffix);
20     else static if(is(T B == B*)) const char[] NameFromType = NameFromType!(B, "P" ~ suffix);
21     else const char[] NameFromType = suffix == "" ? T.stringof : T.stringof ~ "-" ~ suffix;
22 }
23
24 template NameFromType(T)
25 {
26     const char[] NameFromType = NameFromType!(T,"");
27 }
28
29 pragma(msg, NameFromType!(int));
30 pragma(msg, NameFromType!(int[]));
31 pragma(msg, NameFromType!(int[][]));
32 pragma(msg, NameFromType!(int*[]));
33
34 template Usefull(T)
35 {
36     static if(is(T== struct))
37         alias T BaseType;
38     else static if(is(T U == U*))
39     {
40         static if(is(U == struct))
41             alias U BaseType;
42     }
43     else static if(is(T == class))
44         alias T BaseType;
45 }
Note: See TracBrowser for help on using the browser.