Pointer.hx 3.1 KB

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