[Gridflow-cvs] [svn] commit: r5648 - in /trunk/src: gridflow.cxx gridflow.hxx source_filter.rb

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Tue May 11 21:42:36 EDT 2010


Author: matju
Date: Tue May 11 21:42:34 2010
New Revision: 5648

Log:
use std::map for method-list

Modified:
    trunk/src/gridflow.cxx
    trunk/src/gridflow.hxx
    trunk/src/source_filter.rb

Modified: trunk/src/gridflow.cxx
==============================================================================
--- trunk/src/gridflow.cxx (original)
+++ trunk/src/gridflow.cxx Tue May 11 21:42:34 2010
@@ -545,8 +545,10 @@
 #define pd_classname(x) (fclasses_pd[pd_class(x)]->name.data())
 
 static FMethod funcall_lookup (FClass *fclass, const char *sel) {
-	int n = fclass->methodsn;
-	for (int i=0; i<n; i++) if (strcmp(fclass->methods[i].selector,sel)==0) return fclass->methods[i].method;
+	string s = sel;
+	typeof(fclass->methods) &m = fclass->methods;
+	typeof(m.begin()) it = m.find(s);
+	if (it!=m.end()) return it->second;
 	if (fclass->super) return funcall_lookup(fclass->super,sel);
 	return 0;
 }
@@ -892,7 +894,7 @@
 	foreach(attr,fc->attrs) post("    %s %s;",attr->second->type.data(),attr->second->name.data());
 	post(")");
 	post("methods (");
-	for (int i=0; i<fc->methodsn; i++) post("    %s",fc->methods[i].selector);
+	foreach(meth,fc->methods) post("    %s",meth->first.data());
 	post(")");
 }
 \classinfo {}

Modified: trunk/src/gridflow.hxx
==============================================================================
--- trunk/src/gridflow.hxx (original)
+++ trunk/src/gridflow.hxx Tue May 11 21:42:34 2010
@@ -322,9 +322,6 @@
 	CObject() : refcount(0) {}
 	virtual ~CObject() {}
 };
-
-// you shouldn't use MethodDecl directly (used by source_filter.rb)
-struct MethodDecl {const char *selector; FMethod method;};
 
 #undef check
 
@@ -705,6 +702,8 @@
 #define MESSAGE t_symbol *sel, int argc, t_atom2 *argv
 #define MESSAGE2 sel,argc,argv
 #define MESSAGE3 t_symbol *, int, t_atom2 *
+// you shouldn't use MethodDecl directly (used by source_filter.rb)
+struct MethodDecl {const char *selector; FMethod method;};
 struct AttrDecl {
 	string name;
 	string type;
@@ -715,12 +714,12 @@
 	t_allocator allocator; // returns a new C++ object
 	void (*startup)(FClass *);
 	const char *cname; // C++ name (not PD name)
-	int methodsn; MethodDecl *methods;
 	FClass *super;
 	int ninlets;
 	int noutlets;
 	t_class *bfclass;
 	string name;
+	std::map<string,FMethod> methods;
 	std::map<string,AttrDecl *> attrs;
 };
 

Modified: trunk/src/source_filter.rb
==============================================================================
--- trunk/src/source_filter.rb (original)
+++ trunk/src/source_filter.rb Tue May 11 21:42:34 2010
@@ -211,9 +211,7 @@
 	cl = frame.name
 	line="{}" if /^\s*$/ =~ line
 	Out.print "static void #{cl}_startup (FClass *fclass); ALLOCATOR(#{cl});"
-	Out.print "static MethodDecl #{cl}_methods[] = {"
-	Out.print frame.methods.map {|foo,method| "{ \"#{method.selector}\",(FMethod)#{frame.name}::#{method.selector}_wrap }" }.join(",")
-	Out.print "}; FClass ci#{cl} = {#{cl}_allocator,#{cl}_startup,#{cl.inspect},COUNT(#{cl}_methods),#{cl}_methods};"
+	Out.print "FClass ci#{cl} = {#{cl}_allocator,#{cl}_startup,#{cl.inspect}};"
 	get="void ___get(t_symbol *s=0) {t_atom a[1];"
 	frame.attrs.each {|name,attr|
 		virtual = if attr.virtual then "(0,0)" else "" end
@@ -226,7 +224,8 @@
 	get << "RAISE(\"unknown attr %s\",s->s_name); outlet_anything(outlets[noutlets-1],s,1,a);}"
 	handle_def get if frame.attrs.size>0
 	Out.print "void #{frame.name}_startup (FClass *fclass) {"
-	frame.attrs.each {|name,attr| Out.print "fclass->attrs[\"#{name}\"] = new AttrDecl(\"#{name}\",\"#{attr.type}\");" }
+	frame.methods.each {|name,method| Out.print "fclass->methods[\"#{name}\"] = FMethod(#{frame.name}::#{method.selector}_wrap);" }
+	frame.attrs.each   {|name,attr|   Out.print "fclass->  attrs[\"#{name}\"           ] = new AttrDecl(\"#{name}\",\"#{attr.type}\");" }
 	Out.print line.chomp
 end
 



More information about the Gridflow-cvs mailing list