Array.hx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright (C)2005-2012 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. #if !macro
  23. import python.lib.Builtin;
  24. import python.internal.ArrayImpl;
  25. import python.lib.Types;
  26. #end
  27. @:native("list")
  28. @:coreApi
  29. extern class Array<T> implements ArrayAccess<T> extends ArrayImpl {
  30. public var length(default,null) : Int;
  31. private inline function get_length ():Int return ArrayImpl.get_length(this);
  32. public function new() : Void;
  33. public inline function concat( a : Array<T>) : Array<T> {
  34. return ArrayImpl.concat(this, a);
  35. }
  36. public inline function copy() : Array<T> {
  37. return ArrayImpl.copy(this);
  38. }
  39. @:runtime public inline function iterator() : Iterator<T> {
  40. return ArrayImpl.iterator(this);
  41. }
  42. public inline function insert( pos : Int, x : T ) : Void {
  43. return ArrayImpl.insert(this, pos, x);
  44. }
  45. @:runtime public inline function join( sep : String ) : String {
  46. return ArrayImpl.join(this, sep);
  47. }
  48. public inline function toString() : String {
  49. return ArrayImpl.toString(this);
  50. }
  51. @:runtime public inline function pop() : Null<T> {
  52. return ArrayImpl.pop(this);
  53. }
  54. @:runtime public inline function push(x:T) : Int {
  55. return ArrayImpl.push(this,x);
  56. }
  57. public inline function unshift(x : T) : Void {
  58. return ArrayImpl.unshift(this,x);
  59. }
  60. public inline function indexOf(x : T, ?fromIndex:Int) : Int {
  61. return ArrayImpl.indexOf(this,x, fromIndex);
  62. }
  63. public inline function lastIndexOf(x : T, ?fromIndex:Int) : Int {
  64. return ArrayImpl.lastIndexOf(this,x, fromIndex);
  65. }
  66. public inline function remove(x : T) : Bool {
  67. return ArrayImpl.remove(this,x);
  68. }
  69. public inline function reverse() : Void {
  70. return ArrayImpl.reverse(this);
  71. }
  72. @:runtime public inline function shift() : Null<T> {
  73. return ArrayImpl.shift(this);
  74. }
  75. public inline function slice( pos : Int, ?end : Int ) : Array<T> {
  76. return ArrayImpl.slice(this, pos, end);
  77. }
  78. public inline function sort(f:T->T->Int) : Void {
  79. return ArrayImpl.sort(this, f);
  80. }
  81. public inline function splice( pos : Int, len : Int ) : Array<T> {
  82. return ArrayImpl.splice(this, pos, len);
  83. }
  84. public inline function map<S>( f : T -> S ) : Array<S> {
  85. return ArrayImpl.map(this, f);
  86. }
  87. public inline function filter( f : T -> Bool ) : Array<T> {
  88. return ArrayImpl.filter(this,f);
  89. }
  90. @:keep private inline function __get(idx:Int):T
  91. {
  92. return ArrayImpl.__get(this, idx);
  93. }
  94. @:keep private inline function __set(idx:Int, val:T):T
  95. {
  96. return ArrayImpl.__set(this, idx,val);
  97. }
  98. @:keep private inline function __unsafe_get(idx:Int):T
  99. {
  100. return ArrayImpl.__unsafe_get(this, idx);
  101. }
  102. @:keep private inline function __unsafe_set(idx:Int, val:T):T
  103. {
  104. return ArrayImpl.__unsafe_set(this, idx,val);
  105. }
  106. @:noCompletion private function __iter__ ():PyIterator<T>;
  107. }