diff dstep/internal/Traits.d @ 16:19885b43130e

Huge update, the bridge actually works now
author Jacob Carlborg <doob@me.com>
date Sun, 03 Jan 2010 22:06:11 +0100
parents 033d260cfc9b
children c2fba45df857
line wrap: on
line diff
--- a/dstep/internal/Traits.d	Mon Aug 03 15:31:48 2009 +0200
+++ b/dstep/internal/Traits.d	Sun Jan 03 22:06:11 2010 +0100
@@ -6,6 +6,9 @@
  */
 module dstep.internal.Traits;
 
+import dstep.objc.bridge.Bridge;
+import dstep.internal.String;
+
 /**
  * Returns the name of the given function
  * 
@@ -36,10 +39,10 @@
 	const parameterNamesOf = parameterNamesOfImpl!(func);
 }
 
-private char[][] parameterNamesOfImpl (alias func) ()
+private string[] parameterNamesOfImpl (alias func) ()
 {
-	char[] funcStr = typeof(&func).stringof;
-	
+	string funcStr = typeof(&func).stringof;
+
 	auto start = funcStr.indexOf('(');
 	auto end = funcStr.indexOf(')');
 	
@@ -53,8 +56,8 @@
 		
 	funcStr ~= secondPattern;
 	
-	char[] token;
-	char[][] arr;
+	string token;
+	string[] arr;
 	
 	foreach (c ; funcStr)
 	{		
@@ -70,7 +73,10 @@
 		}			
 	}
 	
-	char[][] result;
+	if (arr.length == 1)
+		return arr;
+	
+	string[] result;
 	bool skip = false;
 	
 	foreach (str ; arr)
@@ -101,9 +107,78 @@
  */
 private size_t indexOf (T) (T[] arr, T element)
 {
-	foreach (i, e ; arr)
-		if (e == element)
-			return i;
+	static if (is(T == char) || is(T == wchar) || is(T == dchar))
+		foreach (i, dchar e ; arr)
+			if (e == element)
+				return i;
+	
+	else
+		foreach (i, e ; arr)
+			if (e == element)
+				return i;
 	
 	return size_t.max;
+}
+
+/**
+ * Evaluates to true if $(D_PARAM T) has a instance method with the given name
+ * 
+ * Params:
+ * 		T = the type of the class/struct
+ * 		method = the name of the method
+ */
+template hasInstanceMethod (T, string method)
+{
+	const hasInstanceMethod = is(typeof({
+		T t;
+		mixin("auto f = &t." ~ method ~ ";");
+	}));
+}
+
+/**
+ * Evaluates to true if $(D_PARAM T) has a class method with the given name
+ * 
+ * Params:
+ * 		T = the type of the class/struct
+ * 		method = the name of the method
+ */
+template hasClassMethod (T, string method)
+{
+	const hasClassMethod = is(typeof({
+		mixin("auto f = &T." ~ method ~ ";");
+	}));
+}
+
+/**
+ * Evaluates to true if $(D_PARAM T) has a either a class method or a instance method
+ * with the given name.
+ * 
+ * Params:
+ * 		T = the type of the class/struct
+ * 		method = the name of the method
+ */
+template hasMethod (T, string method)
+{
+	const hasMethod = hasClassMethod!(T, method) || hasInstanceMethod!(T, method);
+}
+
+/**
+ * Evaluates to true if $(D_PARAM T) has a field with the given name
+ * 
+ * Params:
+ * 		T = the type of the class/struct
+ * 		field = the name of the field
+ */
+template hasField (T, string field)
+{
+	const hasField = is(typeof({
+		T t;
+		mixin("auto f = t." ~ field ~ ";");
+	}));
+}
+
+/// Evaluates to true if $(D_PARAM T) has binded methods
+template hasBindedMethods (T)
+{
+	const bool hasBindedMethods = hasField!(T, Bridge.objcClassMethodDeclarationVar) || hasField!(T, Bridge.objcMethodDeclarationVar);
 }
\ No newline at end of file