xref: /netbsd-src/external/gpl3/gcc.old/dist/libphobos/libdruntime/rt/typeinfo/ti_Ashort.d (revision 627f7eb200a4419d89b531d55fccd2ee3ffdcde0)
1 /**
2  * TypeInfo support code.
3  *
4  * Copyright: Copyright Digital Mars 2004 - 2009.
5  * License:   $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
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  */
14 module rt.typeinfo.ti_Ashort;
15 
16 private import core.stdc.string;
17 
18 // short[]
19 
20 class TypeInfo_As : TypeInfo_Array
21 {
opEquals(Object o)22     override bool opEquals(Object o) { return TypeInfo.opEquals(o); }
23 
toString()24     override string toString() const { return "short[]"; }
25 
getHash(scope const void * p)26     override size_t getHash(scope const void* p) @trusted const
27     {
28         // Hash as if unsigned.
29         const s = *cast(const ushort[]*)p;
30         return hashOf(s);
31     }
32 
equals(in void * p1,in void * p2)33     override bool equals(in void* p1, in void* p2) const
34     {
35         short[] s1 = *cast(short[]*)p1;
36         short[] s2 = *cast(short[]*)p2;
37 
38         return s1.length == s2.length &&
39                memcmp(cast(void *)s1, cast(void *)s2, s1.length * short.sizeof) == 0;
40     }
41 
compare(in void * p1,in void * p2)42     override int compare(in void* p1, in void* p2) const
43     {
44         short[] s1 = *cast(short[]*)p1;
45         short[] s2 = *cast(short[]*)p2;
46         size_t len = s1.length;
47 
48         if (s2.length < len)
49             len = s2.length;
50         for (size_t u = 0; u < len; u++)
51         {
52             int result = s1[u] - s2[u];
53             if (result)
54                 return result;
55         }
56         if (s1.length < s2.length)
57             return -1;
58         else if (s1.length > s2.length)
59             return 1;
60         return 0;
61     }
62 
inout(TypeInfo)63     override @property inout(TypeInfo) next() inout
64     {
65         return cast(inout)typeid(short);
66     }
67 }
68 
69 
70 // ushort[]
71 
72 class TypeInfo_At : TypeInfo_As
73 {
toString()74     override string toString() const { return "ushort[]"; }
75 
compare(in void * p1,in void * p2)76     override int compare(in void* p1, in void* p2) const
77     {
78         ushort[] s1 = *cast(ushort[]*)p1;
79         ushort[] s2 = *cast(ushort[]*)p2;
80         size_t len = s1.length;
81 
82         if (s2.length < len)
83             len = s2.length;
84         for (size_t u = 0; u < len; u++)
85         {
86             int result = s1[u] - s2[u];
87             if (result)
88                 return result;
89         }
90         if (s1.length < s2.length)
91             return -1;
92         else if (s1.length > s2.length)
93             return 1;
94         return 0;
95     }
96 
inout(TypeInfo)97     override @property inout(TypeInfo) next() inout
98     {
99         return cast(inout)typeid(ushort);
100     }
101 }
102 
103 // wchar[]
104 
105 class TypeInfo_Au : TypeInfo_At
106 {
toString()107     override string toString() const { return "wchar[]"; }
108 
inout(TypeInfo)109     override @property inout(TypeInfo) next() inout
110     {
111         return cast(inout)typeid(wchar);
112     }
113 }
114