/src/rt/typeinfo/ti_Ashort.d
D | 128 lines | 90 code | 23 blank | 15 comment | 14 complexity | 378285f6624487c3d4a789d5958abeb7 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_Ashort; 15 16private import core.stdc.string; 17private import rt.util.hash; 18 19// short[] 20 21class TypeInfo_As : 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 "short[]"; } 31 32 override size_t getHash(in void* p) 33 { 34 short[] s = *cast(short[]*)p; 35 return hashOf(s.ptr, s.length * short.sizeof); 36 } 37 38 override bool equals(in void* p1, in void* p2) 39 { 40 short[] s1 = *cast(short[]*)p1; 41 short[] s2 = *cast(short[]*)p2; 42 43 return s1.length == s2.length && 44 memcmp(cast(void *)s1, cast(void *)s2, s1.length * short.sizeof) == 0; 45 } 46 47 override int compare(in void* p1, in void* p2) 48 { 49 short[] s1 = *cast(short[]*)p1; 50 short[] s2 = *cast(short[]*)p2; 51 size_t len = s1.length; 52 53 if (s2.length < len) 54 len = s2.length; 55 for (size_t u = 0; u < len; u++) 56 { 57 int result = s1[u] - s2[u]; 58 if (result) 59 return result; 60 } 61 if (s1.length < s2.length) 62 return -1; 63 else if (s1.length > s2.length) 64 return 1; 65 return 0; 66 } 67 68 override @property const(TypeInfo) next() nothrow pure 69 { 70 return typeid(short); 71 } 72} 73 74 75// ushort[] 76 77class TypeInfo_At : TypeInfo_As 78{ 79 @trusted: 80 const: 81 pure: 82 nothrow: 83 84 override string toString() const pure nothrow @safe { return "ushort[]"; } 85 86 override int compare(in void* p1, in void* p2) 87 { 88 ushort[] s1 = *cast(ushort[]*)p1; 89 ushort[] s2 = *cast(ushort[]*)p2; 90 size_t len = s1.length; 91 92 if (s2.length < len) 93 len = s2.length; 94 for (size_t u = 0; u < len; u++) 95 { 96 int result = s1[u] - s2[u]; 97 if (result) 98 return result; 99 } 100 if (s1.length < s2.length) 101 return -1; 102 else if (s1.length > s2.length) 103 return 1; 104 return 0; 105 } 106 107 override @property const(TypeInfo) next() nothrow pure 108 { 109 return typeid(ushort); 110 } 111} 112 113// wchar[] 114 115class TypeInfo_Au : TypeInfo_At 116{ 117 @trusted: 118 const: 119 pure: 120 nothrow: 121 122 override string toString() const pure nothrow @safe { return "wchar[]"; } 123 124 override @property const(TypeInfo) next() nothrow pure 125 { 126 return typeid(wchar); 127 } 128}