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

/src/rt/typeinfo/ti_Acreal.d

http://github.com/AlexeyProkhin/druntime
D | 79 lines | 54 code | 12 blank | 13 comment | 10 complexity | 031ded90f8915bf8313cb8ca2da90697 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_Acreal;
15
16private import rt.typeinfo.ti_creal;
17private import rt.util.hash;
18
19// creal[]
20
21class TypeInfo_Ac : TypeInfo_Array
22{
23    override bool opEquals(Object o) { return TypeInfo.opEquals(o); }
24
25    @trusted:
26    const:
27    pure:
28    nothrow:
29
30    override string toString() const pure nothrow @safe { return "creal[]"; }
31
32    override size_t getHash(in void* p)
33    {
34        creal[] s = *cast(creal[]*)p;
35        return hashOf(s.ptr, s.length * creal.sizeof);
36    }
37
38    override bool equals(in void* p1, in void* p2)
39    {
40        creal[] s1 = *cast(creal[]*)p1;
41        creal[] s2 = *cast(creal[]*)p2;
42        size_t len = s1.length;
43
44        if (len != s2.length)
45            return 0;
46        for (size_t u = 0; u < len; u++)
47        {
48            if (!TypeInfo_c._equals(s1[u], s2[u]))
49                return false;
50        }
51        return true;
52    }
53
54    override int compare(in void* p1, in void* p2)
55    {
56        creal[] s1 = *cast(creal[]*)p1;
57        creal[] s2 = *cast(creal[]*)p2;
58        size_t len = s1.length;
59
60        if (s2.length < len)
61            len = s2.length;
62        for (size_t u = 0; u < len; u++)
63        {
64            int c = TypeInfo_c._compare(s1[u], s2[u]);
65            if (c)
66                return c;
67        }
68        if (s1.length < s2.length)
69            return -1;
70        else if (s1.length > s2.length)
71            return 1;
72        return 0;
73    }
74
75    override @property const(TypeInfo) next() nothrow pure
76    {
77        return typeid(creal);
78    }
79}