/src/rt/typeinfo/ti_Ashort.d

http://github.com/AlexeyProkhin/druntime · 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. /* Copyright Digital Mars 2004 - 2009.
  9. * Distributed under the Boost Software License, Version 1.0.
  10. * (See accompanying file LICENSE or copy at
  11. * http://www.boost.org/LICENSE_1_0.txt)
  12. */
  13. module rt.typeinfo.ti_Ashort;
  14. private import core.stdc.string;
  15. private import rt.util.hash;
  16. // short[]
  17. class TypeInfo_As : TypeInfo_Array
  18. {
  19. override bool opEquals(Object o) { return TypeInfo.opEquals(o); }
  20. @trusted:
  21. const:
  22. pure:
  23. nothrow:
  24. override string toString() const pure nothrow @safe { return "short[]"; }
  25. override size_t getHash(in void* p)
  26. {
  27. short[] s = *cast(short[]*)p;
  28. return hashOf(s.ptr, s.length * short.sizeof);
  29. }
  30. override bool equals(in void* p1, in void* p2)
  31. {
  32. short[] s1 = *cast(short[]*)p1;
  33. short[] s2 = *cast(short[]*)p2;
  34. return s1.length == s2.length &&
  35. memcmp(cast(void *)s1, cast(void *)s2, s1.length * short.sizeof) == 0;
  36. }
  37. override int compare(in void* p1, in void* p2)
  38. {
  39. short[] s1 = *cast(short[]*)p1;
  40. short[] s2 = *cast(short[]*)p2;
  41. size_t len = s1.length;
  42. if (s2.length < len)
  43. len = s2.length;
  44. for (size_t u = 0; u < len; u++)
  45. {
  46. int result = s1[u] - s2[u];
  47. if (result)
  48. return result;
  49. }
  50. if (s1.length < s2.length)
  51. return -1;
  52. else if (s1.length > s2.length)
  53. return 1;
  54. return 0;
  55. }
  56. override @property const(TypeInfo) next() nothrow pure
  57. {
  58. return typeid(short);
  59. }
  60. }
  61. // ushort[]
  62. class TypeInfo_At : TypeInfo_As
  63. {
  64. @trusted:
  65. const:
  66. pure:
  67. nothrow:
  68. override string toString() const pure nothrow @safe { return "ushort[]"; }
  69. override int compare(in void* p1, in void* p2)
  70. {
  71. ushort[] s1 = *cast(ushort[]*)p1;
  72. ushort[] s2 = *cast(ushort[]*)p2;
  73. size_t len = s1.length;
  74. if (s2.length < len)
  75. len = s2.length;
  76. for (size_t u = 0; u < len; u++)
  77. {
  78. int result = s1[u] - s2[u];
  79. if (result)
  80. return result;
  81. }
  82. if (s1.length < s2.length)
  83. return -1;
  84. else if (s1.length > s2.length)
  85. return 1;
  86. return 0;
  87. }
  88. override @property const(TypeInfo) next() nothrow pure
  89. {
  90. return typeid(ushort);
  91. }
  92. }
  93. // wchar[]
  94. class TypeInfo_Au : TypeInfo_At
  95. {
  96. @trusted:
  97. const:
  98. pure:
  99. nothrow:
  100. override string toString() const pure nothrow @safe { return "wchar[]"; }
  101. override @property const(TypeInfo) next() nothrow pure
  102. {
  103. return typeid(wchar);
  104. }
  105. }