VirtualArray.hx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. package cpp;
  23. @:native("cpp::VirtualArray")
  24. @:coreType extern class NativeVirtualArray implements ArrayAccess<Dynamic> {
  25. public function new():Void;
  26. public var length(get, null):Int;
  27. // concat<T>( a:Array<T> ) : Array<T> ?
  28. public function concat(a:VirtualArray):VirtualArray;
  29. public function join(sep:String):String;
  30. public function pop():Dynamic;
  31. public function push(x:Dynamic):Int;
  32. public function reverse():Void;
  33. public function shift():Dynamic;
  34. public function slice(pos:Int, ?end:Int):VirtualArray;
  35. public function sort(f:Dynamic->Dynamic->Int):Void;
  36. public function splice(pos:Int, len:Int):VirtualArray;
  37. public function toString():String;
  38. public function unshift(x:Dynamic):Void;
  39. public function insert(pos:Int, x:Dynamic):Void;
  40. public function remove(x:Dynamic):Bool;
  41. public function indexOf(x:Dynamic, ?fromIndex:Int):Int;
  42. public function lastIndexOf(x:Dynamic, ?fromIndex:Int):Int;
  43. public function copy():VirtualArray;
  44. public function iterator():Iterator<Dynamic>;
  45. public function map<S>(f:Dynamic->S):VirtualArray;
  46. public function filter(f:Dynamic->Bool):VirtualArray;
  47. public function resize(len:Int):Void;
  48. }
  49. abstract VirtualArray(NativeVirtualArray) {
  50. // Add these two functions...
  51. @:from extern inline static public function fromArray<T>(a:Array<T>):VirtualArray
  52. return untyped a;
  53. @:to extern inline public function toArray<T>():Array<T>
  54. return untyped this;
  55. // The rest is just boiler-plate
  56. inline public function new()
  57. this = new NativeVirtualArray();
  58. @:arrayAccess extern inline function get(idx:Int):Dynamic
  59. return untyped this[idx];
  60. @:arrayAccess extern inline function set<T>(pos:Int, value:T):T
  61. return untyped this[idx] = value;
  62. public var length(get, never):Int;
  63. extern inline public function get_length():Int
  64. return this.length;
  65. // concat<T>( a:Array<T> ) : Array<T> ?
  66. extern inline public function concat(a:VirtualArray):VirtualArray
  67. return this.concat(a);
  68. extern inline public function join(sep:String):String
  69. return this.join(sep);
  70. extern inline public function pop():Dynamic
  71. return this.pop();
  72. extern inline public function push(x:Dynamic):Int
  73. return this.push(x);
  74. extern inline public function reverse():Void
  75. this.reverse();
  76. extern inline public function shift():Dynamic
  77. return this.shift();
  78. extern inline public function slice(pos:Int, ?end:Int):VirtualArray
  79. return this.slice(pos, end);
  80. extern inline public function sort(f:Dynamic->Dynamic->Int):Void
  81. this.sort(f);
  82. extern inline public function splice(pos:Int, len:Int):VirtualArray
  83. return this.slice(pos, len);
  84. extern inline public function unshift(x:Dynamic):Void
  85. this.unshift(x);
  86. extern inline public function insert(pos:Int, x:Dynamic):Void
  87. this.insert(pos, x);
  88. extern inline public function remove(x:Dynamic):Bool
  89. return this.remove(x);
  90. extern inline public function indexOf(x:Dynamic, ?fromIndex:Int):Int
  91. return this.indexOf(x, fromIndex);
  92. extern inline public function lastIndexOf(x:Dynamic, ?fromIndex:Int):Int
  93. return this.lastIndexOf(x, fromIndex);
  94. extern inline public function copy():VirtualArray
  95. return this.copy();
  96. extern inline public function iterator():Iterator<Dynamic>
  97. return this.iterator();
  98. extern inline public function map<S>(f:Dynamic->S):VirtualArray
  99. return this.map(f);
  100. extern inline public function filter(f:Dynamic->Bool):VirtualArray
  101. return this.filter(f);
  102. extern inline public function resize(len:Int):Void
  103. return this.resize(len);
  104. }