[Gridflow-cvs] [svn] commit: r6284 - in /trunk/src: classes2.cxx gridflow.cxx gridflow.hxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Sun Sep 19 16:47:01 EDT 2010


Author: matju
Date: Sun Sep 19 16:46:59 2010
New Revision: 6284

Log:
add noparens in [args]; move join() to .h; change return-type of atomtype_to_s; support more types in <<(t_atom2)

Modified:
    trunk/src/classes2.cxx
    trunk/src/gridflow.cxx
    trunk/src/gridflow.hxx

Modified: trunk/src/classes2.cxx
==============================================================================
--- trunk/src/classes2.cxx (original)
+++ trunk/src/classes2.cxx Sun Sep 19 16:46:59 2010
@@ -46,12 +46,6 @@
 
 #define foreach(ITER,COLL) for(typeof(COLL.begin()) ITER = COLL.begin(); ITER != (COLL).end(); ITER++)
 
-string join (int argc, t_atom *argv, string sep=" ", string term="") {
-	ostringstream os;
-	for (int i=0; i<argc; i++) os << argv[i] << (i==argc-1 ? term : sep);
-	return os.str();
-}
-
 /* get the owner of the result of canvas_getenv */
 static t_canvas *canvas_getabstop(t_canvas *x) {
     while (!x->gl_env) if (!(x = x->gl_owner)) bug("t_canvasenvironment %p", x);
@@ -71,6 +65,10 @@
 	if (argv[0].a_type==A_FLOAT && argc==1) {pd_float(o,argv[0].a_float); return;}
 	if (argv[0].a_type==A_SYMBOL) pd_typedmess(o,argv[0].a_symbol,argc-1,argv+1);
 	else                          pd_typedmess(o,&s_list         ,argc  ,argv  );
+}
+
+static void dont_handle_parens (int ac, t_atom2 *av) {
+	for (int i=0; i<ac; i++) if (av[i]==s_comma) SETCOMMA(&av[i]);
 }
 
 \class Args : FObject {
@@ -100,7 +98,7 @@
 	\decl 0 bang () {
 		t_canvasenvironment *env = canvas_getenv(mom); int ac = env->ce_argc; t_atom2 av[ac];
 		for (int i=0; i<ac; i++) av[i] = env->ce_argv[i];
-		ac = handle_parens(ac,av);
+		if (noparens) dont_handle_parens(ac,av); else ac = handle_parens(ac,av);
 		int j; for (j=0; j<ac; j++) if (av[j].a_type==A_COMMA) break;
 		process_args(j,av);
 		while (j<ac) {

Modified: trunk/src/gridflow.cxx
==============================================================================
--- trunk/src/gridflow.cxx (original)
+++ trunk/src/gridflow.cxx Sun Sep 19 16:46:59 2010
@@ -66,6 +66,8 @@
 BUILTIN_SYMBOLS(FOO)
 #undef FOO
 
+string t_atom2::to_s() {ostringstream os; os << *this; return os.str();}
+
 Barf::Barf(const char *s, ...) {
     ostringstream os; va_list ap; va_start(ap,s  ); voprintf(os,s  ,ap);
     va_end(ap); text = os.str();}
@@ -83,10 +85,22 @@
         ::error("[%s]: %s",os.str().data(),text.data());
 }
 
+// gf/expr
+#define A_OP    t_atomtype(0x1000)
+#define A_VAR   t_atomtype(0x1001) /* for $f1-style variables, not other variables */
+#define A_OPEN  t_atomtype(0x1002) /* only between next() and parse() */
+#define A_CLOSE t_atomtype(0x1003) /* only between next() and parse() */
+
 #define Z(T) case T: return #T; break;
-const char *atomtype_to_s (t_atomtype t) {
-  switch (t) {Z(A_FLOAT)Z(A_SYMBOL)Z(A_POINTER)Z(A_DOLLAR)Z(A_DOLLSYM)Z(A_COMMA)Z(A_SEMI)Z(A_LIST)Z(A_GRID)Z(A_GRIDOUT)
-  default: return "unknown type";}}
+string atomtype_to_s (t_atomtype t) {
+  switch (int(t)) {
+    Z(A_FLOAT)Z(A_SYMBOL)Z(A_POINTER)Z(A_LIST)Z(A_GRID)Z(A_GRIDOUT)
+    Z(A_DOLLAR)Z(A_DOLLSYM)Z(A_COMMA)Z(A_SEMI)
+    Z(A_OP)Z(A_VAR)Z(A_OPEN)Z(A_CLOSE)
+    Z(A_CANT)Z(A_NULL)
+    default: ostringstream os; oprintf(os,"unknown:%d",int(t)); return os.str();
+  }
+}
 #undef Z
 
 void pd_oprint (ostream &o, int argc, t_atom *argv) {
@@ -163,7 +177,7 @@
 
 // backslash is doubled here because Pd doesn't do it and Tcl's eval interprets a double backslash as a single.
 ostream &operator << (ostream &self, const t_atom &a) {
-	switch (a.a_type) {
+	switch (int(a.a_type)) {
 		case A_FLOAT:   self << a.a_float; break;
 		case A_SYMBOL:  self << a.a_symbol->s_name; break; // i would rather show backslashes here...
 		case A_DOLLSYM: self << a.a_symbol->s_name; break; // for real, it's the same thing as A_SYMBOL in pd >= 0.40
@@ -180,7 +194,11 @@
 			self << ")";
 			break;
 		}
-		default: self << "\\\\a(" << atomtype_to_s(a.a_type) << " " << std::hex << a.a_gpointer << std::dec << ")"; break;
+		case A_NULL: case A_CANT: case A_OPEN: case A_CLOSE:
+			   self << "\\\\a(" << atomtype_to_s(a.a_type)                                                << ")"; break;
+		case A_OP: case A_VAR:
+			   self << "\\\\a(" << atomtype_to_s(a.a_type) << " " << std::hex << a.a_symbol   << std::dec << ")"; break;
+		default:   self << "\\\\a(" << atomtype_to_s(a.a_type) << " " << std::hex << a.a_gpointer << std::dec << ")"; break;
 	}
 	return self;
 }
@@ -192,7 +210,7 @@
     else if (a.a_type==A_POINTER) (*this)(a.a_gpointer);
     else if (a.a_type==A_LIST   ) (*this)((t_list *)a.a_gpointer);
     else if (a.a_type==A_BLOB   ) (*this)((t_blob *)a.a_gpointer);
-    else error("can't send atom whose type is %s",atomtype_to_s(a.a_type));
+    else {string s = atomtype_to_s(a.a_type); RAISE("can't send atom whose type is %s",s.data());}
     //self(1,av);
 }
 
@@ -204,7 +222,8 @@
 	if (a.a_type==A_POINTER) return a.a_gpointer==b.a_gpointer; // not deep
 	if (a.a_type==A_LIST)    return a.a_gpointer==b.a_gpointer; // not deep
 	if (a.a_type==A_BLOB)    return a.a_gpointer==b.a_gpointer; // not deep
-	RAISE("don't know how to compare elements of type %s",atomtype_to_s(a.a_type));
+	string s = atomtype_to_s(a.a_type);
+	RAISE("don't know how to compare elements of type %s",s.data());
 }
 //----------------------------------------------------------------
 // Dim

Modified: trunk/src/gridflow.hxx
==============================================================================
--- trunk/src/gridflow.hxx (original)
+++ trunk/src/gridflow.hxx Sun Sep 19 16:46:59 2010
@@ -66,7 +66,7 @@
 #define A_GRID    t_atomtype(14) /* (Grid *)    */
 #define A_GRIDOUT t_atomtype(15) /* (GridOut *) */
 
-const char *atomtype_to_s (t_atomtype t);
+string atomtype_to_s (t_atomtype t);
 
 #define gensym(s) gensym(const_cast<char *>(s))
 #define sys_vgui(FMT,ARGS...) sys_vgui(const_cast<char *>(FMT),ARGS)
@@ -282,6 +282,8 @@
 	template <class T> t_atom2 &operator = (T value) {set_atom(this,value); return *this;};
 	template <class T> t_atom2             (T value) {set_atom(this,value);              };
 	t_atom2 () {}
+
+	string to_s ();
 };
 
 template <class T> static inline T convert(const t_atom &x, T *foo) {
@@ -971,6 +973,12 @@
               ostream &operator << (ostream &self, const t_atom &a);
 static inline ostream &operator << (ostream &self, t_symbol *s) {self << s->s_name; return self;}
 
+static inline string join (int argc, t_atom *argv, string sep=" ", string term="") {
+	ostringstream os;
+	for (int i=0; i<argc; i++) os << argv[i] << (i==argc-1 ? term : sep);
+	return os.str();
+}
+
 // from pd/src/g_canvas.c
 struct _canvasenvironment {
     t_symbol *ce_dir;   /* directory patch lives in */



More information about the Gridflow-cvs mailing list