PageRenderTime 37ms CodeModel.GetById 17ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/rt/typeinfo/ti_int.d

http://github.com/AlexeyProkhin/druntime
D | 59 lines | 36 code | 10 blank | 13 comment | 4 complexity | 6e1be4efd61bb5b64e4d73ccaf796897 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_int;
15
16// int
17
18class TypeInfo_i : TypeInfo
19{
20    @trusted:
21    const:
22    pure:
23    nothrow:
24
25    override string toString() const pure nothrow @safe { return "int"; }
26
27    override size_t getHash(in void* p)
28    {
29        return *cast(uint *)p;
30    }
31
32    override bool equals(in void* p1, in void* p2)
33    {
34        return *cast(uint *)p1 == *cast(uint *)p2;
35    }
36
37    override int compare(in void* p1, in void* p2)
38    {
39        if (*cast(int*) p1 < *cast(int*) p2)
40            return -1;
41        else if (*cast(int*) p1 > *cast(int*) p2)
42            return 1;
43        return 0;
44    }
45
46    override @property size_t tsize() nothrow pure
47    {
48        return int.sizeof;
49    }
50
51    override void swap(void *p1, void *p2)
52    {
53        int t;
54
55        t = *cast(int *)p1;
56        *cast(int *)p1 = *cast(int *)p2;
57        *cast(int *)p2 = t;
58    }
59}