[PD-cvs] externals/grill/flext/source flatom.cpp,1.12,1.13 flattr.cpp,1.29,1.30 flattr_ed.cpp,1.35,1.36 flbase.cpp,1.21,1.22 flbind.cpp,1.18,1.19 flclass.h,1.52,1.53 flitem.cpp,1.15,1.16 fllib.cpp,1.30,1.31 flmap.h,1.5,1.6 flmeth.cpp,1.14,1.15 flsupport.cpp,1.44,1.45 flsupport.h,1.81,1.82

Thomas Grill xovo at users.sourceforge.net
Tue Mar 15 05:56:38 CET 2005


Update of /cvsroot/pure-data/externals/grill/flext/source
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2493/source

Modified Files:
	flatom.cpp flattr.cpp flattr_ed.cpp flbase.cpp flbind.cpp 
	flclass.h flitem.cpp fllib.cpp flmap.h flmeth.cpp 
	flsupport.cpp flsupport.h 
Log Message:
new data type flext::AtomListStatic using pre-allocated space if possible
fixes for OSX
replaced memory-intensive STL maps by custom-made vector/map-container
fix for gcc strangeness
no more static assignment of symbols (problems with Metrowerks)
small fix for gcc
fixed bugs in SIMD code for non-power-of-2 lengths
fixes for attribute editor (to deal with large dialogs)


Index: flmap.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flmap.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** flmap.h	26 Jan 2005 05:01:49 -0000	1.5
--- flmap.h	15 Mar 2005 04:56:36 -0000	1.6
***************
*** 16,25 ****
  #define __FLMAP_H
  
- #include <map>
- 
  /*!	\defgroup FLEXT_SUPPORT Flext support classes
  	@{
  */
  
  //! Key/Value type for AnyMap... must have size of pointer!
  typedef size_t AnyMapType;
--- 16,27 ----
  #define __FLMAP_H
  
  /*!	\defgroup FLEXT_SUPPORT Flext support classes
  	@{
  */
  
+ #if 0
+ 
+ #include <map>
+ 
  //! Key/Value type for AnyMap... must have size of pointer!
  typedef size_t AnyMapType;
***************
*** 75,78 ****
--- 77,228 ----
  };
  
+ #endif
+ 
+ class TableAnyMap
+ {
+ protected:
+     virtual TableAnyMap *New(TableAnyMap *parent) = 0;
+     virtual void Free(void *ptr) = 0;
+ 
+     struct Data {
+         void operator()(size_t k,void *v) { key = k,value = v; }
+         void operator =(void *v) { value = v; }
+ 
+         size_t key;
+         void *value;
+     };
+ 
+     TableAnyMap(TableAnyMap *p,int mx,Data *dt,bool o)
+         : owned(o),max(mx),data(dt)
+         , n(0),parent(p),left(NULL),right(NULL) 
+     {}
+ 
+     virtual ~TableAnyMap() { clear(); }
+ 
+     int size() const;
+ 
+     inline void insert(size_t k,void *t)
+     {
+         FLEXT_ASSERT(t);
+         if(n) _set(k,t);
+         else data[n++](k,t);
+     }
+ 
+     inline void *find(size_t k) { return n?_find(k):NULL; }
+ 
+     void clear();
+ 
+     inline void _toleft(size_t k,void *t)
+     {
+         if(left)
+             left->_set(k,t);
+         else {
+             left = New(this);
+             left->data[0](k,t);
+             left->n = 1;
+         }
+     }
+ 
+     inline void _toright(size_t k,void *t)
+     {
+         if(right) 
+             right->_set(k,t);
+         else {
+             right = New(this);
+             right->data[0](k,t);
+             right->n = 1;
+         }
+     }
+ 
+     inline void _toleft(Data &v) { _toleft(v.key,v.value); }
+     inline void _toright(Data &v) { _toright(v.key,v.value); }
+ 
+     void _set(size_t k,void *t);
+     void *_find(size_t k);
+ 
+     Data *const data;
+     const int max;
+     const bool owned;
+     int n;
+     TableAnyMap *parent,*left,*right;
+ 
+ 
+     class iterator
+     {
+     public:
+         inline iterator(): map(NULL) {}
+         inline iterator(TableAnyMap &m): map(&m),ix(0) { leftmost(); }
+         inline iterator(iterator &it): map(it.map),ix(it.ix) {}
+     
+         iterator &operator =(const iterator &it) { map = it.map,ix = it.ix; return *this; }
+ 
+         operator bool() const { return map && /*ix >= 0 &&*/ ix < map->n; }
+ 
+         // no checking here!
+         void *data() const { return map->data[ix].value; }
+         size_t key() const { return map->data[ix].key; }
+ 
+         iterator &operator ++() { forward(); return *this; }  
+ 
+     protected:
+         void leftmost()
+         {
+             // search smallest branch (go left as far as possible)
+             TableAnyMap *nmap;
+             while((nmap = map->left) != NULL) map = nmap;
+         }
+ 
+         void forward();
+ 
+         TableAnyMap *map;
+         int ix;
+     };
+ };
+ 
+ 
+ template <typename K,typename T,int N = 8,bool O = false>
+ class TableMap
+     : TableAnyMap
+ {
+ public:
+     TableMap(): TableAnyMap(NULL,N,slots,O) {}
+     virtual ~TableMap() { clear(); }
+ 
+     inline void clear() { TableAnyMap::clear(); }
+ 
+     inline int size() const { return TableAnyMap::size(); }
+ 
+     inline void insert(K k,T *t) { TableAnyMap::insert(*(size_t *)&k,t); }
+ 
+     inline T *find(K k) { return (T *)TableAnyMap::find(*(size_t *)&k); }
+ 
+     class iterator
+         : TableAnyMap::iterator
+     {
+     public:
+         inline iterator() {}
+         inline iterator(TableMap &m): TableAnyMap::iterator(m) {}
+         inline iterator(iterator &it): TableAnyMap::iterator(it) {}
+ 
+         inline iterator &operator =(const iterator &it) { TableAnyMap::operator =(it); return *this; }
+ 
+         inline operator bool() const {return TableAnyMap::iterator::operator bool(); }
+         inline T *data() const { return (T *)TableAnyMap::iterator::data(); }
+         inline K key() const { return (K)TableAnyMap::iterator::key(); }
+ 
+         inline iterator &operator ++() { TableAnyMap::iterator::operator ++(); return *this; }  
+ 
+     };
+ 
+ protected:
+     inline TableMap(TableAnyMap *p): TableAnyMap(p,N,slots,O) {}
+ 
+     virtual TableAnyMap *New(TableAnyMap *parent) { return new TableMap(parent); }
+     virtual void Free(void *ptr) { delete (T *)ptr; }
+ 
+     Data slots[N];
+ };
+ 
+ 
  //! @} // FLEXT_SUPPORT
  

Index: flbase.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flbase.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** flbase.cpp	26 Jan 2005 05:01:37 -0000	1.21
--- flbase.cpp	15 Mar 2005 04:56:35 -0000	1.22
***************
*** 19,22 ****
--- 19,23 ----
  #include <string.h>
  #include <ctype.h>
+ #include <stdlib.h>
  
  #if FLEXT_SYS == FLEXT_SYS_PD

Index: flsupport.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flsupport.h,v
retrieving revision 1.81
retrieving revision 1.82
diff -C2 -d -r1.81 -r1.82
*** flsupport.h	13 Mar 2005 04:56:39 -0000	1.81
--- flsupport.h	15 Mar 2005 04:56:36 -0000	1.82
***************
*** 546,551 ****
  
  	//! Class representing a list of atoms
!     class FLEXT_SHARE AtomList:
!         public flext_root
  	{
  	public:
--- 546,551 ----
  
  	//! Class representing a list of atoms
!     class FLEXT_SHARE AtomList
!         : public flext_root
  	{
  	public:
***************
*** 553,561 ****
          AtomList(): cnt(0),lst(NULL) {}
  		//! Construct list
! 		AtomList(int argc,const t_atom *argv = NULL);
  		//! Construct list
! 		AtomList(const AtomList &a);
  		//! Destroy list
! 		~AtomList();
  
  		//! Clear list
--- 553,561 ----
          AtomList(): cnt(0),lst(NULL) {}
  		//! Construct list
! 		AtomList(int argc,const t_atom *argv = NULL): cnt(0),lst(NULL) { operator()(argc,argv); }
  		//! Construct list
!         AtomList(const AtomList &a): cnt(0),lst(NULL) { operator =(a); }
  		//! Destroy list
!         virtual ~AtomList();
  
  		//! Clear list
***************
*** 616,623 ****
--- 616,653 ----
  
  	protected:
+         virtual void Alloc(int sz);
+         virtual void Free();
+ 
  		int cnt;
  		t_atom *lst;
  	};
  
+     class FLEXT_SHARE AtomListStaticBase
+         : public AtomList
+     {
+     protected:
+         AtomListStaticBase(int pc,t_atom *dt): precnt(pc),predata(dt) {}
+         virtual ~AtomListStaticBase();
+         virtual void Alloc(int sz);
+         virtual void Free();
+ 
+         const int precnt;
+         t_atom *const predata;
+     };
+ 
+     template<int PRE>
+     class FLEXT_SHARE AtomListStatic
+         : public AtomListStaticBase
+     {
+     public:
+ 		//! Construct list
+         AtomListStatic(): AtomListStaticBase(PRE,pre) {}
+ 		//! Construct list
+ 		AtomListStatic(int argc,const t_atom *argv = NULL): AtomListStaticBase(PRE,pre) { operator()(argc,argv); }
+ 		//! Construct list
+         AtomListStatic(const AtomList &a): AtomListStaticBase(PRE,pre) { operator =(a); }
+     protected:
+         t_atom pre[PRE];
+     };
  
  	//! Class representing an "anything"
***************
*** 629,638 ****
  #if FLEXT_SYS != FLEXT_SYS_JMAX
  		//! Construct anything
! 		AtomAnything(const t_symbol *h,int argc = 0,const t_atom *argv = NULL);
  #endif
  		//! Construct anything
! 		AtomAnything(const char *h,int argc = 0,const t_atom *argv = NULL);
  		//! Construct anything
! 		AtomAnything(const AtomAnything &a);
  
  		//! Clear anything
--- 659,675 ----
  #if FLEXT_SYS != FLEXT_SYS_JMAX
  		//! Construct anything
! 		AtomAnything(const t_symbol *h,int argc = 0,const t_atom *argv = NULL)
!             : AtomList(argc,argv),hdr(h?h:sym__) 
!         {}
  #endif
  		//! Construct anything
! 		AtomAnything(const char *h,int argc = 0,const t_atom *argv = NULL)
!             : AtomList(argc,argv),hdr(MakeSymbol(h)) 
!         {}
! 
  		//! Construct anything
! 		AtomAnything(const AtomAnything &a)
!             : AtomList(a),hdr(a.hdr) 
!         {}
  
  		//! Clear anything

Index: flbind.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flbind.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** flbind.cpp	26 Jan 2005 05:01:41 -0000	1.18
--- flbind.cpp	15 Mar 2005 04:56:35 -0000	1.19
***************
*** 145,149 ****
  }
  
- 
  bool flext_base::UnbindMethod(const t_symbol *sym,bool (*fun)(flext_base *,t_symbol *s,int argc,t_atom *argv,void *data),void **data)
  {
--- 145,148 ----
***************
*** 152,155 ****
--- 151,156 ----
      if(bindhead && bindhead->Contained(0)) {
          ItemSet &set = bindhead->GetInlet();
+ 
+ /*
          ItemSet::iterator it1,it2;
          if(sym) { 
***************
*** 174,184 ****
              }
          }
  
!         if(it) {
!             if(data) *data = it->px->data;
!             ok = bindhead->Remove(it,sym,0,false);
              if(ok) {
!                 it->Unbind(sym);
!                 delete it;
              }
          }
--- 175,209 ----
              }
          }
+ */
+         BindItem *item = NULL;
+         if(sym) {
+             // symbol is given
+             Item *it = set.find(sym);
+             if(fun) {
+                 // check if function matches
+                 for(; it && static_cast<BindItem *>(it)->fun != fun; it = it->nxt);
+             }
+             item = static_cast<BindItem *>(it); 
+         }
+         else {
+             // take any entry that matches
+             for(ItemSet::iterator si(set); si && !item; ++si) {
+                 for(Item *i = si.data(); i; i = i->nxt) {
+                     BindItem *bit = (BindItem *)i;
+                     if(!fun || bit->fun == fun) { 
+                         item = bit; 
+                         if(!sym) sym = si.key();
+                         break; 
+                     }
+                 }
+             }
+         }
  
!         if(item) {
!             if(data) *data = item->px->data;
!             ok = bindhead->Remove(item,sym,0,false);
              if(ok) {
!                 item->Unbind(sym);
!                 delete item;
              }
          }
***************
*** 208,212 ****
      if(bindhead && bindhead->Contained(0)) {
          ItemSet &set = bindhead->GetInlet();
!         for(ItemSet::iterator si = set.begin(); si != set.end(); ++si) {
              Item *lst = si.data();
              while(lst) {
--- 233,238 ----
      if(bindhead && bindhead->Contained(0)) {
          ItemSet &set = bindhead->GetInlet();
! //        for(ItemSet::iterator si = set.begin(); si != set.end(); ++si) {
!         for(ItemSet::iterator si(set); si; ++si) {
              Item *lst = si.data();
              while(lst) {

Index: flattr.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flattr.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** flattr.cpp	10 Mar 2005 04:56:40 -0000	1.29
--- flattr.cpp	15 Mar 2005 04:56:35 -0000	1.30
***************
*** 34,37 ****
--- 34,38 ----
  
  
+ /*
  flext_base::AttrDataCont::AttrDataCont() {}
  
***************
*** 41,44 ****
--- 42,46 ----
  		if(it.data()) delete it.data();
  }
+ */
  
  
***************
*** 102,106 ****
  void flext_base::ListAttrib(AtomList &la) const
  {
! 	typedef DataMap<int,const t_symbol *> AttrList;
  	AttrList list[2];
  
--- 104,108 ----
  void flext_base::ListAttrib(AtomList &la) const
  {
! 	typedef TableMap<int,t_symbol,32> AttrList;
  	AttrList list[2];
  
***************
*** 110,117 ****
  		if(a && a->Contained(0)) {
              ItemSet &ai = a->GetInlet();
!             for(ItemSet::iterator as = ai.begin(); as != ai.end(); ++as) {
                  for(Item *al = as.data(); al; al = al->nxt) {
  					AttrItem *aa = (AttrItem *)al;
! 					list[i][aa->index] = as.key();
                      break;
                  }
--- 112,119 ----
  		if(a && a->Contained(0)) {
              ItemSet &ai = a->GetInlet();
!             for(ItemSet::iterator as(ai); as; ++as) {
                  for(Item *al = as.data(); al; al = al->nxt) {
  					AttrItem *aa = (AttrItem *)al;
! 					list[i].insert(aa->index,const_cast<t_symbol *>(as.key()));
                      break;
                  }
***************
*** 122,128 ****
  	la((int)(list[0].size()+list[1].size()));
  	int ix = 0;
- 	AttrList::iterator it;
  	for(i = 0; i <= 1; ++i)
! 		for(it = list[i].begin(); it != list[i].end(); ++it) 
  			SetSymbol(la[ix++],it.data());
  }
--- 124,129 ----
  	la((int)(list[0].size()+list[1].size()));
  	int ix = 0;
  	for(i = 0; i <= 1; ++i)
! 		for(AttrList::iterator it(list[i]); it; ++it) 
  			SetSymbol(la[ix++],it.data());
  }
***************
*** 150,153 ****
--- 151,155 ----
  		if(attr) {
  			// make an entry (there are none beforehand...)
+ /*
  			AttrDataCont::iterator it = attrdata->find(tag);
  			if(it == attrdata->end()) {
***************
*** 164,167 ****
--- 166,178 ----
  			// pass value to object
  			SetAttrib(tag,attr,a.GetInitValue());
+ */
+ 			AttrData *a = attrdata->find(tag);
+ 			if(!a) attrdata->insert(tag,a = new AttrData);
+ 
+ 			a->SetInit(true);
+ 			a->SetInitValue(nxt-cur-1,argv+cur+1);
+ 
+ 			// pass value to object
+ 			SetAttrib(tag,attr,a->GetInitValue());
  		}
  	}
***************
*** 175,179 ****
          extern const t_symbol *sym_attributes;
  
! 		AtomList la;
  		ListAttrib(la);
  		ToOutAnything(GetOutAttr(),sym_attributes,la.Count(),la.Atoms());
--- 186,190 ----
          extern const t_symbol *sym_attributes;
  
! 		AtomListStatic<32> la;
  		ListAttrib(la);
  		ToOutAnything(GetOutAttr(),sym_attributes,la.Count(),la.Atoms());
***************
*** 258,262 ****
  			break;
  		case a_LIST: {
! 			AtomList la(argc);
  			for(int i = 0; i < argc; ++i)
  				if(IsSymbol(argv[i])) 
--- 269,273 ----
  			break;
  		case a_LIST: {
! 			AtomListStatic<16> la(argc);
  			for(int i = 0; i < argc; ++i)
  				if(IsSymbol(argv[i])) 
***************
*** 345,349 ****
  bool flext_base::DumpAttrib(const t_symbol *tag,AttrItem *a) const
  {
! 	AtomList la;
  	bool ret = GetAttrib(tag,a,la);
  	if(ret) {
--- 356,360 ----
  bool flext_base::DumpAttrib(const t_symbol *tag,AttrItem *a) const
  {
! 	AtomListStatic<16> la;
  	bool ret = GetAttrib(tag,a,la);
  	if(ret) {
***************
*** 361,365 ****
  bool flext_base::BangAttrib(const t_symbol *attr,AttrItem *item)
  {
! 	AtomList val;
  	AttrItem *item2;
  	if(!item->IsGet()) 
--- 372,376 ----
  bool flext_base::BangAttrib(const t_symbol *attr,AttrItem *item)
  {
! 	AtomListStatic<16> val;
  	AttrItem *item2;
  	if(!item->IsGet()) 
***************
*** 385,388 ****
--- 396,400 ----
  		if(a) {
              ItemSet &ai = a->GetInlet(); // \todo need to check for presence of inlet 0?
+ /*
              for(ItemSet::iterator as = ai.begin(); as != ai.end(); ++as) {
                  for(Item *al = as.data(); al; al = al->nxt) {
***************
*** 391,394 ****
--- 403,413 ----
                  }
  			}
+ */
+             for(ItemSet::iterator as(ai); as; ++as) {
+                 for(Item *al = as.data(); al; al = al->nxt) {
+ 					AttrItem *a = (AttrItem *)al;
+ 	        		if(a->IsGet() && a->BothExist()) BangAttrib(as.key(),a);
+                 }
+ 			}
  		}
  	}

Index: fllib.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/fllib.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** fllib.cpp	26 Jan 2005 05:01:49 -0000	1.30
--- fllib.cpp	15 Mar 2005 04:56:36 -0000	1.31
***************
*** 127,131 ****
  
  
! typedef DataMap<const t_symbol *,libclass *> LibMap;
  
  static LibMap libnames;
--- 127,131 ----
  
  
! typedef TableMap<const t_symbol *,libclass,8> LibMap;
  
  static LibMap libnames;
***************
*** 134,145 ****
  static libclass *FindName(const t_symbol *s,libclass *o = NULL) 
  {
! //    typedef std::map<const t_symbol *,libclass *> LibMap;
!     LibMap::iterator it = libnames.find(s);
!     if(it == libnames.end()) {
!         if(o) libnames[s] = o;
!         return o;
!     }
!     else
!         return it.data();
  }
  
--- 134,140 ----
  static libclass *FindName(const t_symbol *s,libclass *o = NULL) 
  {
!     libclass *cl = libnames.find(s);
!     if(!cl) libnames.insert(s,cl = o);
!     return cl;
  }
  

Index: flatom.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flatom.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** flatom.cpp	26 Jan 2005 05:01:22 -0000	1.12
--- flatom.cpp	15 Mar 2005 04:56:34 -0000	1.13
***************
*** 49,79 ****
  }
  
! flext::AtomList::AtomList(int argc,const t_atom *argv):
! 	cnt(0),lst(NULL)
  {
! 	operator()(argc,argv);
  }
  
! flext::AtomList::AtomList(const AtomList &a):
! 	cnt(0),lst(NULL)
  {
! 	operator =(a);
  }
  
- flext::AtomList::~AtomList() {	Clear(); }
- 
- 
  flext::AtomList &flext::AtomList::Set(int argc,const t_atom *argv,int offs,bool resize)
  {
  	int ncnt = argc+offs;
! 	if(resize && lst && cnt != ncnt) { delete[] lst; lst = NULL; cnt = 0; }
  
! 	if(ncnt) {
! 		if(!lst) lst = new t_atom[cnt = ncnt];
  
- 		if(argv) {
- 			for(int i = 0; i < argc; ++i) SetAtom(lst[offs+i],argv[i]);
- 		}
- 	}
  	return *this;
  }
--- 49,85 ----
  }
  
! void flext::AtomList::Alloc(int sz)
  {
!     if(lst) {
!         if(cnt == sz) return; // no change
!         delete[] lst;
!     }
!     else
!         FLEXT_ASSERT(cnt == 0);
!     lst = new t_atom[cnt = sz];
  }
  
! flext::AtomList::~AtomList() { Free(); }
! 
! void flext::AtomList::Free()
  {
!     if(lst) { 
!         delete[] lst; lst = NULL; 
!         cnt = 0;
!     }
!     else
!         FLEXT_ASSERT(cnt == 0);
  }
  
  flext::AtomList &flext::AtomList::Set(int argc,const t_atom *argv,int offs,bool resize)
  {
  	int ncnt = argc+offs;
! 	if(resize) Alloc(ncnt);
  
!     // argv can be NULL indepently from argc
!     if(argv)
!         for(int i = 0; i < argc; ++i) 
!             SetAtom(lst[offs+i],argv[i]);
  
  	return *this;
  }
***************
*** 92,110 ****
  }
  
  
! #if FLEXT_SYS != FLEXT_SYS_JMAX 
! // not for jmax as long as t_symbol * == char *
! flext::AtomAnything::AtomAnything(const t_symbol *h,int argc,const t_atom *argv): 
! 	AtomList(argc,argv),hdr(h?h:MakeSymbol("")) 
! {}
! #endif
! 
! flext::AtomAnything::AtomAnything(const char *h,int argc,const t_atom *argv): 
! 	AtomList(argc,argv),hdr(MakeSymbol(h)) 
! {}
! 
! flext::AtomAnything::AtomAnything(const AtomAnything &a): 
! 	AtomList(a),hdr(a.hdr) 
! {}
! 
  
--- 98,112 ----
  }
  
+ flext::AtomListStaticBase::~AtomListStaticBase() { Free(); }
  
! void flext::AtomListStaticBase::Alloc(int sz) 
! { 
!     if(sz < precnt) lst = predata,cnt = sz;
!     else AtomList::Alloc(sz);
! }
  
+ void flext::AtomListStaticBase::Free() 
+ {
+     if(lst != predata) AtomList::Free();
+     else lst = NULL,cnt = 0;
+ }

Index: flitem.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flitem.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** flitem.cpp	26 Jan 2005 05:01:48 -0000	1.15
--- flitem.cpp	15 Mar 2005 04:56:35 -0000	1.16
***************
*** 22,25 ****
--- 22,26 ----
  }
  
+ /*
  flext_base::ItemSet::ItemSet() {}
  
***************
*** 29,32 ****
--- 30,34 ----
          if(it.data()) delete it.data();
  }
+ */
  
  flext_base::ItemCont::ItemCont(): 
***************
*** 65,71 ****
      if(!Contained(inlet)) Resize(inlet+2);
      ItemSet &set = GetInlet(inlet);
!     Item *&lst = set[tag];
      if(!lst) 
!         lst = item;
      else
          for(;;)
--- 67,73 ----
      if(!Contained(inlet)) Resize(inlet+2);
      ItemSet &set = GetInlet(inlet);
!     Item *lst = set.find(tag);
      if(!lst) 
!         set.insert(tag,lst = item);
      else
          for(;;)
***************
*** 81,95 ****
      if(Contained(inlet)) {
          ItemSet &set = GetInlet(inlet);
!         ItemSet::iterator it = set.find(tag);
!         if(it != set.end()) {
!             for(Item *lit = it.data(),*prv = NULL; lit; prv = lit,lit = lit->nxt) {
!                 if(lit == item) {
!                     if(prv) prv->nxt = lit->nxt;
!                     else it.data() = lit->nxt;
!                 
!                     lit->nxt = NULL; 
!                     if(free) delete lit;
!                     return true;
!                 }
              }
          }
--- 83,95 ----
      if(Contained(inlet)) {
          ItemSet &set = GetInlet(inlet);
!         Item *lit = set.find(tag);
!         for(Item *prv = NULL; lit; prv = lit,lit = lit->nxt) {
!             if(lit == item) {
!                 if(prv) prv->nxt = lit->nxt;
!                 else set.insert(tag,lit->nxt);
!             
!                 lit->nxt = NULL; 
!                 if(free) delete lit;
!                 return true;
              }
          }
***************
*** 101,116 ****
  {
      FLEXT_ASSERT(tag);
! 
!     if(Contained(inlet)) {
!         ItemSet &ai = GetInlet(inlet);
!         ItemSet::iterator as = ai.find(tag); 
!         if(as != ai.end()) return as.data();
!     }
!     return NULL;
  }
  
  // --- class item lists (methods and attributes) ----------------
  
! typedef DataMap<flext_base::t_classid,flext_base::ItemCont *> ClassMap;
  
  static ClassMap classarr[2];
--- 101,110 ----
  {
      FLEXT_ASSERT(tag);
!     return Contained(inlet)?GetInlet(inlet).find(tag):NULL;
  }
  
  // --- class item lists (methods and attributes) ----------------
  
! typedef TableMap<flext_base::t_classid,flext_base::ItemCont,64> ClassMap;
  
  static ClassMap classarr[2];
***************
*** 119,129 ****
  {
      ClassMap &map = classarr[ix];
!     ClassMap::iterator it = map.find(c);
!     if(it == map.end()) {
!         ItemCont *cont = new ItemCont;
!         map[c] = cont;
!         return cont;
!     }
!     else
!         return it.data();
  }
--- 113,118 ----
  {
      ClassMap &map = classarr[ix];
!     ItemCont *cont = map.find(c);
!     if(!cont) map.insert(c,cont = new ItemCont);
!     return cont;
  }

Index: flmeth.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flmeth.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** flmeth.cpp	10 Mar 2005 04:56:40 -0000	1.14
--- flmeth.cpp	15 Mar 2005 04:56:36 -0000	1.15
***************
*** 93,97 ****
  void flext_base::ListMethods(AtomList &la,int inlet) const
  {
!     typedef DataMap<int,const t_symbol *> MethList;
      MethList list[2];
  
--- 93,97 ----
  void flext_base::ListMethods(AtomList &la,int inlet) const
  {
! 	typedef TableMap<int,t_symbol,32> MethList;
      MethList list[2];
  
***************
*** 101,111 ****
          if(a && a->Contained(inlet)) {
              ItemSet &ai = a->GetInlet(inlet);
!             for(ItemSet::iterator as = ai.begin(); as != ai.end(); ++as) {
                  for(Item *al = as.data(); al; al = al->nxt) {
                      MethItem *aa = (MethItem *)al;
- 
                      // check it's not related to an attribute
                      if(!aa->IsAttr()) {
!                         list[i][aa->index] = as.key();
                          break;
                      }
--- 101,110 ----
          if(a && a->Contained(inlet)) {
              ItemSet &ai = a->GetInlet(inlet);
!             for(ItemSet::iterator as(ai); as; ++as) {
                  for(Item *al = as.data(); al; al = al->nxt) {
                      MethItem *aa = (MethItem *)al;
                      // check it's not related to an attribute
                      if(!aa->IsAttr()) {
!                         list[i].insert(aa->index,const_cast<t_symbol *>(as.key()));
                          break;
                      }
***************
*** 117,123 ****
      la((int)list[0].size()+(int)list[1].size());
      int ix = 0;
-     MethList::iterator it;
      for(i = 0; i <= 1; ++i)
!         for(it = list[i].begin(); it != list[i].end(); ++it) 
              SetSymbol(la[ix++],it.data());
  }
--- 116,121 ----
      la((int)list[0].size()+(int)list[1].size());
      int ix = 0;
      for(i = 0; i <= 1; ++i)
!         for(MethList::iterator it(list[i]); it; ++it) 
              SetSymbol(la[ix++],it.data());
  }
***************
*** 130,134 ****
  
          int inlet = argc?GetAInt(argv[0]):0;
!         AtomList la;
          c->ListMethods(la,inlet);
          c->ToOutAnything(c->GetOutAttr(),sym_methods,la.Count(),la.Atoms());
--- 128,132 ----
  
          int inlet = argc?GetAInt(argv[0]):0;
!         AtomListStatic<32> la;
          c->ListMethods(la,inlet);
          c->ToOutAnything(c->GetOutAttr(),sym_methods,la.Count(),la.Atoms());

Index: flattr_ed.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flattr_ed.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -d -r1.35 -r1.36
*** flattr_ed.cpp	12 Mar 2005 04:56:33 -0000	1.35
--- flattr_ed.cpp	15 Mar 2005 04:56:35 -0000	1.36
***************
*** 495,499 ****
      sys_vgui("%s } {\n",buf);
  
!     AtomList la;
      th->ListAttrib(la);
      int cnt = la.Count();
--- 495,499 ----
      sys_vgui("%s } {\n",buf);
  
!     AtomListStatic<32> la;
      th->ListAttrib(la);
      int cnt = la.Count();
***************
*** 510,525 ****
          int sv;
          const AtomList *initdata;
!         AttrDataCont::iterator it = th->attrdata->find(sym);
!         if(it == th->attrdata->end())
              sv = 0,initdata = NULL;
          else {
!             const AttrData &a = *it.data();
!             if(a.IsSaved())
                  sv = 2;
!             else if(a.IsInit())
                  sv = 1;
              else 
                  sv = 0;
!             initdata = a.IsInitValue()?&a.GetInitValue():NULL;
          }
  
--- 510,527 ----
          int sv;
          const AtomList *initdata;
!         const AttrData *a = th->attrdata->find(sym);
! //        AttrDataCont::iterator it = th->attrdata->find(sym);
! //        if(it == th->attrdata->end())
!         if(!a)
              sv = 0,initdata = NULL;
          else {
! //            const AttrData &a = *it.data();
!             if(a->IsSaved())
                  sv = 2;
!             else if(a->IsInit())
                  sv = 1;
              else 
                  sv = 0;
!             initdata = a->IsInitValue()?&a->GetInitValue():NULL;
          }
  
***************
*** 541,545 ****
          sys_vgui(const_cast<char *>(list?"%s {":"%s "),GetString(sym));
  
!         AtomList lv;
          if(gattr) { // gettable attribute is present
              // Retrieve attribute value
--- 543,547 ----
          sys_vgui(const_cast<char *>(list?"%s {":"%s "),GetString(sym));
  
!         AtomListStatic<32> lv;
          if(gattr) { // gettable attribute is present
              // Retrieve attribute value
***************
*** 562,566 ****
          if(pattr) {
              // if there is initialization data take this, otherwise take the current data
!             const AtomList &lp = initdata?*initdata:lv;
  
              char *b = buf; *b = 0;
--- 564,568 ----
          if(pattr) {
              // if there is initialization data take this, otherwise take the current data
!             const AtomList &lp = initdata?*initdata:static_cast<const AtomList &>(lv);
  
              char *b = buf; *b = 0;
***************
*** 703,710 ****
              FLEXT_ASSERT(ret);
  
!             AttrDataCont::iterator it = th->attrdata->find(aname);
  
              if(sv >= 1) {
                  // if data not present create it
                  if(it == th->attrdata->end()) {
                      AttrDataCont::pair pair; 
--- 705,715 ----
              FLEXT_ASSERT(ret);
  
! //            AttrDataCont::iterator it = th->attrdata->find(aname);
!             AttrData *a = th->attrdata->find(aname);
  
              if(sv >= 1) {
                  // if data not present create it
+ 
+ /*
                  if(it == th->attrdata->end()) {
                      AttrDataCont::pair pair; 
***************
*** 718,723 ****
--- 723,736 ----
                  a.SetInit(true);
                  a.SetInitValue(icnt,argv+ioffs);
+ */
+                 if(!a)
+                     th->attrdata->insert(aname,a = new AttrData);
+ 
+                 a->SetSave(sv == 2);
+                 a->SetInit(true);
+                 a->SetInitValue(icnt,argv+ioffs);
              }
              else {
+ /*
                  if(it != th->attrdata->end()) {
                      AttrData &a = *it.data();
***************
*** 728,731 ****
--- 741,752 ----
                      // let init data as is
                  }
+ */
+                 if(a) {
+                     // if data is present reset flags
+                     a->SetSave(false);
+                     a->SetInit(false);
+ 
+                     // let init data as is
+                 }
              }
          }
***************
*** 766,770 ****
  {
      // process the attributes
!     AtomList la;
      ListAttrib(la);
      int i,cnt = la.Count();
--- 787,791 ----
  {
      // process the attributes
!     AtomListStatic<32> la,lv;
      ListAttrib(la);
      int i,cnt = la.Count();
***************
*** 772,784 ****
      for(i = 0; i < cnt; ++i) {
          const t_symbol *sym = GetSymbol(la[i]);
-         AtomList lv;
          const AtomList *lref = NULL;
          AttrDataCont::iterator it = attrdata->find(sym);
- 
          if(it != attrdata->end()) {
              const AttrData &a = *it.data();
              if(a.IsInit() && a.IsInitValue()) {
                  lref = &a.GetInitValue();
! /*
                  // check for $-parameters
                  lv = lref->Count();
--- 793,810 ----
      for(i = 0; i < cnt; ++i) {
          const t_symbol *sym = GetSymbol(la[i]);
          const AtomList *lref = NULL;
+ /*
          AttrDataCont::iterator it = attrdata->find(sym);
          if(it != attrdata->end()) {
              const AttrData &a = *it.data();
              if(a.IsInit() && a.IsInitValue()) {
                  lref = &a.GetInitValue();
! */
!         AttrData *a = attrdata->find(sym);
!         if(a) {
!             if(a->IsInit() && a->IsInitValue()) {
!                 lref = &a->GetInitValue();
! 
! #if 0 /////////////////////////////////////////////////////////////
                  // check for $-parameters
                  lv = lref->Count();
***************
*** 796,802 ****
  
                  lref = &lv;
! */
              }
!             else if(a.IsSaved()) {
                  AttrItem *attr = FindAttrib(sym,true);
  
--- 822,829 ----
  
                  lref = &lv;
! #endif /////////////////////////////////////////////////////////////
              }
! //            else if(a.IsSaved()) {
!             else if(a->IsSaved()) {
                  AttrItem *attr = FindAttrib(sym,true);
  

Index: flsupport.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flsupport.cpp,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** flsupport.cpp	10 Mar 2005 04:56:41 -0000	1.44
--- flsupport.cpp	15 Mar 2005 04:56:36 -0000	1.45
***************
*** 17,20 ****
--- 17,22 ----
  #include <stdio.h>
  #include <stdarg.h>
+ #include <stdlib.h>
+ #include <string.h>
  #include <new>
  
***************
*** 296,302 ****
  }
  
! 
  AnyMap::AnyMap() {}
  AnyMap::~AnyMap() {}
  AnyMap::iterator AnyMap::find(AnyMapType k) { return Parent::find(k); }
  AnyMapType &AnyMap::operator [](AnyMapType k) { return Parent::operator [](k); }
--- 298,462 ----
  }
  
! #if 0
  AnyMap::AnyMap() {}
  AnyMap::~AnyMap() {}
  AnyMap::iterator AnyMap::find(AnyMapType k) { return Parent::find(k); }
  AnyMapType &AnyMap::operator [](AnyMapType k) { return Parent::operator [](k); }
+ #endif
+ 
+ void TableAnyMap::clear() 
+ {
+     if(left) { delete left; left = NULL; }
+     if(right) { delete right; right = NULL; }
+     if(owned)
+         for(int i = 0; i < n; ++i) {
+             FLEXT_ASSERT(data[i].value);
+             Free(data[i].value);
+         }
+     n = 0;
+ }
+ 
+ int TableAnyMap::size() const 
+ {
+     int sz = n;
+     if(sz >= max) {
+         if(left) sz += left->size();
+         if(right) sz += right->size();
+     }
+     return sz;
+ }
+ 
+ void TableAnyMap::_set(size_t k,void *t)
+ {
+     FLEXT_ASSERT(n);
+ 
+     if(n < max) {
+         // fall through
+     }
+     else if(k < data[0].key) {
+         _toleft(k,t);
+         return;
+     }
+     else if(k > data[max-1].key) {
+         _toright(k,t);
+         return;
+     }
+ 
+     int ix = 0;
+     {
+         int b = n;
+         while(ix != b) {
+             const int c = (ix+b)/2;
+             const size_t dk = data[c].key;
+             if(k == dk) {
+                 ix = c;
+                 break;
+             }
+             else if(k < dk)
+                 b = c;
+             else if(ix < c)
+                 ix = c;
+             else {
+                 ix = b;
+                 break;
+             }
+         }
+     }
+ 
+     size_t dk = data[ix].key;
+     if(k == dk) {
+         // update data in existing slot (same key)
+         if(owned) Free(data[ix].value);
+         data[ix] = t;
+     }
+     else if(ix >= n) {
+         FLEXT_ASSERT(ix == n);
+         // after last entry
+         data[n++](k,t);
+     }
+     else {
+         // insert new slot by shifting the higher ones
+         FLEXT_ASSERT(k < dk);
+         if(n == max)
+             _toright(data[max-1]);
+         else
+             ++n;
+ 
+         Data *tg = data+ix;
+         for(Data *d = data+n-1; d > tg; d--) d[0] = d[-1];
+         (*tg)(k,t);
+     }
+ }
+ 
+ void *TableAnyMap::_find(size_t k) 
+ {
+     FLEXT_ASSERT(n);
+     if(n < max) {
+         // fall through
+     }
+     else if(k < data[0].key)
+         return left?left->_find(k):NULL;
+     else if(k > data[n-1].key)
+         return right?right->_find(k):NULL;
+ 
+     //! return index of data item with key <= k
+ 
+     FLEXT_ASSERT(n);
+     int ix = 0;
+     {
+         int b = n;
+         while(ix != b) {
+             const int c = (ix+b)/2;
+             const size_t dk = data[c].key;
+             if(k == dk)
+                 return data[c].value;
+             else if(k < dk)
+                 b = c;
+             else if(ix < c)
+                 ix = c;
+             else {
+                 ix = b;
+                 break;
+             }
+         }
+     }
+ 
+     if(data[ix].key == k)
+         return data[ix].value;
+     else
+         return NULL;
+ }
+ 
+ void TableAnyMap::iterator::forward() 
+ { 
+     if(map || ix >= map->n) {
+         if(++ix >= map->n) {
+             TableAnyMap *nmap;
+ 
+             // we reached the end of the slots
+             if(map->right) {
+                 // climb up one
+                 map = map->right;
+                 leftmost();
+                 ix = 0;
+             }
+             else {
+                 // fall back
+                 for(;;) {
+                     nmap = map->parent;
+                     if(!nmap) break; // no parent
+                     if(nmap->left == map) {
+                         // ok, we are in front of the slots now
+                         ix = 0;
+                         map = nmap;
+                         break;
+                     }
+                     else {
+                         FLEXT_ASSERT(nmap->right == map);
+                         ix = (map = nmap)->n;
+                     }
+                 }
+             }
+         }
+     }
+ }

Index: flclass.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flclass.h,v
retrieving revision 1.52
retrieving revision 1.53
diff -C2 -d -r1.52 -r1.53
*** flclass.h	13 Mar 2005 04:56:31 -0000	1.52
--- flclass.h	15 Mar 2005 04:56:35 -0000	1.53
***************
*** 651,654 ****
--- 651,655 ----
  	};
  
+ /*
  	class ItemSet:
  		public DataMap<const t_symbol *,Item *>
***************
*** 658,661 ****
--- 659,664 ----
  		~ItemSet();
  	};
+ */
+ 	typedef TableMap<const t_symbol *,Item,8,true> ItemSet;
  
      /*! This class holds hashed item entries
***************
*** 764,767 ****
--- 767,771 ----
  	};
  
+ /*
  	class AttrDataCont:
  		public DataMap<const t_symbol *,AttrData *>
***************
*** 771,774 ****
--- 775,780 ----
  		~AttrDataCont();
  	};
+ */
+ 	typedef TableMap<const t_symbol *,AttrData,8,true> AttrDataCont;
  
  	// these outlet functions don't check for thread but send directly to the real-time system





More information about the Pd-cvs mailing list