Array.hx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 function insert( pos : Int, x : T ) : Void;
  43. public inline function join( sep : String ) : String {
  44. return ArrayImpl.join(this, sep);
  45. }
  46. public inline function toString() : String {
  47. return ArrayImpl.toString(this);
  48. }
  49. @:runtime public inline function pop() : Null<T> {
  50. return ArrayImpl.pop(this);
  51. }
  52. @:runtime public inline function push(x:T) : Int {
  53. return ArrayImpl.push(this,x);
  54. }
  55. public inline function unshift(x : T) : Void {
  56. return ArrayImpl.unshift(this,x);
  57. }
  58. public inline function indexOf(x : T, ?fromIndex:Int) : Int {
  59. return ArrayImpl.indexOf(this,x, fromIndex);
  60. }
  61. public inline function lastIndexOf(x : T, ?fromIndex:Int) : Int {
  62. return ArrayImpl.lastIndexOf(this,x, fromIndex);
  63. }
  64. public inline function remove(x : T) : Bool {
  65. return ArrayImpl.remove(this,x);
  66. }
  67. public function reverse() : Void;
  68. @:runtime public inline function shift() : Null<T> {
  69. return ArrayImpl.shift(this);
  70. }
  71. public inline function slice( pos : Int, ?end : Int ) : Array<T> {
  72. return ArrayImpl.slice(this, pos, end);
  73. }
  74. public inline function sort(f:T->T->Int) : Void {
  75. return ArrayImpl.sort(this, f);
  76. }
  77. public inline function splice( pos : Int, len : Int ) : Array<T> {
  78. return ArrayImpl.splice(this, pos, len);
  79. }
  80. public inline function map<S>( f : T -> S ) : Array<S> {
  81. return ArrayImpl.map(this, f);
  82. }
  83. public inline function filter( f : T -> Bool ) : Array<T> {
  84. return ArrayImpl.filter(this,f);
  85. }
  86. @:keep private inline function __get(idx:Int):T
  87. {
  88. return ArrayImpl.__get(this, idx);
  89. }
  90. @:keep private inline function __set(idx:Int, val:T):T
  91. {
  92. return ArrayImpl.__set(this, idx,val);
  93. }
  94. @:keep private inline function __unsafe_get(idx:Int):T
  95. {
  96. return ArrayImpl.__unsafe_get(this, idx);
  97. }
  98. @:keep private inline function __unsafe_set(idx:Int, val:T):T
  99. {
  100. return ArrayImpl.__unsafe_set(this, idx,val);
  101. }
  102. @:noCompletion private function __iter__ ():PyIterator<T>;
  103. }