StdTypes.hx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (C)2005-2013 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. // standard Haxe types
  23. /**
  24. The standard Void type. Only `null` values can be of the type `Void`.
  25. **/
  26. @:coreType abstract Void { }
  27. /**
  28. The standard Float type, this is a double-precision IEEE 64bit float.
  29. On static targets, null cannot be assigned to Float. If this is necessary,
  30. `Null<Float>` can be used instead.
  31. **/
  32. @:coreType @:notNull @:runtimeValue abstract Float { }
  33. /**
  34. The standard Int type. Its precision depends on the platform.
  35. On static targets, null cannot be assigned to Int. If this is necessary,
  36. `Null<Int>` can be used instead.
  37. **/
  38. @:coreType @:notNull @:runtimeValue abstract Int to Float { }
  39. #if (java || cs)
  40. @:coreType @:notNull @:runtimeValue abstract Single to Float from Float {}
  41. #end
  42. /**
  43. `Null` can be useful in two cases. In order to document some methods
  44. that accepts or can return a `null` value, or for the Flash9 compiler and AS3
  45. generator to distinguish between base values that can be null and others that
  46. can't.
  47. **/
  48. typedef Null<T> = T
  49. /**
  50. The standard Boolean type, which can either be true or false.
  51. On static targets, null cannot be assigned to Bool. If this is necessary,
  52. `Null<Bool>` can be used instead.
  53. **/
  54. @:coreType @:notNull @:runtimeValue abstract Bool {
  55. }
  56. /**
  57. Dynamic is a special type which is compatible with all other types.
  58. Use of Dynamic should be minimized as it prevents several compiler
  59. checks and optimizations.
  60. **/
  61. @:coreType @:runtimeValue abstract Dynamic<T> {
  62. }
  63. /**
  64. An Iterator is a structure that permits iteration over elements of type T.
  65. Any class with matching hasNext and next fields is considered an Iterator
  66. and can then be used e.g. in for-loops. This makes it easy to implement
  67. custom iterators.
  68. **/
  69. typedef Iterator<T> = {
  70. /**
  71. Returns false if the iteration is complete, true otherwise.
  72. Usually iteration is considered to be complete if all elements of the
  73. underlying data structure were handled through calls to next(). However,
  74. in custom iterators any logic may be used to determine the completion
  75. state.
  76. **/
  77. function hasNext() : Bool;
  78. /**
  79. Returns the current item of the Iterator and advances to the next one.
  80. This method is not required to check `hasNext` first. A call to this
  81. method while `hasNext` is false yields unspecified behavior.
  82. On the other hand iterators should not require a call to `hasNext`
  83. before the first call to `next` if an element is available.
  84. **/
  85. function next() : T;
  86. }
  87. /**
  88. An Iterable is a data structure which has an iterator() method.
  89. See `Lambda` for generic functions on iterable structures.
  90. **/
  91. typedef Iterable<T> = {
  92. function iterator() : Iterator<T>;
  93. }
  94. /**
  95. ArrayAccess is used to indicate a class that can be accessed using brackets.
  96. The type parameter represents the type of the elements stored.
  97. **/
  98. extern interface ArrayAccess<T> { }