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_Ag; 15 16 private import core.stdc.string; 17 private import core.internal.string; 18 19 // byte[] 20 21 class TypeInfo_Ag : TypeInfo_Array 22 { opEquals(Object o)23 override bool opEquals(Object o) { return TypeInfo.opEquals(o); } 24 toString()25 override string toString() const { return "byte[]"; } 26 getHash(scope const void * p)27 override size_t getHash(scope const void* p) @trusted const 28 { 29 const s = *cast(const void[]*)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 byte[] s1 = *cast(byte[]*)p1; 36 byte[] s2 = *cast(byte[]*)p2; 37 38 return s1.length == s2.length && 39 memcmp(cast(byte *)s1, cast(byte *)s2, s1.length) == 0; 40 } 41 compare(in void * p1,in void * p2)42 override int compare(in void* p1, in void* p2) const 43 { 44 byte[] s1 = *cast(byte[]*)p1; 45 byte[] s2 = *cast(byte[]*)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(byte); 66 } 67 } 68 69 70 // ubyte[] 71 72 class TypeInfo_Ah : TypeInfo_Ag 73 { toString()74 override string toString() const { return "ubyte[]"; } 75 compare(in void * p1,in void * p2)76 override int compare(in void* p1, in void* p2) const 77 { 78 char[] s1 = *cast(char[]*)p1; 79 char[] s2 = *cast(char[]*)p2; 80 81 return dstrcmp(s1, s2); 82 } 83 inout(TypeInfo)84 override @property inout(TypeInfo) next() inout 85 { 86 return cast(inout)typeid(ubyte); 87 } 88 } 89 90 // void[] 91 92 class TypeInfo_Av : TypeInfo_Ah 93 { toString()94 override string toString() const { return "void[]"; } 95 inout(TypeInfo)96 override @property inout(TypeInfo) next() inout 97 { 98 return cast(inout)typeid(void); 99 } 100 } 101 102 // bool[] 103 104 class TypeInfo_Ab : TypeInfo_Ah 105 { toString()106 override string toString() const { return "bool[]"; } 107 inout(TypeInfo)108 override @property inout(TypeInfo) next() inout 109 { 110 return cast(inout)typeid(bool); 111 } 112 } 113 114 // char[] 115 116 class TypeInfo_Aa : TypeInfo_Ah 117 { toString()118 override string toString() const { return "char[]"; } 119 getHash(scope const void * p)120 override size_t getHash(scope const void* p) @trusted const 121 { 122 char[] s = *cast(char[]*)p; 123 return hashOf(s); 124 } 125 inout(TypeInfo)126 override @property inout(TypeInfo) next() inout 127 { 128 return cast(inout)typeid(char); 129 } 130 } 131 132 // string 133 134 class TypeInfo_Aya : TypeInfo_Aa 135 { toString()136 override string toString() const { return "immutable(char)[]"; } 137 inout(TypeInfo)138 override @property inout(TypeInfo) next() inout 139 { 140 return cast(inout)typeid(immutable(char)); 141 } 142 } 143 144 // const(char)[] 145 146 class TypeInfo_Axa : TypeInfo_Aa 147 { toString()148 override string toString() const { return "const(char)[]"; } 149 inout(TypeInfo)150 override @property inout(TypeInfo) next() inout 151 { 152 return cast(inout)typeid(const(char)); 153 } 154 } 155