From f7e8bf39ce93d52d60cc6fd5e6a83539f9d598db Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Tue, 29 Jul 2003 02:32:56 +0000 Subject: "" svn path=/trunk/; revision=800 --- externals/grill/flext/source/flattr.cpp | 99 ++++++++++--------------- externals/grill/flext/source/flattr_ed.cpp | 113 ++++++++++++++++++----------- externals/grill/flext/source/flclass.h | 11 ++- externals/grill/flext/source/flitem.cpp | 3 +- externals/grill/flext/source/flmeth.cpp | 66 ++++++++++++++++- 5 files changed, 182 insertions(+), 110 deletions(-) (limited to 'externals/grill/flext/source') diff --git a/externals/grill/flext/source/flattr.cpp b/externals/grill/flext/source/flattr.cpp index 97c1dd34..40c811de 100644 --- a/externals/grill/flext/source/flattr.cpp +++ b/externals/grill/flext/source/flattr.cpp @@ -14,7 +14,9 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include "flext.h" #include -#include + +#include + #ifdef __MWERKS__ #define STD std @@ -23,7 +25,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #endif flext_base::AttrItem::AttrItem(const t_symbol *t,metharg tp,methfun f,int fl): - Item(t,0,NULL), + Item(t,0,NULL),index(0), flags(fl),argtp(tp),fun(f) {} @@ -38,9 +40,14 @@ void flext_base::AddAttrib(ItemCont *aa,ItemCont *ma,const char *attr,metharg tp { const t_symbol *asym = MakeSymbol(attr); -// if(sfun) // if commented out, there will be a warning at run-time (more user-friendly) + if(sfun) // if commented out, there will be a warning at run-time (more user-friendly) { AttrItem *a = new AttrItem(asym,tp,sfun,AttrItem::afl_bothexist|AttrItem::afl_set); + + // set index of item to the next higher value + AttrItem *last = (AttrItem *)aa->Last(); + if(last) a->index = last->index+1; + aa->Add(a); // bind attribute to a method @@ -49,9 +56,14 @@ void flext_base::AddAttrib(ItemCont *aa,ItemCont *ma,const char *attr,metharg tp ma->Add(mi); } -// if(gfun) // if commented out, there will be a warning at run-time (more user-friendly) + if(gfun) // if commented out, there will be a warning at run-time (more user-friendly) { AttrItem *a = new AttrItem(asym,tp,gfun,AttrItem::afl_bothexist|AttrItem::afl_get); + + // set index of item to the next higher value + AttrItem *last = (AttrItem *)aa->Last(); + if(last) a->index = last->index+1; + aa->Add(a); static char tmp[256] = "get"; @@ -77,20 +89,26 @@ 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::ListAttrib(AtomList &la) const +struct attrless : public std::binary_function { - int cnt = attrhead?attrhead->Count():0; - int ccnt = clattrhead?clattrhead->Count():0; - la(ccnt+cnt); + bool operator()(const flext_base::AttrItem *l,const flext_base::AttrItem *r) const { + return l->index != r->index?l->index < r->index:strcmp(flext::GetString(l->tag),flext::GetString(r->tag)) < 0; + } +}; + +void flext_base::ListAttrib(AtomList &la) const +{ + typedef std::set AttrList; + AttrList list[2]; - int ix = 0; for(int i = 0; i <= 1; ++i) { ItemCont *a = i?attrhead:clattrhead; if(a) { @@ -99,44 +117,21 @@ int flext_base::ListAttrib(AtomList &la) const AttrItem *aa = (AttrItem *)l; // only list once! - if(!aa->BothExist() || aa->IsGet()) - SetSymbol(la[ix++],aa->tag); + if(!aa->BothExist() || aa->IsGet()) + list[i].insert(aa); } } } } - qsort(la.Atoms(),ix,sizeof(t_atom),sortcmp); - return ix; -} - -int flext_base::ListMethods(AtomList &la,int inlet) const -{ - int cnt = methhead?methhead->Count():0; - int ccnt = clmethhead?clmethhead->Count():0; - la(ccnt+cnt); - + la(list[0].size()+list[1].size()); int ix = 0; - for(int i = 0; i <= 1; ++i) { - ItemCont *a = i?methhead:clmethhead; - if(a) { - for(int ai = 0; ai < a->Size(); ++ai) { - for(Item *l = a->GetItem(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; + AttrList::iterator it; + for(i = 0; i <= 1; ++i) + for(it = list[i].begin(); it != list[i].end(); ++it) + SetSymbol(la[ix++],(*it)->tag); } - int flext_base::CheckAttrib(int argc,const t_atom *argv) { int offs = 0; @@ -174,34 +169,14 @@ bool flext_base::ListAttrib() const { if(procattr) { AtomList la; - int c = ListAttrib(la); - ToOutAnything(GetOutAttr(),MakeSymbol("attributes"),c,la.Atoms()); - return true; - } - else - return false; -} - -bool flext_base::ListMethods(int inlet) const -{ - if(procattr) { - AtomList la; - int c = ListMethods(la,inlet); - ToOutAnything(GetOutAttr(),MakeSymbol("methods"),c,la.Atoms()); + ListAttrib(la); + ToOutAnything(GetOutAttr(),MakeSymbol("attributes"),la.Count(),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::FindAttrib(const t_symbol *tag,bool get,bool msg) const { // first search within object scope diff --git a/externals/grill/flext/source/flattr_ed.cpp b/externals/grill/flext/source/flattr_ed.cpp index ea756fd2..8a5f6c7d 100644 --- a/externals/grill/flext/source/flattr_ed.cpp +++ b/externals/grill/flext/source/flattr_ed.cpp @@ -66,30 +66,36 @@ void flext_base::SetAttrEditor(t_classid c) "global $var_attr_val\n" "set var_attr_save [concat [concat var_save_$ix]_$vid ]\n" "global $var_attr_save\n" + "set var_attr_type [concat [concat var_type_$ix]_$vid ]\n" + "global $var_attr_type\n" - "lappend lst [eval concat $$var_attr_name]\n" - - // process current value - "set len [llength [expr $$var_attr_val]]\n" - "if { $len == 1 } {\n" - // it's an atom - "lappend lst [expr $$var_attr_val]\n" - "} else {\n" - // it's a list - "set lst [concat $lst {list} $len [expr $$var_attr_val]]\n" - "}\n" + "if { [expr $$var_attr_type] != 0 } {\n" + // attribute is puttable + + "lappend lst [eval concat $$var_attr_name]\n" + + // process current value + "set len [llength [expr $$var_attr_val]]\n" + "if { $len == 1 } {\n" + // it's an atom + "lappend lst [expr $$var_attr_val]\n" + "} else {\n" + // it's a list + "set lst [concat $lst {list} $len [expr $$var_attr_val]]\n" + "}\n" - // process init value - "set len [llength [expr $$var_attr_init]]\n" - "if { $len == 1 } {\n" - // it's an atom - "lappend lst [expr $$var_attr_init]\n" - "} else {\n" - // it's a list - "set lst [concat $lst {list} $len [expr $$var_attr_init]]\n" - "}\n" + // process init value + "set len [llength [expr $$var_attr_init]]\n" + "if { $len == 1 } {\n" + // it's an atom + "lappend lst [expr $$var_attr_init]\n" + "} else {\n" + // it's a list + "set lst [concat $lst {list} $len [expr $$var_attr_init]]\n" + "}\n" - "lappend lst [eval concat $$var_attr_save]\n" + "lappend lst [eval concat $$var_attr_save]\n" + "}\n" "}\n" "set cmd [concat $id attributedialog $lst \\;]\n" @@ -167,31 +173,50 @@ void flext_base::SetAttrEditor(t_classid c) "global $var_attr_save\n" "set $var_attr_save $asv\n" + // get type flag + "set var_attr_type [concat [concat var_type_$ix]_$vid ]\n" + "global $var_attr_type\n" + "set $var_attr_type $afl\n" + // add dialog elements to window // attribute label "label $id.label-$ix -text \"$an :\" -font {Helvetica 8 bold}\n" "grid config $id.label-$ix -column 0 -row $row -padx 5 -sticky {e}\n" - // entry field for initial value - "entry $id.init-$ix -textvariable $var_attr_init\n" - "grid config $id.init-$ix -column 1 -row $row -padx 5 -sticky {ew}\n" - - "button $id.b2i-$ix -text {<-} -height 1 -command \" flext_copyval $var_attr_init $var_attr_val \"\n" - "grid config $id.b2i-$ix -column 2 -row $row -sticky {ew}\n" - "button $id.b2c-$ix -text {->} -height 1 -command \" flext_copyval $var_attr_val $var_attr_init \"\n" - "grid config $id.b2c-$ix -column 3 -row $row -sticky {ew}\n" - - // entry field for current value - "entry $id.val-$ix -textvariable $var_attr_val\n" - "grid config $id.val-$ix -column 4 -row $row -padx 5 -sticky {ew}\n" - -// "tk_optionMenu $id.opt-$ix $var_attr_save {don't save} {initialize} {always save}\n" -// "grid config $id.opt-$ix -column 5 -row $ix \n" - - // radiobuttons - "foreach {i c} {0 black 1 blue 2 red} {\n" - "radiobutton $id.b$i-$ix -value $i -foreground $c -variable $var_attr_save \n" - "grid config $id.b$i-$ix -column [expr $i + 5] -row $row \n" + + "if { $afl != 0 } {\n" + // attribute is puttable + + // entry field for current value + "entry $id.val-$ix -textvariable $var_attr_val\n" + "grid config $id.val-$ix -column 4 -row $row -padx 5 -sticky {ew}\n" + + // entry field for initial value + "entry $id.init-$ix -textvariable $var_attr_init\n" + "grid config $id.init-$ix -column 1 -row $row -padx 5 -sticky {ew}\n" + + "button $id.b2i-$ix -text {<-} -height 1 -command \" flext_copyval $var_attr_init $var_attr_val \"\n" + "grid config $id.b2i-$ix -column 2 -row $row -sticky {ew}\n" + "button $id.b2c-$ix -text {->} -height 1 -command \" flext_copyval $var_attr_val $var_attr_init \"\n" + "grid config $id.b2c-$ix -column 3 -row $row -sticky {ew}\n" + + // "tk_optionMenu $id.opt-$ix $var_attr_save {don't save} {initialize} {always save}\n" + // "grid config $id.opt-$ix -column 5 -row $ix \n" + + // radiobuttons + "foreach {i c} {0 black 1 blue 2 red} {\n" + "radiobutton $id.b$i-$ix -value $i -foreground $c -variable $var_attr_save \n" + "grid config $id.b$i-$ix -column [expr $i + 5] -row $row \n" + "}\n" + "} else {\n" + // attribute is gettable only + + // entry field for current value (read-only) + "entry $id.val-$ix -textvariable $var_attr_val -state disabled\n" + "grid config $id.val-$ix -column 4 -row $row -padx 5 -sticky {ew}\n" + + "label $id.readonly-$ix -text \"read-only\"\n" + "grid config $id.readonly-$ix -column 5 -columnspan 3 -row $row -padx 5 -sticky {ew}\n" "}\n" // increase counter @@ -263,7 +288,8 @@ void flext_base::cb_GfxProperties(t_gobj *c, t_glist *) STD::sprintf(b, " } { "); b += strlen(b); AtomList la; - int cnt = th->ListAttrib(la); + th->ListAttrib(la); + int cnt = la.Count(); for(int i = 0; i < cnt; ++i) { const t_symbol *sym = GetSymbol(la[i]); @@ -367,7 +393,8 @@ void flext_base::cb_GfxSave(t_gobj *c, t_binbuf *b) // process the attributes AtomList la; - cnt = th->ListAttrib(la); + th->ListAttrib(la); + cnt = la.Count(); char attrname[100]; *attrname= '@'; diff --git a/externals/grill/flext/source/flclass.h b/externals/grill/flext/source/flclass.h index fce496a8..0f7df9c2 100644 --- a/externals/grill/flext/source/flclass.h +++ b/externals/grill/flext/source/flclass.h @@ -531,14 +531,14 @@ protected: bool DumpAttrib(const char *attr) const { return DumpAttrib(MakeSymbol(attr)); } //! List attributes - int ListAttrib(AtomList &a) const; + void ListAttrib(AtomList &a) const; //! Get an attribute value bool GetAttrib(const t_symbol *s,AtomList &a) const; //! Set an attribute value bool SetAttrib(const t_symbol *s,const AtomList &a) { return SetAttrib(s,a.Count(),a.Atoms()); } //! List methods - int ListMethods(AtomList &a,int inlet = 0) const; + void ListMethods(AtomList &a,int inlet = 0) const; /*! \addtogroup FLEXT_C_INOUT @{ @@ -606,6 +606,11 @@ protected: //! Create hash table out of the preliminary linked lists void Finalize(); + + //! Get first element + Item *First() { return !Ready()?arr[0]:NULL; } + //! Get last element + Item *Last() { return !Ready()?arr[1]:NULL; } //! Query whether the array has been finalized bool Ready() const { return bits >= 0; } @@ -634,6 +639,7 @@ protected: void SetArgs(methfun fun,int argc,metharg *args); + int index; int argc; metharg *args; methfun fun; @@ -656,6 +662,7 @@ protected: bool IsSet() const { return (flags&afl_getset) == afl_set; } bool BothExist() const { return (flags&afl_bothexist) != 0; } + int index; int flags; metharg argtp; methfun fun; diff --git a/externals/grill/flext/source/flitem.cpp b/externals/grill/flext/source/flitem.cpp index c2b36057..ffd7f3f1 100755 --- a/externals/grill/flext/source/flitem.cpp +++ b/externals/grill/flext/source/flitem.cpp @@ -117,8 +117,7 @@ bool flext_base::ItemCont::Remove(Item *it) void flext_base::ItemCont::Finalize() { - if(!Ready()) - { + if(!Ready()) { bits = Int2Bits(cnt); // at least enough bits to hold all items // post("This=%p, Count %i, Bits %i",this,cnt,bits); diff --git a/externals/grill/flext/source/flmeth.cpp b/externals/grill/flext/source/flmeth.cpp index 3637529e..e911d563 100755 --- a/externals/grill/flext/source/flmeth.cpp +++ b/externals/grill/flext/source/flmeth.cpp @@ -17,8 +17,11 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include #include "flinternal.h" +#include + + flext_base::MethItem::MethItem(int in,const t_symbol *tg,AttrItem *conn): - Item(tg,in,conn), + Item(tg,in,conn),index(0), argc(0),args(NULL) ,fun(NULL) {} @@ -86,4 +89,65 @@ void flext_base::AddMethod(ItemCont *ma,int inlet,const char *tag,methfun fun,me mi->SetArgs(fun,argc,args); ma->Add(mi); + + // set index + MethItem *last = (MethItem *)ma->Last(); + if(last) mi->index = last->index+1; +} + + +struct methless : public std::binary_function +{ + bool operator()(const flext_base::MethItem *l,const flext_base::MethItem *r) const { + return l->index != r->index?l->index < r->index:strcmp(flext::GetString(l->tag),flext::GetString(r->tag)) < 0; + } +}; + +void flext_base::ListMethods(AtomList &la,int inlet) const +{ + typedef std::set MethList; + MethList list[2]; + + for(int i = 0; i <= 1; ++i) { + ItemCont *a = i?methhead:clmethhead; + if(a) { + for(int ai = 0; ai < a->Size(); ++ai) { + for(Item *l = a->GetItem(ai); l; l = l->nxt) { + MethItem *aa = (MethItem *)l; + + // match inlet and see check it's not related to an attribute + if(aa->inlet == inlet && !aa->IsAttr()) + list[i].insert(aa); + } + } + } + } + + la(list[0].size()+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)->tag); +} + +bool flext_base::ListMethods(int inlet) const +{ + if(procattr) { + AtomList la; + ListMethods(la,inlet); + ToOutAnything(GetOutAttr(),MakeSymbol("methods"),la.Count(),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; } + -- cgit v1.2.1