Update of /cvsroot/pure-data/externals/grill/flext/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28946/source
Modified Files: flattr.cpp flattr_ed.cpp flclass.h flitem.cpp flmap.h flsupport.cpp Log Message: changed template parameter of TableMap fixed problems with symbol binding restructured TableMap type (doesn't own pointers any more)
Index: flmap.h =================================================================== RCS file: /cvsroot/pure-data/externals/grill/flext/source/flmap.h,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** flmap.h 16 Apr 2005 21:35:06 -0000 1.14 --- flmap.h 18 Apr 2005 15:07:40 -0000 1.15 *************** *** 84,89 **** { protected: ! virtual TableAnyMap *New(TableAnyMap *parent) = 0; ! virtual void Free(void *ptr) = 0;
struct Data { --- 84,90 ---- { protected: ! virtual TableAnyMap *_newmap(TableAnyMap *parent) = 0; ! virtual void _delmap(TableAnyMap *map) = 0; ! // virtual void Free(void *ptr) = 0;
struct Data { *************** *** 97,101 **** TableAnyMap(TableAnyMap *p,int sz,Data *dt) : tsize(sz),data(dt) ! , n(0),count(0) , parent(p),left(NULL),right(NULL) {} --- 98,103 ---- TableAnyMap(TableAnyMap *p,int sz,Data *dt) : tsize(sz),data(dt) ! , n(0) ! // , count(0) , parent(p),left(NULL),right(NULL) {} *************** *** 103,116 **** virtual ~TableAnyMap();
! int size() const { return count; }
! void insert(size_t k,void *t) { // FLEXT_ASSERT(t); if(n) ! _set(k,t); else { data[n++](k,t); ! ++count; } } --- 105,119 ---- virtual ~TableAnyMap();
! // int size() const { return count; }
! void *insert(size_t k,void *t) { // FLEXT_ASSERT(t); if(n) ! return _set(k,t); else { data[n++](k,t); ! // ++count; ! return NULL; } } *************** *** 118,126 **** void *find(size_t k) const { return n?_find(k):NULL; }
! void erase(size_t k) { if(n) { void *s = _remove(k); if(s) Free(s); } }
void *remove(size_t k) { return n?_remove(k):NULL; }
! void clear();
class FLEXT_SHARE iterator --- 121,129 ---- void *find(size_t k) const { return n?_find(k):NULL; }
! // void erase(size_t k) { if(n) { void *s = _remove(k); if(s) Free(s); } }
void *remove(size_t k) { return n?_remove(k):NULL; }
! virtual void clear();
class FLEXT_SHARE iterator *************** *** 156,193 ****
private: ! void _init(size_t k,void *t) { data[0](k,t); n = count = 1; }
! bool _toleft(size_t k,void *t) { if(left) { ! bool a = left->_set(k,t); ! if(a) ++count; return a; } else { ! (left = New(this))->_init(k,t); ! ++count; ! return true; } }
! bool _toright(size_t k,void *t) { if(right) { ! bool a = right->_set(k,t); ! if(a) ++count; return a; } else { ! (right = New(this))->_init(k,t); ! ++count; ! return true; } }
! bool _toleft(Data &v) { return _toleft(v.key,v.value); } ! bool _toright(Data &v) { return _toright(v.key,v.value); }
! bool _set(size_t k,void *t); void *_find(size_t k) const; void *_remove(size_t k); --- 159,196 ----
private: ! void _init(size_t k,void *t) { data[0](k,t); n = /*count =*/ 1; }
! void *_toleft(size_t k,void *t) { if(left) { ! void *a = left->_set(k,t); ! // if(!a) ++count; return a; } else { ! (left = _newmap(this))->_init(k,t); ! // ++count; ! return NULL; } }
! void *_toright(size_t k,void *t) { if(right) { ! void *a = right->_set(k,t); ! // if(!a) ++count; return a; } else { ! (right = _newmap(this))->_init(k,t); ! // ++count; ! return NULL; } }
! void *_toleft(Data &v) { return _toleft(v.key,v.value); } ! void *_toright(Data &v) { return _toright(v.key,v.value); }
! void *_set(size_t k,void *t); void *_find(size_t k) const; void *_remove(size_t k); *************** *** 195,205 **** const int tsize; Data *const data; ! int n,count; TableAnyMap *parent,*left,*right;
int _tryix(size_t k) const { - //! return index of data item with key <= k - // FLEXT_ASSERT(n); int ix = 0; --- 198,209 ---- const int tsize; Data *const data; ! int n; ! // int count; TableAnyMap *parent,*left,*right;
+ //! return index of data item with key <= k + //! \note index can point past the last item! int _tryix(size_t k) const { // FLEXT_ASSERT(n); int ix = 0; *************** *** 224,233 **** }
! static void _eraseempty(TableAnyMap *&b) { // FLEXT_ASSERT(b); if(!b->n) { // remove empty branch ! delete b; b = NULL; } } --- 228,237 ---- }
! void _eraseempty(TableAnyMap *&b) { // FLEXT_ASSERT(b); if(!b->n) { // remove empty branch ! _delmap(b); b = NULL; } } *************** *** 242,258 **** { public: ! TablePtrMap(): TableAnyMap(NULL,N,slots) {} virtual ~TablePtrMap() { 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,(void *)t); }
inline T find(K k) const { return (T)TableAnyMap::find(*(size_t *)&k); }
! inline void erase(K k) { TableAnyMap::erase(*(size_t *)&k); } ! inline T remove(K k) { return (T)TableAnyMap::remove(*(size_t *)&k); }
class iterator --- 246,272 ---- { public: ! TablePtrMap(): TableAnyMap(NULL,N,slots),count(0) {} virtual ~TablePtrMap() { clear(); }
! virtual void clear() { TableAnyMap::clear(); count = 0; }
! inline int size() const { return count; }
! inline T insert(K k,T t) ! { ! void *d = TableAnyMap::insert(*(size_t *)&k,(void *)t); ! if(!d) ++count; ! return (T)d; ! }
inline T find(K k) const { return (T)TableAnyMap::find(*(size_t *)&k); }
! // inline void erase(K k) { TableAnyMap::erase(*(size_t *)&k); } ! inline T remove(K k) ! { ! void *d = TableAnyMap::remove(*(size_t *)&k); ! if(d) --count; ! return (T)d; ! }
class iterator *************** *** 275,287 ****
protected: ! TablePtrMap(TableAnyMap *p): TableAnyMap(p,N,slots) {}
! virtual TableAnyMap *New(TableAnyMap *parent) { return new TablePtrMap(parent); }
! virtual void Free(void *ptr) {}
Data slots[N]; };
template <typename K,typename T,int N = 8> class TablePtrMapOwned --- 289,304 ----
protected: ! TablePtrMap(TableAnyMap *p): TableAnyMap(p,N,slots),count(0) {}
! virtual TableAnyMap *_newmap(TableAnyMap *parent) { return new TablePtrMap(parent); } ! virtual void _delmap(TableAnyMap *map) { delete (TablePtrMap *)map; }
! // virtual void Free(void *ptr) {}
+ int count; Data slots[N]; };
+ #if 0 template <typename K,typename T,int N = 8> class TablePtrMapOwned *************** *** 292,295 **** --- 309,313 ----
protected: + /* virtual void Free(void *ptr) { *************** *** 297,302 **** delete (T)ptr; } ! };
//! @} // FLEXT_SUPPORT --- 315,321 ---- delete (T)ptr; } ! */ }; + #endif
//! @} // FLEXT_SUPPORT
Index: flitem.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/flext/source/flitem.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** flitem.cpp 16 Apr 2005 21:35:06 -0000 1.18 --- flitem.cpp 18 Apr 2005 15:07:40 -0000 1.19 *************** *** 16,19 **** --- 16,27 ---- #include <string.h>
+ flext_base::ItemSet::~ItemSet() { clear(); } + + void flext_base::ItemSet::clear() + { + for(iterator it(*this); it; ++it) delete it.data(); + TablePtrMap<const t_symbol *,Item *,8>::clear(); + } +
flext_base::Item::~Item() *************** *** 58,63 **** ItemSet &set = GetInlet(inlet); Item *lst = set.find(tag); ! if(!lst) ! set.insert(tag,lst = item); else for(;;) --- 66,73 ---- ItemSet &set = GetInlet(inlet); Item *lst = set.find(tag); ! if(!lst) { ! Item *old = set.insert(tag,lst = item); ! FLEXT_ASSERT(!old); ! } else for(;;) *************** *** 77,82 **** if(lit == item) { if(prv) prv->nxt = lit->nxt; ! else if(lit->nxt) ! set.insert(tag,lit->nxt); else { Item *l = set.remove(tag); --- 87,94 ---- if(lit == item) { if(prv) prv->nxt = lit->nxt; ! else if(lit->nxt) { ! Item *old = set.insert(tag,lit->nxt); ! FLEXT_ASSERT(!old); ! } else { Item *l = set.remove(tag);
Index: flattr_ed.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/flext/source/flattr_ed.cpp,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** flattr_ed.cpp 15 Mar 2005 04:56:35 -0000 1.36 --- flattr_ed.cpp 18 Apr 2005 15:07:39 -0000 1.37 *************** *** 724,729 **** a.SetInitValue(icnt,argv+ioffs); */ ! if(!a) ! th->attrdata->insert(aname,a = new AttrData);
a->SetSave(sv == 2); --- 724,731 ---- a.SetInitValue(icnt,argv+ioffs); */ ! if(!a) { ! AttrData *old = th->attrdata->insert(aname,a = new AttrData); ! FLEXT_ASSERT(!old); ! }
a->SetSave(sv == 2);
Index: flsupport.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/flext/source/flsupport.cpp,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** flsupport.cpp 31 Mar 2005 03:52:38 -0000 1.48 --- flsupport.cpp 18 Apr 2005 15:07:41 -0000 1.49 *************** *** 309,317 **** void TableAnyMap::clear() { ! if(left) { delete left; left = NULL; } ! if(right) { delete right; right = NULL; }
! for(int i = 0; i < n; ++i) Free(data[i].value); ! count = n = 0; }
--- 309,317 ---- void TableAnyMap::clear() { ! if(left) { _delmap(left); left = NULL; } ! if(right) { _delmap(right); right = NULL; }
! // for(int i = 0; i < n; ++i) Free(data[i].value); ! /*count = */n = 0; }
*************** *** 329,333 **** */
! bool TableAnyMap::_set(size_t k,void *t) { FLEXT_ASSERT(n); --- 329,333 ---- */
! void *TableAnyMap::_set(size_t k,void *t) { FLEXT_ASSERT(n); *************** *** 342,368 ****
int ix = _tryix(k); size_t dk = data[ix].key; if(k == dk) { // update data in existing slot (same key) ! Free(data[ix].value); data[ix] = t; ! return false; ! } ! else if(ix >= n) { ! FLEXT_ASSERT(ix == n); ! // after last entry ! data[n++](k,t); ! ++count; ! return true; } else { // insert new slot by shifting the higher ones FLEXT_ASSERT(k < dk); ! bool a; if(n == tsize) a = _toright(data[tsize-1]); else { ! ++n,++count; ! a = true; }
--- 342,370 ----
int ix = _tryix(k); + if(ix >= n) { + FLEXT_ASSERT(ix == n); + // after last entry + data[n++](k,t); + // ++count; + return NULL; + } + size_t dk = data[ix].key; if(k == dk) { // update data in existing slot (same key) ! void *a = data[ix].value; data[ix] = t; ! return a; } else { // insert new slot by shifting the higher ones FLEXT_ASSERT(k < dk); ! void *a; if(n == tsize) a = _toright(data[tsize-1]); else { ! ++n; ! // ++count; ! a = NULL; }
*************** *** 386,390 ****
const int ix = _tryix(k); ! return data[ix].key == k?data[ix].value:NULL; }
--- 388,392 ----
const int ix = _tryix(k); ! return ix < n && data[ix].key == k?data[ix].value:NULL; }
*************** *** 399,403 **** if(r) { _eraseempty(left); ! --count; } return r; --- 401,405 ---- if(r) { _eraseempty(left); ! // --count; } return r; *************** *** 407,411 **** if(r) { _eraseempty(right); ! --count; } return r; --- 409,413 ---- if(r) { _eraseempty(right); ! // --count; } return r; *************** *** 413,417 ****
const int ix = _tryix(k); ! if(data[ix].key != k) return NULL; else { --- 415,419 ----
const int ix = _tryix(k); ! if(ix >= n || data[ix].key != k) return NULL; else { *************** *** 455,459 **** }
! --count; return ret; } --- 457,461 ---- }
! // --count; return ret; } *************** *** 477,481 **** dt = data[--n]; } ! --count; }
--- 479,483 ---- dt = data[--n]; } ! // --count; }
*************** *** 498,502 **** --n; } ! --count; }
--- 500,504 ---- --n; } ! // --count; }
Index: flattr.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/flext/source/flattr.cpp,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** flattr.cpp 16 Apr 2005 21:35:06 -0000 1.32 --- flattr.cpp 18 Apr 2005 15:07:39 -0000 1.33 *************** *** 44,47 **** --- 44,54 ---- */
+ flext_base::AttrDataCont::~AttrDataCont() { clear(); } + + void flext_base::AttrDataCont::clear() + { + for(iterator it(*this); it; ++it) delete it.data(); + TablePtrMap<const t_symbol *,AttrData *,8>::clear(); + }
//! Add get and set attributes *************** *** 168,172 **** */ AttrData *a = attrdata->find(tag); ! if(!a) attrdata->insert(tag,a = new AttrData);
a->SetInit(true); --- 175,182 ---- */ AttrData *a = attrdata->find(tag); ! if(!a) { ! AttrData *old = attrdata->insert(tag,a = new AttrData); ! FLEXT_ASSERT(!old); ! }
a->SetInit(true);
Index: flclass.h =================================================================== RCS file: /cvsroot/pure-data/externals/grill/flext/source/flclass.h,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** flclass.h 16 Apr 2005 21:35:06 -0000 1.56 --- flclass.h 18 Apr 2005 15:07:40 -0000 1.57 *************** *** 660,664 **** }; */ ! typedef TablePtrMapOwned<const t_symbol *,Item *,8> ItemSet;
/*! This class holds hashed item entries --- 660,670 ---- }; */ ! class ItemSet ! :public TablePtrMap<const t_symbol *,Item *,8> ! { ! public: ! virtual ~ItemSet(); ! virtual void clear(); ! };
/*! This class holds hashed item entries *************** *** 776,780 **** }; */ ! typedef TablePtrMapOwned<const t_symbol *,AttrData *,8> AttrDataCont;
// these outlet functions don't check for thread but send directly to the real-time system --- 782,792 ---- }; */ ! class AttrDataCont ! :public TablePtrMap<const t_symbol *,AttrData *,8> ! { ! public: ! virtual ~AttrDataCont(); ! virtual void clear(); ! };
// these outlet functions don't check for thread but send directly to the real-time system