comparison orange/util/Traits.d @ 1:11a31bd929f9

Removed dependency on private library
author Jacob Carlborg <doob@me.com>
date Mon, 31 May 2010 16:06:36 +0200
parents f7b078e85f7f
children c4e7e64ffb67
comparison
equal deleted inserted replaced
0:f7b078e85f7f 1:11a31bd929f9
4 * Version: Initial created: Jan 26, 2010 4 * Version: Initial created: Jan 26, 2010
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
6 */ 6 */
7 module orange.util.Traits; 7 module orange.util.Traits;
8 8
9 public import mambo.util.Traits;
10
11 import orange.serialization.Serializable; 9 import orange.serialization.Serializable;
12 import orange.serialization.archives.Archive; 10 import orange.serialization.archives.Archive;
13 import orange.util._; 11 import orange.util._;
12
13 version (Tango)
14 {
15 import Tango = tango.core.Traits;
16 alias Tango.BaseTypeTupleOf BaseTypeTupleOf;
17 alias Tango.ParameterTupleOf ParameterTupleOf;
18 alias Tango.ReturnTypeOf ReturnTypeOf;
19 }
20
21 else
22 {
23 import Phobos = std.traits;
24 alias Phobos.BaseTypeTuple BaseTypeTupleOf;
25 alias Phobos.ParameterTypeTuple ParameterTupleOf;
26 alias Phobos.ReturnType ReturnTypeOf;
27
28 version = Phobos;
29 }
30
31 template isPrimitive (T)
32 {
33 const bool isPrimitive = is(T == bool) ||
34 is(T == byte) ||
35 is(T == cdouble) ||
36 //is(T == cent) ||
37 is(T == cfloat) ||
38 is(T == char) ||
39 is(T == creal) ||
40 is(T == dchar) ||
41 is(T == double) ||
42 is(T == float) ||
43 is(T == idouble) ||
44 is(T == ifloat) ||
45 is(T == int) ||
46 is(T == ireal) ||
47 is(T == long) ||
48 is(T == real) ||
49 is(T == short) ||
50 is(T == ubyte) ||
51 //is(T == ucent) ||
52 is(T == uint) ||
53 is(T == ulong) ||
54 is(T == ushort) ||
55 is(T == wchar);
56 }
57
58 template isChar (T)
59 {
60 const bool isChar = is(T == char) || is(T == wchar) || is(T == dchar);
61 }
62
63 template isClass (T)
64 {
65 const bool isClass = is(T == class);
66 }
67
68 template isInterface (T)
69 {
70 const bool isInterface = is(T == interface);
71 }
72
73 template isObject (T)
74 {
75 const bool isObject = isClass!(T) || isInterface!(T);
76 }
77
78 template isStruct (T)
79 {
80 const bool isStruct = is(T == struct);
81 }
82
83 template isArray (T)
84 {
85 static if (is(T U : U[]))
86 const bool isArray = true;
87
88 else
89 const bool isArray = false;
90 }
91
92 template isString (T)
93 {
94 const bool isString = is(T : char[]) || is(T : wchar[]) || is(T : dchar[]);
95 }
96
97 template isAssociativeArray (T)
98 {
99 const bool isAssociativeArray = is(typeof(T.init.values[0])[typeof(T.init.keys[0])] == T);
100 }
101
102 template isPointer (T)
103 {
104 static if (is(T U : U*))
105 const bool isPointer = true;
106
107 else
108 const bool isPointer = false;
109 }
110
111 template isFunctionPointer (T)
112 {
113 const bool isFunctionPointer = is(typeof(*T) == function);
114 }
115
116 template isEnum (T)
117 {
118 const bool isEnum = is(T == enum);
119 }
120
121 template isReference (T)
122 {
123 const bool isReference = isObject!(T) || isPointer!(T);
124 }
125
126 template isTypeDef (T)
127 {
128 const bool isTypeDef = is(T == typedef);
129 }
130
131 template isVoid (T)
132 {
133 const bool isVoid = is(T == void);
134 }
135
136 template BaseTypeOfArray (T)
137 {
138 static if (is(T U : U[]))
139 alias BaseTypeOfArray!(U) BaseTypeOfArray;
140
141 else
142 alias T BaseTypeOfArray;
143 }
144
145 template BaseTypeOfPointer (T)
146 {
147 static if (is(T U : U*))
148 alias BaseTypeOfPointer!(U) BaseTypeOfPointer;
149
150 else
151 alias T BaseTypeOfPointer;
152 }
153
154 template BaseTypeOfTypeDef (T)
155 {
156 static if (is(T U == typedef))
157 alias BaseTypeOfTypeDef!(U) BaseTypeOfTypeDef;
158
159 else
160 alias T BaseTypeOfTypeDef;
161 }
162
163 template KeyTypeOfAssociativeArray (T)
164 {
165 static assert(isAssociativeArray!(T), "The type needs to be an associative array");
166 alias typeof(T.init.keys[0]) KeyTypeOfAssociativeArray;
167 }
168
169 template ValueTypeOfAssociativeArray (T)
170 {
171 static assert(isAssociativeArray!(T), "The type needs to be an associative array");
172 alias typeof(T.init.values[0]) ValueTypeOfAssociativeArray;
173 }
14 174
15 template isArchive (T) 175 template isArchive (T)
16 { 176 {
17 const isArchive = is(typeof({ 177 const isArchive = is(typeof({
18 alias T.DataType Foo; 178 alias T.DataType Foo;