Show
Ignore:
Timestamp:
06/11/09 03:30:07 (3 years ago)
Author:
BCS
Message:

Added support for 3rd party types and arrays

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Serial/utill.d

    r586 r591  
    11module utill; 
    22 
     3template 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 
     11static assert(0 == ArrayDepth!(int)); 
     12static assert(1 == ArrayDepth!(int[])); 
     13static assert(2 == ArrayDepth!(int[][])); 
     14 
     15 
     16 
     17template 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 
     24template NameFromType(T) 
     25{ 
     26    const char[] NameFromType = NameFromType!(T,""); 
     27} 
     28 
     29pragma(msg, NameFromType!(int)); 
     30pragma(msg, NameFromType!(int[])); 
     31pragma(msg, NameFromType!(int[][])); 
     32pragma(msg, NameFromType!(int*[])); 
    333 
    434template Usefull(T) 
    535{ 
    6     static if(is(T U == U*))  
     36    static if(is(T== struct)) 
     37        alias T BaseType; 
     38    else static if(is(T U == U*))  
    739    { 
    840        static if(is(U == struct))