Created
July 26, 2012 13:51
-
-
Save waneck/3182127 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@:generic class NativeArrayWrapper<T> | |
{ | |
public var cls(default, null):Class<T>; | |
public function get(idx:Int):Dynamic { return throw "not implemented"; } | |
public function get_f(idx:Int):Float { return get(idx); } | |
public function set(idx:Int, v:Dynamic):Dynamic { return throw "not implemented"; } | |
public function set_f(idx:Int, v:Float):Float { return set(idx, v); } | |
public static function alloc<T>(cl:Class<T>, size:Int):NativeArrayWrapper<T> | |
{ | |
switch(cl) | |
{ | |
case Int: return new IntNativeArray(size); | |
case .... | |
default: return new DynamicNativeArray(cl, size); | |
} | |
} | |
} | |
class IntNativeArray extends NativeArrayWrapper<Int> | |
{ | |
private var arr:NativeArray<Int>; | |
public function new(size:Int) | |
{ | |
this.cls = Int; | |
this.arr = new NativeArray<Int>(size); | |
} | |
override public function get(idx:Int):Dynamic | |
{ | |
return arr[idx]; | |
} | |
override public function get_f(idx:Int):Float | |
{ | |
return arr[idx]; | |
} | |
override public function set(idx:Int, v:Dynamic):Dynamic | |
{ | |
arr[idx] = v; | |
return v; | |
} | |
override public function set_f(idx:Int, v:Float):Float | |
{ | |
return arr[idx] = cast v; | |
} | |
} | |
//and so on.. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment