Procházet zdrojové kódy

added Type.allEnums()

Nicolas Cannasse před 14 roky
rodič
revize
d44877d3eb

+ 1 - 0
doc/CHANGES.txt

@@ -1,5 +1,6 @@
 2012-??-??: 3.00
 	all : optimized const == const and const != const (with different const types)
+	all : add Type.allEnums(e)
 
 2011-09-25: 2.08
 	js : added js.JQuery

+ 6 - 0
std/Type.hx

@@ -144,5 +144,11 @@ extern class Type {
 		Returns the index of the constructor of an enum
 	**/
 	public static function enumIndex( e : Dynamic ) : Int;
+
+	/**
+		Returns the list of all enum values that don't take any parameter.
+	**/
+	public static function allEnums<T>( e : Enum<T> ) : Array<T>;
+
 }
 

+ 6 - 0
std/cpp/_std/Type.hx

@@ -148,5 +148,11 @@ enum ValueType {
 			return e.__Index();
 	}
 
+	public static function allEnums<T>( e : Enum<T> ) : Array<T> {
+		var all = [];
+		throw "TODO";
+		return all;
+	}
+
 }
 

+ 11 - 0
std/flash/_std/Type.hx

@@ -196,5 +196,16 @@ enum ValueType {
 		return e[1];
 	}
 
+	public static function allEnums<T>( e : Enum<T> ) : Array<T> {
+		var all = [];
+		var cst : Array<String> = untyped e.__constructs__;
+		for( c in cst ) {
+			var v = Reflect.field(e,c);
+			if( !Reflect.isFunction(v) )
+				all.push(v);
+		}
+		return all;
+	}
+
 }
 

+ 11 - 0
std/flash9/_std/Type.hx

@@ -271,5 +271,16 @@ enum ValueType {
 		return e.index;
 	}
 
+	public static function allEnums<T>( e : Enum<T> ) : Array<T> {
+		var all = [];
+		var cst : Array<String> = untyped e.__constructs__;
+		for( c in cst ) {
+			var v = Reflect.field(e,c);
+			if( !Reflect.isFunction(v) )
+				all.push(v);
+		}
+		return all;
+	}
+
 }
 

+ 11 - 0
std/js/_std/Type.hx

@@ -216,5 +216,16 @@ enum ValueType {
 		return e[1];
 	}
 
+	public static function allEnums<T>( e : Enum<T> ) : Array<T> {
+		var all = [];
+		var cst : Array<String> = untyped e.__constructs__;
+		for( c in cst ) {
+			var v = Reflect.field(e,c);
+			if( !Reflect.isFunction(v) )
+				all.push(v);
+		}
+		return all;
+	}
+
 }
 

+ 11 - 0
std/neko/_std/Type.hx

@@ -211,6 +211,17 @@ enum ValueType {
 	public inline static function enumIndex( e : Dynamic ) : Int {
 		return e.index;
 	}
+	
+	public static function allEnums<T>( e : Enum<T> ) : Array<T> {
+		var all = [];
+		var cst : Array<String> = untyped e.__constructs__;
+		for( c in cst ) {
+			var v = Reflect.field(e,c);
+			if( !Reflect.isFunction(v) )
+				all.push(v);
+		}
+		return all;
+	}
 
 }
 

+ 11 - 0
std/php/_std/Type.hx

@@ -225,5 +225,16 @@ enum ValueType {
 		return e.index;
 	}
 
+	public static function allEnums<T>( e : Enum<T> ) : Array<T> {
+		var all = [];
+		for( c in getEnumConstructs(e) ) {
+			var v = Reflect.field(e,c);
+			if( !Reflect.isFunction(v) )
+				all.push(v);
+		}
+		return all;
+	}
+
+
 }
 

+ 4 - 0
tests/unit/TestType.hx

@@ -70,4 +70,8 @@ class TestType extends Test {
 		// the current enum - since it's not cachable
 	}
 	
+	function testAllField() {
+		eq( Type.allEnums(MyEnum).join("#"), "A#B" );
+	}
+	
 }