[PD-cvs] pd/src desire.c,1.1.2.217.2.221,1.1.2.217.2.222

Mathieu Bouchard matju at users.sourceforge.net
Sat Aug 18 06:16:55 CEST 2007


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20929

Modified Files:
      Tag: desiredata
	desire.c 
Log Message:
more t_boxes


Index: desire.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/desire.c,v
retrieving revision 1.1.2.217.2.221
retrieving revision 1.1.2.217.2.222
diff -C2 -d -r1.1.2.217.2.221 -r1.1.2.217.2.222
*** desire.c	18 Aug 2007 02:59:39 -0000	1.1.2.217.2.221
--- desire.c	18 Aug 2007 04:16:51 -0000	1.1.2.217.2.222
***************
*** 80,83 ****
--- 80,84 ----
  
  struct t_boxes : t_gobj {
+ 	typedef  std::map<int,t_gobj *> M;
  	typedef std::pair<int,t_gobj *> KV;
  private:
***************
*** 90,101 ****
  		size_t n=0;
  		boxes_each(g,this) n++;
! 		//post("map size=%d list size=%d",map.size(),n);
  		return n;
  	}
! 	t_gobj *first() {return list;}
  	t_gobj *last()  {
  		t_gobj *r = first();
  		if (!r) return 0;
  		while (r->next()) r=r->next();
  		return r;
  	}
--- 91,109 ----
  		size_t n=0;
  		boxes_each(g,this) n++;
! 		if (map.size()!=n) post("map size=%d list size=%d",map.size(),n);
  		return n;
  	}
! 	t_gobj *first() {
! 		if (list && list != map.begin()->second) post("list first=%p map begin=%p",list,map.begin()->second);
! 		return list;
! 	}
  	t_gobj *last()  {
  		t_gobj *r = first();
  		if (!r) return 0;
  		while (r->next()) r=r->next();
+ 		M::iterator iter = map.end();
+ 		iter--;
+ 		t_gobj *lasse = iter->second;
+ 		if (r != lasse) post("list last=%p, map last=%p",r,lasse);
  		return r;
  	}
***************
*** 108,114 ****
  		invariant();
  	}
  	void remove_by_value(t_gobj *x) {
! 		if (list == x) list = x->next();
! 		else boxes_each(g,this) if (g->next() == x) {g->g_next = x->next(); break;}
  		invariant();
  	}
--- 116,129 ----
  		invariant();
  	}
+ 	void remove(int i) {
+ 		map.erase(i);
+ 		if (list->dix->index == i) list = list->next();
+ 		else boxes_each(g,this) if (g->next()->dix->index == i) {g->g_next = g->next()->next(); break;}
+ 		invariant();
+ 	}
  	void remove_by_value(t_gobj *x) {
! 		map.erase(x->dix->index);
! 		if (list == x) list = list->next();
! 		else boxes_each(g,this) if (g->next()             == x) {g->g_next = g->next()->next(); break;}
  		invariant();
  	}
***************
*** 506,516 ****
  /* --------------- traversing the set of lines in a canvas ----------- */
  
- /* get the index of a gobj in a canvas.  If y is zero, return the total number of objects. */
- int canvas_getindex(t_canvas *x, t_gobj *y) {
-     int i=0;
-     canvas_each(y2,x) {if (y2==y) break; else i++;}
-     return i;
- }
- 
  t_linetraverser::t_linetraverser(t_canvas *canvas) {linetraverser_start(this,canvas);}
  
--- 521,524 ----
***************
*** 1048,1056 ****
  }
  
- static t_gobj *canvas_nth(t_canvas *x, int n) {
-     canvas_each(y,x) if (!n) return y; else n--;
-     return 0;
- }
- 
  //#define canvas_each2(CHILD,CANVAS) for(CHILD=&(CANVAS)->list; *CHILD; CHILD=&(*CHILD)->next())
  /* just a raw remove, no other business */
--- 1056,1059 ----
***************
*** 1099,1118 ****
  }
  
  /* recursively check for abstractions to reload as result of a save.
     Don't reload the one we just saved ("except") though. */
  /*  LATER try to do the same trick for externs. */
  static void canvas_doreload(t_canvas *gl, t_symbol *name, t_symbol *dir, t_gobj *except) {
!     int i=0, nobj = canvas_getindex(gl, 0);  /* number of objects */
      for (t_gobj *g = gl->boxes->first(); g && i < nobj; i++) {
  	if (g != except && g->_class == canvas_class) {
  	    t_canvas *c = (t_canvas *)g;
  	    if (canvas_isabstraction(c) && c->name==name && canvas_getdir(c) == dir) {
! 		/* we're going to remake the object, so "g" will go stale. Get its index here,
! 		and afterward restore g.  Also, the replacement will be at the end of the list,
! 		so we don't do g = g->next() in this case. */
! 		int j = canvas_getindex(gl, g);
  		int hadwindow = gl->havewindow;
  		if (!hadwindow) canvas_vis(canvas_getcanvas(gl), 1);
! 		g = canvas_nth(gl, j);
  		if (!hadwindow) canvas_vis(canvas_getcanvas(gl), 0);
  		continue;
--- 1102,1126 ----
  }
  
+ static t_binbuf *canvas_cut_wires(t_canvas *x, t_gobj *o);
+ static void canvas_paste_wires(t_canvas *x, t_binbuf *buf);
+ 
  /* recursively check for abstractions to reload as result of a save.
     Don't reload the one we just saved ("except") though. */
  /*  LATER try to do the same trick for externs. */
  static void canvas_doreload(t_canvas *gl, t_symbol *name, t_symbol *dir, t_gobj *except) {
!     int i=0, nobj = gl->boxes->size();
      for (t_gobj *g = gl->boxes->first(); g && i < nobj; i++) {
  	if (g != except && g->_class == canvas_class) {
  	    t_canvas *c = (t_canvas *)g;
  	    if (canvas_isabstraction(c) && c->name==name && canvas_getdir(c) == dir) {
! 		/* we're going to remake the object, so "g" will go stale. Get its index here, and afterwards restore g.
!                    Also, the replacement will be at the end of the list, so we don't do g = g->next() in this case. */
! 		int j = g->dix->index;
  		int hadwindow = gl->havewindow;
  		if (!hadwindow) canvas_vis(canvas_getcanvas(gl), 1);
! 		t_binbuf *buf = canvas_cut_wires(gl,g);
! 		gl->boxes->remove(j);
! 		//MISSING: remake the object here.
! 		canvas_paste_wires(gl,buf);
  		if (!hadwindow) canvas_vis(canvas_getcanvas(gl), 0);
  		continue;
***************
*** 2715,2724 ****
  }
  
  static void canvas_saveto(t_canvas *x, t_binbuf *b) {
      canvas_savecontainerto(x,b);
      canvas_each(y,x) gobj_save(y, b);
      canvas_wires_each(oc,t,x) {
!         int from = canvas_getindex(x,t.from);
!         int to   = canvas_getindex(x,t.to);
          binbuf_addv(b, "ttiiii;","#X","connect", from, t.outlet, to, t.inlet);
  	appendix_save(oc,b);
--- 2723,2739 ----
  }
  
+ /* get the index of a gobj in a canvas.  If y is zero, return the total number of objects. */
+ int canvas_oldindex(t_canvas *x, t_gobj *y) {
+     int i=0;
+     canvas_each(y2,x) {if (y2==y) break; else i++;}
+     return i;
+ }
+ 
  static void canvas_saveto(t_canvas *x, t_binbuf *b) {
      canvas_savecontainerto(x,b);
      canvas_each(y,x) gobj_save(y, b);
      canvas_wires_each(oc,t,x) {
!         int from = canvas_oldindex(x,t.from);
!         int to   = canvas_oldindex(x,t.to);
          binbuf_addv(b, "ttiiii;","#X","connect", from, t.outlet, to, t.inlet);
  	appendix_save(oc,b);





More information about the Pd-cvs mailing list