PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/runtime/typeinfo/ti_object.d

http://github.com/wilkie/djehuty
D | 54 lines | 38 code | 9 blank | 7 comment | 6 complexity | 13a7bbe62d7a0996b11f1cce2e04252e MD5 | raw file
 1/*
 2 * ti_object.d
 3 *
 4 * This module implements the TypeInfo for a class reference.
 5 *
 6 */
 7
 8module runtime.typeinfo.ti_object;
 9
10class TypeInfo_Class : TypeInfo {
11	hash_t getHash(void *p) {
12		Object o = *cast(Object*)p;
13		assert(o);
14		return o.toHash();
15	}
16
17	int equals(void *p1, void *p2) {
18		Object o1 = *cast(Object*)p1;
19		Object o2 = *cast(Object*)p2;
20
21		return o1 == o2;
22	}
23
24	int compare(void *p1, void *p2) {
25		Object o1 = *cast(Object*)p1;
26		Object o2 = *cast(Object*)p2;
27		int c = 0;
28
29		// Regard null references as always being "less than"
30		if (!(o1 is o2)) {
31			if (o1) {
32				if (!o2) {
33					c = 1;
34				}
35				else {
36					c = o1.opCmp(o2);
37				}
38			}
39			else {
40				c = -1;
41			}
42		}
43
44		return c;
45	}
46
47	size_t tsize() {
48		return Object.sizeof;
49	}
50
51	uint flags() {
52		return 1;
53	}
54}