2
0

VirtualArray.hx 4.5 KB

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