Revision: 10390 http://pure-data.svn.sourceforge.net/pure-data/?rev=10390&view=rev Author: zmoelnig Date: 2008-11-26 11:13:07 +0000 (Wed, 26 Nov 2008)
Log Message: ----------- moved general functions into a header-file for reusability
Modified Paths: -------------- trunk/externals/iem/iemguts/src/savebangs.c
Added Paths: ----------- trunk/externals/iem/iemguts/src/iemguts-objlist.h
Added: trunk/externals/iem/iemguts/src/iemguts-objlist.h =================================================================== --- trunk/externals/iem/iemguts/src/iemguts-objlist.h (rev 0) +++ trunk/externals/iem/iemguts/src/iemguts-objlist.h 2008-11-26 11:13:07 UTC (rev 10390) @@ -0,0 +1,153 @@ +/****************************************************** + * + * iemguts - implementation file + * + * copyleft (c) IOhannes m zm\xF6lnig + * + * 2008:forum::f\xFCr::uml\xE4ute:2008 + * + * institute of electronic music and acoustics (iem) + * + ****************************************************** + * + * license: GNU General Public License v.2 + * + ******************************************************/ + +/* this file implements some helperr functions for dealing with lists of + * objects (containing other objects) + * + * used for callbacks to enumerated objects without $0 tricks + */ + +/* + * TODO: documentation + */ + +#include "m_pd.h" + + +/* ------------------------- helper methods for callbacks ---------------------------- */ + +typedef struct _iemguts_objlist { + const t_pd*obj; + struct _iemguts_objlist*next; +} t_iemguts_objlist; + +typedef struct _iemguts_canvaslist { + const t_pd*parent; + t_iemguts_objlist*obj; + + struct _iemguts_canvaslist*next; +} t_iemguts_canvaslist; + +static t_iemguts_canvaslist*s_canvaslist=0; + + +static t_iemguts_canvaslist*findCanvas(const t_pd*parent) { + t_iemguts_canvaslist*list=s_canvaslist; + if(0==parent || 0==list) + return 0; + + for(list=s_canvaslist; list; list=list->next) { + if(parent == list->parent) { + return list; + } + } + return 0; +} + +static t_iemguts_canvaslist*addCanvas(const t_pd*parent) +{ + t_iemguts_canvaslist*list=findCanvas(parent); + if(!list) { + list=(t_iemguts_canvaslist*)getbytes(sizeof(t_iemguts_canvaslist)); + list->parent=parent; + list->obj=0; + list->next=0; + + if(0==s_canvaslist) { + /* new list */ + s_canvaslist=list; + } else { + /* add to the end of existing list */ + t_iemguts_canvaslist*dummy=s_canvaslist; + while(dummy->next) + dummy=dummy->next; + dummy->next = list; + } + } + return list; +} + +static t_iemguts_objlist*objectsInCanvas(const t_pd*parent) { + t_iemguts_canvaslist*list=findCanvas(parent); + if(list) + return list->obj; + + return 0; +} + +static void addObjectToCanvas(const t_pd*parent, const t_pd*obj) { + t_iemguts_canvaslist*p=addCanvas(parent); + t_iemguts_objlist*list=0; + t_iemguts_objlist*entry=0; + if(!p || !obj) + return; + list=p->obj; + + if(list&&obj==list->obj) + return; + + while(list && list->next) { + if(obj==list->obj) /* obj already in list */ + return; + list=list->next; + } + + /* we are at the end of the list that does not contain obj yet, so add it */ + entry=(t_iemguts_objlist*)getbytes(sizeof(t_iemguts_objlist)); + entry->obj=obj; + entry->next=0; + if(list) { + list->next=entry; + } else { + p->obj=entry; + } +} + +static void removeObjectFromCanvas(const t_pd*parent, const t_pd*obj) { + t_iemguts_canvaslist*p=findCanvas(parent); + t_iemguts_objlist*list=0, *last=0, *next=0; + if(!p || !obj)return; + list=p->obj; + if(!list) + return; + + while(list && obj!=list->obj) { + last=list; + list=list->next; + } + + if(!list) /* couldn't find this object */ + return; + + next=list->next; + + if(last) + last->next=next; + else + p->obj=next; + + freebytes((void*)list, sizeof(t_iemguts_objlist)); + list=0; +} + +static void removeObjectFromCanvases(const t_pd*obj) { + t_iemguts_canvaslist*parents=s_canvaslist; + + while(parents) { + removeObjectFromCanvas(parents->parent, obj); + parents=parents->next; + } +}
Modified: trunk/externals/iem/iemguts/src/savebangs.c =================================================================== --- trunk/externals/iem/iemguts/src/savebangs.c 2008-11-26 09:51:01 UTC (rev 10389) +++ trunk/externals/iem/iemguts/src/savebangs.c 2008-11-26 11:13:07 UTC (rev 10390) @@ -33,134 +33,10 @@ * else we get weird duplicates (most likely due to the "$0" trick */
-#include "m_pd.h" +#include "iemguts-objlist.h" #include "g_canvas.h"
-/* ------------------------- helper methods for callbacks ---------------------------- */ -typedef struct _savebangs_objlist { - const t_pd*obj; - struct _savebangs_objlist*next; -} t_savebangs_objlist;
-typedef struct _savebangs_canvaslist { - const t_pd*parent; - t_savebangs_objlist*obj; - - struct _savebangs_canvaslist*next; -} t_savebangs_canvaslist; - -static t_savebangs_canvaslist*s_canvaslist=0; - - -static t_savebangs_canvaslist*findCanvas(const t_pd*parent) { - t_savebangs_canvaslist*list=s_canvaslist; - if(0==parent || 0==list) - return 0; - - for(list=s_canvaslist; list; list=list->next) { - if(parent == list->parent) { - return list; - } - } - return 0; -} - -static t_savebangs_canvaslist*addCanvas(const t_pd*parent) -{ - t_savebangs_canvaslist*list=findCanvas(parent); - if(!list) { - list=(t_savebangs_canvaslist*)getbytes(sizeof(t_savebangs_canvaslist)); - list->parent=parent; - list->obj=0; - list->next=0; - - if(0==s_canvaslist) { - /* new list */ - s_canvaslist=list; - } else { - /* add to the end of existing list */ - t_savebangs_canvaslist*dummy=s_canvaslist; - while(dummy->next) - dummy=dummy->next; - dummy->next = list; - } - } - return list; -} - -static t_savebangs_objlist*objectsInCanvas(const t_pd*parent) { - t_savebangs_canvaslist*list=findCanvas(parent); - if(list) - return list->obj; - - return 0; -} - -static void addObjectToCanvas(const t_pd*parent, const t_pd*obj) { - t_savebangs_canvaslist*p=addCanvas(parent); - t_savebangs_objlist*list=0; - t_savebangs_objlist*entry=0; - if(!p || !obj) - return; - list=p->obj; - - if(list&&obj==list->obj) - return; - - while(list && list->next) { - if(obj==list->obj) /* obj already in list */ - return; - list=list->next; - } - - /* we are at the end of the list that does not contain obj yet, so add it */ - entry=(t_savebangs_objlist*)getbytes(sizeof(t_savebangs_objlist)); - entry->obj=obj; - entry->next=0; - if(list) { - list->next=entry; - } else { - p->obj=entry; - } -} - -static void removeObjectFromCanvas(const t_pd*parent, const t_pd*obj) { - t_savebangs_canvaslist*p=findCanvas(parent); - t_savebangs_objlist*list=0, *last=0, *next=0; - if(!p || !obj)return; - list=p->obj; - if(!list) - return; - - while(list && obj!=list->obj) { - last=list; - list=list->next; - } - - if(!list) /* couldn't find this object */ - return; - - next=list->next; - - if(last) - last->next=next; - else - p->obj=next; - - freebytes((void*)list, sizeof(t_savebangs_objlist)); - list=0; -} - -static void removeObjectFromCanvases(const t_pd*obj) { - t_savebangs_canvaslist*parents=s_canvaslist; - - while(parents) { - removeObjectFromCanvas(parents->parent, obj); - parents=parents->next; - } -} - - /* ------------------------- helper methods for savefunctions ---------------------------- */
typedef struct _savefuns { @@ -218,12 +94,12 @@ } }
-static void savebangs_bangem(t_savebangs_objlist*objs, int pst); +static void savebangs_bangem(t_iemguts_objlist*objs, int pst); static void savebangs_savefn(t_gobj*z, t_binbuf*b) { /* z is the parent abstraction; - * we maintain a list of all [savebangs] within such each parent, in order to call all of them + * we maintain a list of all [savebangs] within such each parent, in order to call all of them */ - t_savebangs_objlist*obj=objectsInCanvas((t_pd*)z); + t_iemguts_objlist*obj=objectsInCanvas((t_pd*)z); savebangs_bangem(obj, 0); orig_savefn(z, b); savebangs_bangem(obj, 1); @@ -249,7 +125,7 @@ outlet_bang(x->x_post); }
-static void savebangs_bangem(t_savebangs_objlist*objs, int pst) { +static void savebangs_bangem(t_iemguts_objlist*objs, int pst) { while(objs) { t_savebangs*x=(t_savebangs*)objs->obj; savebangs_bangs(x, pst);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.