StdTypes.hx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (C)2005-2017 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. @see https://haxe.org/manual/types-void.html
  26. **/
  27. @:coreType abstract Void { }
  28. /**
  29. The standard `Float` type, this is a double-precision IEEE 64bit float.
  30. On static targets, `null` cannot be assigned to Float. If this is necessary,
  31. `Null<Float>` can be used instead.
  32. `Std.int` converts a `Float` to an `Int`, rounded towards 0.
  33. `Std.parseFloat` converts a `String` to a `Float`.
  34. @see https://haxe.org/manual/types-basic-types.html
  35. @see https://haxe.org/manual/types-nullability.html
  36. **/
  37. @:coreType @:notNull @:runtimeValue abstract Float { }
  38. /**
  39. The standard `Int` type. Its precision depends on the platform.
  40. On static targets, `null` cannot be assigned to `Int`. If this is necessary,
  41. `Null<Int>` can be used instead.
  42. `Std.int` converts a `Float` to an `Int`, rounded towards 0.
  43. `Std.parseInt` converts a `String` to an `Int`.
  44. @see https://haxe.org/manual/types-basic-types.html
  45. @see https://haxe.org/manual/std-math-integer-math.html
  46. @see https://haxe.org/manual/types-nullability.html
  47. **/
  48. @:coreType @:notNull @:runtimeValue abstract Int to Float { }
  49. #if (java || cs || hl || cpp)
  50. /**
  51. Single-precision IEEE 32bit float (4-byte).
  52. **/
  53. @:coreType @:notNull @:runtimeValue abstract Single to Float from Float {}
  54. #end
  55. /**
  56. `Null` can be useful in two cases. In order to document some methods
  57. that accept or can return a `null` value, or for the Flash compiler and AS3
  58. generator to distinguish between base values that can be `null` and others that
  59. can't.
  60. @see https://haxe.org/manual/types-nullability.html
  61. **/
  62. @:forward
  63. @:coreType
  64. abstract Null<T> from T to T { }
  65. /**
  66. The standard Boolean type, which can either be `true` or `false`.
  67. On static targets, `null` cannot be assigned to `Bool`. If this is necessary,
  68. `Null<Bool>` can be used instead.
  69. @see https://haxe.org/manual/types-bool.html
  70. @see https://haxe.org/manual/types-nullability.html
  71. **/
  72. @:coreType @:notNull @:runtimeValue abstract Bool {
  73. }
  74. /**
  75. `Dynamic` is a special type which is compatible with all other types.
  76. Use of `Dynamic` should be minimized as it prevents several compiler
  77. checks and optimizations. See `Any` type for a safer alternative for
  78. representing values of any type.
  79. @see https://haxe.org/manual/types-dynamic.html
  80. **/
  81. @:coreType @:runtimeValue abstract Dynamic<T> {
  82. }
  83. /**
  84. An `Iterator` is a structure that permits iteration over elements of type `T`.
  85. Any class with matching `hasNext()` and `next()` fields is considered an `Iterator`
  86. and can then be used e.g. in `for`-loops. This makes it easy to implement
  87. custom iterators.
  88. @see https://haxe.org/manual/lf-iterators.html
  89. **/
  90. typedef Iterator<T> = {
  91. /**
  92. Returns `false` if the iteration is complete, `true` otherwise.
  93. Usually iteration is considered to be complete if all elements of the
  94. underlying data structure were handled through calls to `next()`. However,
  95. in custom iterators any logic may be used to determine the completion
  96. state.
  97. **/
  98. function hasNext() : Bool;
  99. /**
  100. Returns the current item of the `Iterator` and advances to the next one.
  101. This method is not required to check `hasNext()` first. A call to this
  102. method while `hasNext()` is `false` yields unspecified behavior.
  103. On the other hand, iterators should not require a call to `hasNext()`
  104. before the first call to `next()` if an element is available.
  105. **/
  106. function next() : T;
  107. }
  108. /**
  109. An `Iterable` is a data structure which has an `iterator()` method.
  110. See `Lambda` for generic functions on iterable structures.
  111. @see https://haxe.org/manual/lf-iterators.html
  112. **/
  113. typedef Iterable<T> = {
  114. function iterator() : Iterator<T>;
  115. }
  116. /**
  117. `ArrayAccess` is used to indicate a class that can be accessed using brackets.
  118. The type parameter represents the type of the elements stored.
  119. This interface should be used for externs only. Haxe does not support custom
  120. array access on classes. However, array access can be implemented for
  121. abstract types.
  122. @see https://haxe.org/manual/types-abstract-array-access.html
  123. **/
  124. extern interface ArrayAccess<T> { }