diff options
-rw-r--r-- | externals/grill/flext/changes.txt | 1 | ||||
-rw-r--r-- | externals/grill/flext/source/flatom.cpp | 39 | ||||
-rw-r--r-- | externals/grill/flext/source/flsupport.h | 19 |
3 files changed, 59 insertions, 0 deletions
diff --git a/externals/grill/flext/changes.txt b/externals/grill/flext/changes.txt index 4fcc9bf2..f4539886 100644 --- a/externals/grill/flext/changes.txt +++ b/externals/grill/flext/changes.txt @@ -23,6 +23,7 @@ Version history: - "getattributes" or "getmethods" output lists are now alphabethically sorted - flext::StopThread function to terminate running threads (started with LaunchThread) - added flext::post() and flext::error() console printing (thread-safe) +- added flext::CmpAtom and AtomList::operator < methods ... useful for using lists as keys for STL 0.4.4: - fixed deadly bug for Max/MSP method-to-symbol-binding proxies diff --git a/externals/grill/flext/source/flatom.cpp b/externals/grill/flext/source/flatom.cpp index 0e7eb544..45739e66 100644 --- a/externals/grill/flext/source/flatom.cpp +++ b/externals/grill/flext/source/flatom.cpp @@ -14,6 +14,32 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include "flext.h" +#if FLEXT_SYS != FLEXT_SYS_JMAX +int flext::CmpAtom(const t_atom &a,const t_atom &b) +{ + if(GetType(a) == GetType(b)) { + switch(GetType(a)) { + case A_FLOAT: return GetFloat(a) == GetFloat(b)?0:(GetFloat(a) < GetFloat(b)?-1:1); +#if FLEXT_SYS == FLEXT_SYS_MAX + case A_INT: return GetInt(a) == GetInt(b)?0:(GetInt(a) < GetInt(b)?-1:1); +#endif + case A_SYMBOL: return GetSymbol(a) == GetSymbol(b)?0:(GetSymbol(a) < GetSymbol(b)?-1:1); +#if FLEXT_SYS == FLEXT_SYS_PD + case A_POINTER: return GetPointer(a) == GetPointer(b)?0:(GetPointer(a) < GetPointer(b)?-1:1); +#endif + default: + // can't be compared..... + FLEXT_ASSERT(false); + return 0; + } + } + else + return GetType(a) < GetType(b)?-1:1; +} +#else +#error Not implemented +#endif + t_atom *flext::CopyList(int argc,const t_atom *argv) { int i; @@ -52,6 +78,19 @@ flext::AtomList &flext::AtomList::Set(int argc,const t_atom *argv,int offs,bool return *this; } +int flext::AtomList::Compare(const AtomList &a) const +{ + if(Count() == a.Count()) { + for(int i = 0; i < Count(); ++i) { + int cmp = CmpAtom((*this)[i],a[i]); + if(cmp) return cmp; + } + return 0; + } + else + return Count() < a.Count()?-1:1; +} + #if FLEXT_SYS != FLEXT_SYS_JMAX // not for jmax as long as t_symbol * == char * diff --git a/externals/grill/flext/source/flsupport.h b/externals/grill/flext/source/flsupport.h index 457ed4d0..f2129d7c 100644 --- a/externals/grill/flext/source/flsupport.h +++ b/externals/grill/flext/source/flsupport.h @@ -293,6 +293,15 @@ public: //! Set atom from another atom static void SetAtom(t_atom &a,const t_atom &b) { CopyAtom(&a,&b); } + //! Compare two atoms + static int CmpAtom(const t_atom &a,const t_atom &b); + + static bool operator ==(const t_atom &a,const t_atom &b) { return CmpAtom(a,b) == 0; } + static bool operator !=(const t_atom &a,const t_atom &b) { return CmpAtom(a,b) != 0; } + static bool operator <(const t_atom &a,const t_atom &b) { return CmpAtom(a,b) < 0; } + static bool operator <=(const t_atom &a,const t_atom &b) { return CmpAtom(a,b) <= 0; } + static bool operator >(const t_atom &a,const t_atom &b) { return CmpAtom(a,b) > 0; } + static bool operator >=(const t_atom &a,const t_atom &b) { return CmpAtom(a,b) >= 0; } #if FLEXT_SYS == FLEXT_SYS_JMAX //! Set atom from another atom @@ -479,6 +488,16 @@ public: //! Set list by another AtomList AtomList &operator =(const AtomList &a) { return operator()(a.Count(),a.Atoms()); } + //! Compare list to another AtomList ( -1..< , 0..==, 1...> ) + int Compare(const AtomList &a) const; + + bool operator <(const AtomList &a) const { return Compare(a) < 0; } + bool operator <=(const AtomList &a) const { return Compare(a) <= 0; } + bool operator >(const AtomList &a) const { return Compare(a) > 0; } + bool operator >=(const AtomList &a) const { return Compare(a) >= 0; } + bool operator ==(const AtomList &a) const { return Compare(a) == 0; } + bool operator !=(const AtomList &a) const { return Compare(a) != 0; } + //! Get number of atoms in the list int Count() const { return cnt; } //! Get a reference to an indexed atom |