Pointer.hx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. import haxe.extern.AsVar;
  24. @:coreType
  25. @:semantics(variable)
  26. extern class Pointer<T> extends ConstPointer<T> implements ArrayAccess<T> {
  27. var ref(get, set):Reference<T>;
  28. function get_ref():Reference<T>;
  29. function set_ref(t:T):Reference<T>;
  30. function setAt(inIndex:Int, value:T):Void;
  31. static function fromRaw<T>(ptr:RawPointer<T>):Pointer<T>;
  32. @:native("::cpp::Pointer_obj::fromRaw")
  33. static function fromStar<T>(star:Star<T>):Pointer<T>;
  34. @:native("::cpp::Pointer_obj::fromHandle")
  35. static function nativeFromHandle<T>(inHandle:Dynamic, ?inKind:String):AutoCast;
  36. inline static function fromHandle<T>(inHandle:Dynamic, ?inKind:String):Pointer<T> {
  37. return cast nativeFromHandle(inHandle, inKind);
  38. }
  39. static function fromPointer<T>(inNativePointer:Dynamic):Pointer<T>;
  40. static function addressOf<T>(inVariable:cpp.Reference<T>):Pointer<T>;
  41. static function endOf<T:{}>(inVariable:T):Pointer<cpp.Void>;
  42. @:native("::cpp::Pointer_obj::arrayElem")
  43. static function nativeArrayElem<T>(array:Array<T>, inElem:Int):AutoCast;
  44. inline static function arrayElem<T>(array:Array<T>, inElem:Int):Pointer<T> {
  45. return cast nativeArrayElem(array, inElem);
  46. }
  47. @:native("::cpp::Pointer_obj::ofArray")
  48. static function nativeOfArray<T>(array:Array<T>):AutoCast;
  49. inline static function ofArray<T>(array:Array<T>):Pointer<T> {
  50. return cast nativeOfArray(array);
  51. }
  52. inline function toUnmanagedArray(elementCount:Int):Array<T> {
  53. var result = new Array<T>();
  54. NativeArray.setUnmanagedData(result, this, elementCount);
  55. return result;
  56. }
  57. inline function toUnmanagedVector(elementCount:Int):haxe.ds.Vector<T>
  58. return cast toUnmanagedArray(elementCount);
  59. override function inc():Pointer<T>;
  60. override function dec():Pointer<T>;
  61. override function incBy(inT:Int):Pointer<T>;
  62. override function decBy(inT:Int):Pointer<T>;
  63. override function add(inT:Int):Pointer<T>;
  64. override function sub(inT:Int):Pointer<T>;
  65. function postIncRef():Reference<T>;
  66. function destroy():Void;
  67. function destroyArray():Void;
  68. }