Browse Source

[cpp] Add some setAt and Array helpers to Pointer

hughsando 9 years ago
parent
commit
f98b0bdd5b
1 changed files with 13 additions and 0 deletions
  1. 13 0
      std/cpp/Pointer.hx

+ 13 - 0
std/cpp/Pointer.hx

@@ -34,6 +34,8 @@ extern class Pointer<T> extends ConstPointer<T> implements ArrayAccess<T>
    @:analyzer(no_simplification)
    public function set_ref(t:T) : T;
 
+   @:analyzer(no_simplification)
+   public function setAt(inIndex:Int, value:T):Void;
 
    public static function fromRaw<T>(ptr:RawPointer<T>) : Pointer<T>;
 
@@ -45,6 +47,17 @@ extern class Pointer<T> extends ConstPointer<T> implements ArrayAccess<T>
 
    public static function arrayElem<T>(array:Array<T>, inElem:Int):Pointer<T>;
 
+   public static function ofArray<T>(array:Array<T>):Pointer<T>;
+
+   inline public function toUnmanagedArray(elementCount:Int) : Array<T>
+   {
+      var result = new Array<T>();
+      NativeArray.setUnmanagedData(result,this,elementCount);
+      return result;
+   }
+
+   inline public function toUnmanagedVector(elementCount:Int) : haxe.ds.Vector<T>
+      return cast toUnmanagedArray(elementCount);
  
 
    override public function inc():Pointer<T>;