Selaa lähdekoodia

[cpp] Use static function to get better typing in NativeArray. Small tweaks for Vector on cpp

Hugh 9 vuotta sitten
vanhempi
commit
7230d00743
2 muutettua tiedostoa jossa 22 lisäystä ja 5 poistoa
  1. 19 4
      std/cpp/NativeArray.hx
  2. 3 1
      std/haxe/ds/Vector.hx

+ 19 - 4
std/cpp/NativeArray.hx

@@ -49,6 +49,11 @@ extern class NativeArray {
 		untyped ioDestArray.zero(inFirst, inElements);
 	};
 
+	public static inline function memcmp<T>( inArrayA:Array<T>, inArrayB:Array<T>) : Int {
+		return untyped inArrayA.memcmp(inArrayB);
+	}
+
+   #if cppia
 	public static inline function unsafeGet<T>( inDestArray:Array<T>, inIndex:Int) : T {
 		return untyped inDestArray.__unsafe_get(inIndex);
 	}
@@ -57,11 +62,21 @@ extern class NativeArray {
 		return untyped ioDestArray.__unsafe_set(inIndex,inValue);
 	}
 
-	public static inline function memcmp<T>( inArrayA:Array<T>, inArrayB:Array<T>) : Int {
-		return untyped inArrayA.memcmp(inArrayB);
-	}
-
 	public static inline function setSize<T>( ioArray:Array<T>, inSize:Int) : Array<T> {
 		return untyped ioArray.__SetSizeExact(inSize);
    }
+
+   #else
+   @:native("_hx_array_unsafe_get")
+	public static function unsafeGet<T>( inDestArray:Array<T>, inIndex:Int) : T { return untyped null; }
+
+   @:native("_hx_array_unsafe_set")
+	public static inline function unsafeSet<T>( ioDestArray:Array<T>, inIndex:Int, inValue:T) : T {
+		return untyped ioDestArray.__unsafe_set(inIndex,inValue);
+	}
+
+   @:native("_hx_array_set_size_exact")
+	public static function setSize<T>( ioArray:Array<T>, inSize:Int) : Array<T> return null;
+   #end
+
 }

+ 3 - 1
std/haxe/ds/Vector.hx

@@ -68,7 +68,7 @@ abstract Vector<T>(VectorData<T>) {
 			this = new java.NativeArray(length);
 		#elseif cpp
 			this = new Array<T>();
-			untyped this.__SetSizeExact(length);
+			this.setSize(length);
 		#elseif python
 			this = python.Syntax.pythonCode("[{0}]*{1}", null, length);
 		#else
@@ -213,6 +213,8 @@ abstract Vector<T>(VectorData<T>) {
 		return fromData(java.Lib.nativeArray(array,false));
 		#elseif cs
 		return fromData(cs.Lib.nativeArray(array,false));
+		#elseif cpp
+		return cast array.copy();
 		#else
 		// TODO: Optimize this for flash (and others?)
 		var vec = new Vector<T>(array.length);