PageRenderTime 30ms CodeModel.GetById 16ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/src/rt/typeinfo/ti_Areal.d

http://github.com/AlexeyProkhin/druntime
D | 96 lines | 66 code | 16 blank | 14 comment | 10 complexity | d460aa0c749ef833a76112bb99b02488 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_Areal;
15
16private import rt.typeinfo.ti_real;
17private import rt.util.hash;
18
19// real[]
20
21class TypeInfo_Ae : 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 "real[]"; }
31
32    override size_t getHash(in void* p)
33    {
34        real[] s = *cast(real[]*)p;
35        return hashOf(s.ptr, s.length * real.sizeof);
36    }
37
38    override bool equals(in void* p1, in void* p2)
39    {
40        real[] s1 = *cast(real[]*)p1;
41        real[] s2 = *cast(real[]*)p2;
42        size_t len = s1.length;
43
44        if (len != s2.length)
45            return false;
46        for (size_t u = 0; u < len; u++)
47        {
48            if (!TypeInfo_e._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        real[] s1 = *cast(real[]*)p1;
57        real[] s2 = *cast(real[]*)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_e._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(real);
78    }
79}
80
81// ireal[]
82
83class TypeInfo_Aj : TypeInfo_Ae
84{
85    @trusted:
86    const:
87    pure:
88    nothrow:
89
90    override string toString() const pure nothrow @safe { return "ireal[]"; }
91
92    override @property const(TypeInfo) next() nothrow pure
93    {
94        return typeid(ireal);
95    }
96}