From 6c11b94129b43ddb663122a4d6274489e63bca3d Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Mon, 20 Oct 2003 02:32:51 +0000 Subject: "" svn path=/trunk/; revision=1109 --- externals/grill/flext/source/flbind.cpp | 37 ++++++++++++++++++++++++++------- externals/grill/flext/source/flclass.h | 9 ++++++++ 2 files changed, 39 insertions(+), 7 deletions(-) (limited to 'externals/grill/flext/source') diff --git a/externals/grill/flext/source/flbind.cpp b/externals/grill/flext/source/flbind.cpp index a74ed33b..815ffa45 100644 --- a/externals/grill/flext/source/flbind.cpp +++ b/externals/grill/flext/source/flbind.cpp @@ -95,10 +95,15 @@ bool flext_base::BindMethod(const t_symbol *sym,bool (*fun)(flext_base *,t_symbo bindhead = new ItemCont; else { // Search for symbol - if(bindhead->Find(sym,0)) { - post("%s - Symbol already bound",thisName()); - return false; - } + flext_base::BindItem *item = (flext_base::BindItem *)bindhead->Find(sym,0); + + // go through all items with matching tag + for(; item && item->tag == sym; item = (flext_base::BindItem *)item->nxt) + if(item->fun == fun) { + // function already registered -> bail out! + post("%s - Symbol already bound with this method",thisName()); + return false; + } if(bindhead->Count() > 20) { // Hash it! @@ -153,12 +158,14 @@ bool flext_base::UnbindMethod(const t_symbol *sym,bool (*fun)(flext_base *,t_sym } } else { - int sz = bindhead->Size(); + // any tag + + int sz = bindhead->Count(); if(!sz) sz = 1; for(int i = 0; i < sz; ++i) { for(it = (BindItem *)bindhead->GetItem(i); it; it = (BindItem *)it->nxt) { - if(it->tag == sym && (!fun || it->fun == fun)) break; + if(!fun || it->fun == fun) break; } if(it) break; } @@ -172,11 +179,27 @@ bool flext_base::UnbindMethod(const t_symbol *sym,bool (*fun)(flext_base *,t_sym return ok; } +bool flext_base::GetBoundMethod(const t_symbol *sym,bool (*fun)(flext_base *,t_symbol *s,int argc,t_atom *argv,void *data),void *&data) +{ + if(bindhead) { + // Search for symbol + flext_base::BindItem *item = (flext_base::BindItem *)bindhead->Find(sym,0); + + // go through all items with matching tag + for(; item && item->tag == sym; item = (flext_base::BindItem *)item->nxt) + if(item->fun == fun) { + data = item->px->data; + return true; + } + } + return false; +} + bool flext_base::UnbindAll() { // bool memleak = false; - int sz = bindhead->Size(); + int sz = bindhead->Count(); if(!sz) sz = 1; for(int i = 0; i < sz; ++i) { diff --git a/externals/grill/flext/source/flclass.h b/externals/grill/flext/source/flclass.h index fa5337b7..17842bd2 100644 --- a/externals/grill/flext/source/flclass.h +++ b/externals/grill/flext/source/flclass.h @@ -437,11 +437,20 @@ public: \return true on success */ bool UnbindMethod(const t_symbol *sym,bool (*meth)(flext_base *obj,t_symbol *sym,int argc,t_atom *argv,void *data) = NULL,void **data = NULL); + /*! \brief Get data of bound method of a symbol + \param sym Symbol to bind to + \param meth Function to bind + \param data Reference to returned user data + \return true on success (symbol/method combination was found) + */ + bool GetBoundMethod(const t_symbol *sym,bool (*meth)(flext_base *obj,t_symbol *sym,int argc,t_atom *argv,void *data),void *&data); //! \brief Bind a method to a symbol (as string) bool BindMethod(const char *sym,bool (*meth)(flext_base *obj,t_symbol *sym,int argc,t_atom *argv,void *data),void *data = NULL) { return BindMethod(MakeSymbol(sym),meth,data); } //! \brief Unbind a method from a symbol (as string) bool UnbindMethod(const char *sym,bool (*meth)(flext_base *obj,t_symbol *sym,int argc,t_atom *argv,void *data) = NULL,void **data = NULL) { return UnbindMethod(MakeSymbol(sym),meth,data); } + //! \brief Get data of bound method of a symbol (as string) + bool GetBoundMethod(const char *sym,bool (*meth)(flext_base *obj,t_symbol *sym,int argc,t_atom *argv,void *data),void *&data) { return GetBoundMethod(MakeSymbol(sym),meth,data); } /*! Unbind all symbol bindings \note Memory associated to data pointers passed by BindMethod will not be freed! -- cgit v1.2.1