StdTypes.hx 5.6 KB

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