PageRenderTime 46ms CodeModel.GetById 21ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 0ms

/runtime/typeinfo/ti_interface.d

http://github.com/wilkie/djehuty
D | 69 lines | 49 code | 13 blank | 7 comment | 9 complexity | fb69eac00bc04590cdb12ed6740bf62d MD5 | raw file
 1/*
 2 * ti_interface.d
 3 *
 4 * This module implements the TypeInfo for interfaces.
 5 *
 6 */
 7
 8class TypeInfo_Interface : TypeInfo {
 9	char[] toString() {
10		return info.name;
11	}
12
13	int opEquals(Object o) {
14		TypeInfo_Interface c;
15
16		return this is o ||
17				((c = cast(TypeInfo_Interface)o) !is null &&
18				 this.info.name == c.classinfo.name);
19	}
20
21	hash_t getHash(void *p) {
22		Interface* pi = **cast(Interface ***)*cast(void**)p;
23		Object o = cast(Object)(*cast(void**)p - pi.offset);
24		assert(o);
25		return o.toHash();
26	}
27
28	int equals(void *p1, void *p2) {
29		Interface* pi = **cast(Interface ***)*cast(void**)p1;
30		Object o1 = cast(Object)(*cast(void**)p1 - pi.offset);
31		pi = **cast(Interface ***)*cast(void**)p2;
32		Object o2 = cast(Object)(*cast(void**)p2 - pi.offset);
33
34		return o1 == o2 || (o1 && o1.opCmp(o2) == 0);
35	}
36
37	int compare(void *p1, void *p2) {
38		Interface* pi = **cast(Interface ***)*cast(void**)p1;
39		Object o1 = cast(Object)(*cast(void**)p1 - pi.offset);
40		pi = **cast(Interface ***)*cast(void**)p2;
41		Object o2 = cast(Object)(*cast(void**)p2 - pi.offset);
42		int c = 0;
43
44		// Regard null references as always being "less than"
45		if (o1 != o2) {
46			if (o1) {
47				if (!o2)
48					c = 1;
49				else
50					c = o1.opCmp(o2);
51			}
52			else
53				c = -1;
54		}
55		return c;
56	}
57
58	size_t tsize() {
59		return Object.sizeof;
60	}
61
62	uint flags() {
63		return 1;
64	}
65
66	ClassInfo info;
67}
68
69