PageRenderTime 32ms CodeModel.GetById 11ms app.highlight 15ms RepoModel.GetById 2ms app.codeStats 0ms

/src/rt/typeinfo/ti_C.d

http://github.com/AlexeyProkhin/druntime
D | 70 lines | 44 code | 10 blank | 16 comment | 4 complexity | 54ca51fb923ef79558b4e1b8f5f111b1 MD5 | raw file
 1/**
 2 * TypeInfo support code.
 3 *
 4 * Copyright: Copyright Digital Mars 2004 - 2009.
 5 * License:   <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
 6 * Authors:   Walter Bright
 7 */
 8
 9/*          Copyright Digital Mars 2004 - 2009.
10 * Distributed under the Boost Software License, Version 1.0.
11 *    (See accompanying file LICENSE or copy at
12 *          http://www.boost.org/LICENSE_1_0.txt)
13 */
14module rt.typeinfo.ti_C;
15
16// Object
17
18class TypeInfo_C : TypeInfo
19{
20    @trusted:
21    const:
22    //pure:
23    //nothrow:
24
25    override size_t getHash(in void* p)
26    {
27        Object o = *cast(Object*)p;
28        return o ? o.toHash() : 0;
29    }
30
31    override bool equals(in void* p1, in void* p2)
32    {
33        Object o1 = *cast(Object*)p1;
34        Object o2 = *cast(Object*)p2;
35
36        return o1 == o2;
37    }
38
39    override int compare(in void* p1, in void* p2)
40    {
41        Object o1 = *cast(Object*)p1;
42        Object o2 = *cast(Object*)p2;
43        int c = 0;
44
45        // Regard null references as always being "less than"
46        if (!(o1 is o2))
47        {
48            if (o1)
49            {
50                if (!o2)
51                    c = 1;
52                else
53                    c = o1.opCmp(o2);
54            }
55            else
56                c = -1;
57        }
58        return c;
59    }
60
61    override @property size_t tsize() nothrow pure
62    {
63        return Object.sizeof;
64    }
65
66    override @property uint flags() nothrow pure
67    {
68        return 1;
69    }
70}