From 1d296c40615533f41472fbc5d552f0f9ebd5c2b1 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Wed, 18 Jun 2003 02:41:05 +0000 Subject: "" svn path=/trunk/; revision=704 --- externals/grill/flext/source/flattr.cpp | 66 ++++++++++++++++++++++++++++++++- externals/grill/flext/source/flclass.h | 14 +++++-- externals/grill/flext/source/flext.cpp | 6 ++- 3 files changed, 80 insertions(+), 6 deletions(-) (limited to 'externals/grill/flext/source') diff --git a/externals/grill/flext/source/flattr.cpp b/externals/grill/flext/source/flattr.cpp index 0cdc74c9..e22c15a8 100644 --- a/externals/grill/flext/source/flattr.cpp +++ b/externals/grill/flext/source/flattr.cpp @@ -14,6 +14,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include "flext.h" #include +#include #ifdef __MWERKS__ #define STD std @@ -76,6 +77,13 @@ void flext_base::AddAttrib(t_classid c,const char *attr,metharg tp,methfun gfun, AddAttrib(ClAttrs(c),ClMeths(c),attr,tp,gfun,sfun); } + +//! Sorting function for pure symbol atom lists (used with qsort below) +static int sortcmp(const void *a, const void *b) +{ + return strcmp(flext::GetString(*(t_atom *)a),flext::GetString(*(t_atom *)b)); +} + int flext_base::ListAttr(AtomList &la) const { int cnt = attrhead?attrhead->Count():0; @@ -90,12 +98,43 @@ int flext_base::ListAttr(AtomList &la) const for(item *l = a->Item(ai); l; l = l->nxt) { attritem *aa = (attritem *)l; + + // only list once! if(!aa->BothExist() || aa->IsGet()) SetSymbol(la[ix++],aa->tag); } } } } + + qsort(la.Atoms(),ix,sizeof(t_atom),sortcmp); + return ix; +} + +int flext_base::ListMeth(AtomList &la,int inlet) const +{ + int cnt = methhead?methhead->Count():0; + int ccnt = clmethhead?clmethhead->Count():0; + la(ccnt+cnt); + + int ix = 0; + for(int i = 0; i <= 1; ++i) { + itemarr *a = i?methhead:clmethhead; + if(a) { + for(int ai = 0; ai < a->Size(); ++ai) { + for(item *l = a->Item(ai); l; l = l->nxt) + { + methitem *aa = (methitem *)l; + + // match inlet and see that it's not related to an attribute + if(aa->inlet == inlet && !aa->IsAttr()) + SetSymbol(la[ix++],aa->tag); + } + } + } + } + + qsort(la.Atoms(),ix,sizeof(t_atom),sortcmp); return ix; } @@ -122,7 +161,7 @@ bool flext_base::InitAttrib(int argc,const t_atom *argv) return true; } -bool flext_base::ListAttrib() +bool flext_base::ListAttrib() const { if(procattr) { AtomList la; @@ -134,6 +173,26 @@ bool flext_base::ListAttrib() return false; } +bool flext_base::ListMethods(int inlet) const +{ + if(procattr) { + AtomList la; + int c = ListMeth(la,inlet); + ToOutAnything(GetOutAttr(),MakeSymbol("methods"),c,la.Atoms()); + return true; + } + else + return false; +} + +bool flext_base::cb_ListMethods(flext_base *c,int argc,const t_atom *argv) +{ + if(argc == 0 || (argc == 1 && CanbeInt(argv[0]))) + return c->ListMethods(argc?GetAInt(argv[0]):0); + else + return false; +} + flext_base::attritem *flext_base::FindAttr(const t_symbol *tag,bool get) const { // first search within object scope @@ -249,3 +308,8 @@ bool flext_base::GetAttrib(attritem *a) return true; } +bool flext_base::DumpAttrib(const t_symbol *attr) const +{ + attritem *item = FindAttr(attr,true); + return item && const_cast(this)->GetAttrib(item); +} diff --git a/externals/grill/flext/source/flclass.h b/externals/grill/flext/source/flclass.h index c5559153..8b0e0dc7 100644 --- a/externals/grill/flext/source/flclass.h +++ b/externals/grill/flext/source/flclass.h @@ -310,8 +310,8 @@ public: a_null = 0, a_float,a_int, a_symbol,a_pointer, - a_list,a_any, - a_LIST,a_ANY + a_list,a_any, // (t_symbol *) / int / t_atom * + a_LIST,a_ANY // AtomList, AtomAnything }; typedef bool (*methfun)(flext_base *c); @@ -519,6 +519,11 @@ protected: //! @} FLEXT_C_CATTR + //! Dump an attribute to the attribute outlet + bool DumpAttrib(const t_symbol *attr) const; + //! Dump an attribute to the attribute outlet + bool DumpAttrib(const char *attr) const { return DumpAttrib(MakeSymbol(attr)); } + /*! \addtogroup FLEXT_C_INOUT @{ */ @@ -717,15 +722,18 @@ private: attritem *FindAttr(const t_symbol *tag,bool get) const; int ListAttr(AtomList &a) const; + int ListMeth(AtomList &a,int inlet = 0) const; static int CheckAttrib(int argc,const t_atom *argv); bool InitAttrib(int argc,const t_atom *argv); - bool ListAttrib(); + bool ListMethods(int inlet = 0) const; + bool ListAttrib() const; bool GetAttrib(attritem *a); bool SetAttrib(const t_symbol *s,int argc,const t_atom *argv); bool SetAttrib(attritem *a,int argc,const t_atom *argv); + static bool cb_ListMethods(flext_base *c,int argc,const t_atom *argv); static bool cb_ListAttrib(flext_base *c) { return c->ListAttrib(); } // queue stuff diff --git a/externals/grill/flext/source/flext.cpp b/externals/grill/flext/source/flext.cpp index fc033b21..78f01ff5 100644 --- a/externals/grill/flext/source/flext.cpp +++ b/externals/grill/flext/source/flext.cpp @@ -154,8 +154,10 @@ void flext_base::Setup(t_classid id) #pragma message ("no implementation of loadbang or assist") #endif - if(process_attributes) - AddMethod(id,0,"getattributes",(methfun)cb_ListAttrib); + if(process_attributes) { + AddMethod(id,0,"getattributes",cb_ListAttrib); + AddMethod(id,0,"getmethods",cb_ListMethods); + } SetProxies(c); -- cgit v1.2.1