diff options
Diffstat (limited to 'externals/grill/flext/source')
-rw-r--r-- | externals/grill/flext/source/flatom.cpp | 46 | ||||
-rwxr-xr-x | externals/grill/flext/source/flatom_app.cpp | 76 | ||||
-rw-r--r-- | externals/grill/flext/source/flstdc.h | 40 | ||||
-rw-r--r-- | externals/grill/flext/source/flsupport.h | 114 |
4 files changed, 141 insertions, 135 deletions
diff --git a/externals/grill/flext/source/flatom.cpp b/externals/grill/flext/source/flatom.cpp index bf057c00..ae133425 100644 --- a/externals/grill/flext/source/flatom.cpp +++ b/externals/grill/flext/source/flatom.cpp @@ -48,15 +48,32 @@ t_atom *flext::CopyList(int argc,const t_atom *argv) return dst; } -void flext::AtomList::Alloc(int sz) +static void copyatoms(int cnt,t_atom *dst,const t_atom *src) +{ + if(dst < src) + // forward + memcpy(dst,src,cnt*sizeof(t_atom)); + else + // backwards + while(cnt--) dst[cnt] = src[cnt]; +} + +void flext::AtomList::Alloc(int sz,int keepix,int keeplen,int keepto) { if(lst) { if(cnt == sz) return; // no change + + t_atom *l = new t_atom[sz]; + if(keepix >= 0) + // keep contents + copyatoms(keeplen >= 0?keeplen:(cnt > sz?sz:cnt),l+keepto,lst+keepix); delete[] lst; + lst = l,cnt = sz; } - else + else { FLEXT_ASSERT(cnt == 0); - lst = new t_atom[cnt = sz]; + lst = new t_atom[cnt = sz]; + } } flext::AtomList::~AtomList() { Free(); } @@ -76,10 +93,8 @@ flext::AtomList &flext::AtomList::Set(int argc,const t_atom *argv,int offs,bool int ncnt = argc+offs; if(resize) Alloc(ncnt); - // argv can be NULL indepently from argc - if(argv) - for(int i = 0; i < argc; ++i) - SetAtom(lst[offs+i],argv[i]); + // argv can be NULL independently from argc + if(argv) copyatoms(argc,lst+offs,argv); return *this; } @@ -88,7 +103,7 @@ 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]); + int cmp = CmpAtom(lst[i],a[i]); if(cmp) return cmp; } return 0; @@ -99,10 +114,19 @@ int flext::AtomList::Compare(const AtomList &a) const flext::AtomListStaticBase::~AtomListStaticBase() { Free(); } -void flext::AtomListStaticBase::Alloc(int sz) +void flext::AtomListStaticBase::Alloc(int sz,int keepix,int keeplen,int keepto) { - if(sz < precnt) lst = predata,cnt = sz; - else AtomList::Alloc(sz); + if(sz < precnt) { + if(lst != predata && lst) { + if(keepix >= 0) + // keep contents + copyatoms(keeplen >= 0?keeplen:(cnt > sz?sz:cnt),predata+keepto,lst+keepix); + AtomList::Free(); + } + lst = predata,cnt = sz; + } + else + AtomList::Alloc(sz,keepix,keeplen,keepto); } void flext::AtomListStaticBase::Free() diff --git a/externals/grill/flext/source/flatom_app.cpp b/externals/grill/flext/source/flatom_app.cpp deleted file mode 100755 index d028202b..00000000 --- a/externals/grill/flext/source/flatom_app.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - -flext - C++ layer for Max/MSP and pd (pure data) externals - -Copyright (c) 2001-2005 Thomas Grill (gr@grrrr.org) -For information on usage and redistribution, and for a DISCLAIMER OF ALL -WARRANTIES, see the file, "license.txt," in this distribution. - -*/ - -/*! \file flatom_app.cpp - \brief Definitions for handling the t_atom type and lists thereof. -*/ - -#include "flext.h" - - -flext::AtomList &flext::AtomList::Append(const t_atom &a) -{ - t_atom *nlst = new t_atom[cnt+1]; - for(int i = 0; i < cnt; ++i) SetAtom(nlst[i],lst[i]); - SetAtom(nlst[cnt],a); - - if(lst) delete[] lst; - lst = nlst; - ++cnt; - - return *this; -} - -flext::AtomList &flext::AtomList::Append(int argc,const t_atom *argv) -{ - if(argc) { - t_atom *nlst = new t_atom[cnt+argc]; - int i; - for(i = 0; i < cnt; ++i) SetAtom(nlst[i],lst[i]); - if(argv) - for(i = 0; i < argc; ++i) SetAtom(nlst[cnt+i],argv[i]); - - if(lst) delete[] lst; - lst = nlst; - cnt += argc; - } - return *this; -} - -flext::AtomList &flext::AtomList::Prepend(const t_atom &a) -{ - t_atom *nlst = new t_atom[cnt+1]; - for(int i = 0; i < cnt; ++i) SetAtom(nlst[i+1],lst[i]); - SetAtom(nlst[0],a); - - if(lst) delete[] lst; - lst = nlst; - ++cnt; - - return *this; -} - -flext::AtomList &flext::AtomList::Prepend(int argc,const t_atom *argv) -{ - if(argc) { - t_atom *nlst = new t_atom[cnt+argc]; - int i; - - if(argv) - for(i = 0; i < argc; ++i) SetAtom(nlst[i],argv[i]); - for(i = 0; i < cnt; ++i) SetAtom(nlst[argc+i],lst[i]); - - if(lst) delete[] lst; - lst = nlst; - cnt += argc; - } - return *this; -} - diff --git a/externals/grill/flext/source/flstdc.h b/externals/grill/flext/source/flstdc.h index 75e17d57..fcf43934 100644 --- a/externals/grill/flext/source/flstdc.h +++ b/externals/grill/flext/source/flstdc.h @@ -26,6 +26,12 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include <math.h> #endif +#ifdef FLEXT_DEBUG +#if FLEXT_OS == FLEXT_OS_WIN +#include <crtdbg.h> +#endif +#endif + // PD stuff #if FLEXT_SYS == FLEXT_SYS_PD @@ -223,15 +229,31 @@ typedef t_symbol *t_symptr; // ------------------------- #ifdef FLEXT_LOGGING - /* If FLEXT_LOGGING is defined implement logging */ + +#if FLEXT_OS == FLEXT_OS_WIN +#define FLEXT_LOG(s) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s) +#define FLEXT_LOG1(s,v1) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1) +#define FLEXT_LOG2(s,v1,v2) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1,v2) +#define FLEXT_LOG3(s,v1,v2,v3) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1,v2,v3) +#define FLEXT_LOG4(s,v1,v2,v3,v4) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1,v2,v3,v4) +#define FLEXT_LOG5(s,v1,v2,v3,v4,v5) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1,v2,v3,v4,v5) +#define FLEXT_LOG6(s,v1,v2,v3,v4,v5,v6) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1,v2,v3,v4,v5,v6) +#define FLEXT_LOG7(s,v1,v2,v3,v4,v5,v6,v7) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1,v2,v3,v4,v5,v6,v7) +#define FLEXT_LOG8(s,v1,v2,v3,v4,v5,v6,v7,v8) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1,v2,v3,v4,v5,v6,v7,v8) +#define FLEXT_LOG9(s,v1,v2,v3,v4,v5,v6,v7,v8,v9) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1,v2,v3,v4,v5,v6,v7,v8,v9) +#else #define FLEXT_LOG(s) post(s) #define FLEXT_LOG1(s,v1) post(s,v1) #define FLEXT_LOG2(s,v1,v2) post(s,v1,v2) #define FLEXT_LOG3(s,v1,v2,v3) post(s,v1,v2,v3) #define FLEXT_LOG4(s,v1,v2,v3,v4) post(s,v1,v2,v3,v4) #define FLEXT_LOG5(s,v1,v2,v3,v4,v5) post(s,v1,v2,v3,v4,v5) - +#define FLEXT_LOG6(s,v1,v2,v3,v4,v5,v6) post(s,v1,v2,v3,v4,v5,v6) +#define FLEXT_LOG7(s,v1,v2,v3,v4,v5,v6,v7) post(s,v1,v2,v3,v4,v5,v6,v7) +#define FLEXT_LOG8(s,v1,v2,v3,v4,v5,v6,v7,v8) post(s,v1,v2,v3,v4,v5,v6,v7,v8) +#define FLEXT_LOG9(s,v1,v2,v3,v4,v5,v6,v7,v8,v9) post(s,v1,v2,v3,v4,v5,v6,v7,v8,v9) +#endif #else @@ -242,13 +264,27 @@ typedef t_symbol *t_symptr; #define FLEXT_LOG3(s,v1,v2,v3) ((void)0) #define FLEXT_LOG4(s,v1,v2,v3,v4) ((void)0) #define FLEXT_LOG5(s,v1,v2,v3,v4,v5) ((void)0) +#define FLEXT_LOG6(s,v1,v2,v3,v4,v5,v6) ((void)0) +#define FLEXT_LOG7(s,v1,v2,v3,v4,v5,v6,v7) ((void)0) +#define FLEXT_LOG8(s,v1,v2,v3,v4,v5,v6,v7,v8) ((void)0) +#define FLEXT_LOG9(s,v1,v2,v3,v4,v5,v6,v7,v8,v9) ((void)0) #endif #ifdef FLEXT_DEBUG +#if FLEXT_OS == FLEXT_OS_WIN +#define FLEXT_ASSERT(b) (!(b)?_CrtDbgReport(_CRT_ASSERT,__FILE__,__LINE__,"flext",#b):1) +#define FLEXT_WARN(str) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",NULL) +#define FLEXT_ERROR(str) _CrtDbgReport(_CRT_ERROR,__FILE__,__LINE__,"flext",NULL) +#else #define FLEXT_ASSERT(b) (!(b)?(error("Assertion failed: " #b " - in " __FILE__ " line %i",(int)__LINE__),0):1) +#define FLEXT_WARN(str) error("Warning: in " __FILE__ " line %i",(int)__LINE__) +#define FLEXT_ERROR(str) error("Error: in " __FILE__ " line %i",(int)__LINE__) +#endif #else #define FLEXT_ASSERT(b) (1) +#define FLEXT_WARN(str) (1) +#define FLEXT_ERROR(str) error("Error: in " __FILE__ " line %i",(int)__LINE__) #endif #define ERRINTERNAL() error("flext: Internal error in file " __FILE__ ", line %i - please report",(int)__LINE__) diff --git a/externals/grill/flext/source/flsupport.h b/externals/grill/flext/source/flsupport.h index 9c5a7a41..39713b1c 100644 --- a/externals/grill/flext/source/flsupport.h +++ b/externals/grill/flext/source/flsupport.h @@ -34,10 +34,10 @@ class FLEXT_SHARE FLEXT_CLASSDEF(flext_root) { public: // --- console output ----------------------------------------------- - //! post message to console, with line feed (limited to 1k chars!) - static void post(const char *fmt,...); - //! post error message to console (limited to 1k chars!) - static void error(const char *fmt,...); + //! post message to console, with line feed (limited to 1k chars!) + static void post(const char *fmt,...); + //! post error message to console (limited to 1k chars!) + static void error(const char *fmt,...); // --- memory ------------------------------------------------------- @@ -45,33 +45,33 @@ public: @{ */ - /*! Overloaded new memory allocation method - \note this uses a fast allocation method of the real-time system - \warning Max/MSP (or MacOS) allows only 32K in overdrive mode! - */ - void *operator new(size_t bytes); - //! Overloaded delete method - void operator delete(void *blk); - - inline void *operator new(size_t,void *p) { return p; } - inline void operator delete(void *,void *) {} - - #ifndef __MRC__ // doesn't allow new[] overloading?! - inline void *operator new[](size_t bytes) { return operator new(bytes); } - inline void operator delete[](void *blk) { operator delete(blk); } - - inline void *operator new[](size_t,void *p) { return p; } - inline void operator delete[](void *,void *) {} - #endif - - //! Get an aligned memory block - static void *NewAligned(size_t bytes,int bitalign = 128); - //! Free an aligned memory block - static void FreeAligned(void *blk); - //! Test for alignment - static bool IsAligned(void *ptr,int bitalign = 128) { - return (reinterpret_cast<size_t>(ptr)&(bitalign-1)) == 0; - } + /*! Overloaded new memory allocation method + \note this uses a fast allocation method of the real-time system + \warning Max/MSP (or MacOS) allows only 32K in overdrive mode! + */ + void *operator new(size_t bytes); + //! Overloaded delete method + void operator delete(void *blk); + + inline void *operator new(size_t,void *p) { return p; } + inline void operator delete(void *,void *) {} + + #ifndef __MRC__ // doesn't allow new[] overloading?! + inline void *operator new[](size_t bytes) { return operator new(bytes); } + inline void operator delete[](void *blk) { operator delete(blk); } + + inline void *operator new[](size_t,void *p) { return p; } + inline void operator delete[](void *,void *) {} + #endif + + //! Get an aligned memory block + static void *NewAligned(size_t bytes,int bitalign = 128); + //! Free an aligned memory block + static void FreeAligned(void *blk); + //! Test for alignment + static bool IsAligned(void *ptr,int bitalign = 128) { + return (reinterpret_cast<size_t>(ptr)&(bitalign-1)) == 0; + } //! @} FLEXT_S_MEMORY }; @@ -140,6 +140,14 @@ public: //! Flext version string static const char *VersionStr(); +// --- special typedefs --------------------------------------------- + + typedef t_float Float; + typedef t_int Int; + typedef t_sample Sample; + typedef const t_symbol *Symbol; + typedef t_atom Atom; + // --- buffer/array stuff ----------------------------------------- /*! \defgroup FLEXT_S_BUFFER Buffer handling @@ -593,16 +601,30 @@ public: //! Get a pointer to the list of atoms const t_atom *Atoms() const { return lst; } - //! Append an atom to the list - AtomList &Append(const t_atom &a); - //! Append an atom list to the list - AtomList &Append(int argc,const t_atom *argv = NULL); //! Append an atom list to the list + AtomList &Append(int argc,const t_atom *argv = NULL) + { + int c = Count(); + Alloc(c+argc,0,c); + Set(argc,argv,c); + return *this; + } + + //! Prepend an atom list to the list + AtomList &Prepend(int argc,const t_atom *argv = NULL) + { + int c = Count(); + Alloc(c+argc,0,c,argc); + Set(argc,argv); + return *this; + } + + //! Append an atom to the list + AtomList &Append(const t_atom &a) { return Append(1,&a); } + //! Append an atom list to the list AtomList &Append(const AtomList &a) { return Append(a.Count(),a.Atoms()); } //! Prepend an atom to the list - AtomList &Prepend(const t_atom &a); - //! Prepend an atom list to the list - AtomList &Prepend(int argc,const t_atom *argv = NULL); + AtomList &Prepend(const t_atom &a) { return Prepend(1,&a); } //! Prepend an atom list to the list AtomList &Prepend(const AtomList &a) { return Prepend(a.Count(),a.Atoms()); } @@ -615,7 +637,7 @@ public: bool Print(char *buffer,int buflen) const { return flext::PrintList(Count(),Atoms(),buffer,buflen); } protected: - virtual void Alloc(int sz); + virtual void Alloc(int sz,int keepix = -1,int keeplen = -1,int keepto = 0); virtual void Free(); int cnt; @@ -628,7 +650,7 @@ public: protected: AtomListStaticBase(int pc,t_atom *dt): precnt(pc),predata(dt) {} virtual ~AtomListStaticBase(); - virtual void Alloc(int sz); + virtual void Alloc(int sz,int keepix = -1,int keeplen = -1,int keepto = 0); virtual void Free(); const int precnt; @@ -1195,12 +1217,12 @@ protected: // gcc doesn't like these to be included into the flext class (even if static) -inline bool operator ==(const t_atom &a,const t_atom &b) { return FLEXT_CLASSDEF(flext)::CmpAtom(a,b) == 0; } -inline bool operator !=(const t_atom &a,const t_atom &b) { return FLEXT_CLASSDEF(flext)::CmpAtom(a,b) != 0; } -inline bool operator <(const t_atom &a,const t_atom &b) { return FLEXT_CLASSDEF(flext)::CmpAtom(a,b) < 0; } -inline bool operator <=(const t_atom &a,const t_atom &b) { return FLEXT_CLASSDEF(flext)::CmpAtom(a,b) <= 0; } -inline bool operator >(const t_atom &a,const t_atom &b) { return FLEXT_CLASSDEF(flext)::CmpAtom(a,b) > 0; } -inline bool operator >=(const t_atom &a,const t_atom &b) { return FLEXT_CLASSDEF(flext)::CmpAtom(a,b) >= 0; } +inline bool operator ==(const t_atom &a,const t_atom &b) { return flext::CmpAtom(a,b) == 0; } +inline bool operator !=(const t_atom &a,const t_atom &b) { return flext::CmpAtom(a,b) != 0; } +inline bool operator <(const t_atom &a,const t_atom &b) { return flext::CmpAtom(a,b) < 0; } +inline bool operator <=(const t_atom &a,const t_atom &b) { return flext::CmpAtom(a,b) <= 0; } +inline bool operator >(const t_atom &a,const t_atom &b) { return flext::CmpAtom(a,b) > 0; } +inline bool operator >=(const t_atom &a,const t_atom &b) { return flext::CmpAtom(a,b) >= 0; } //! @} // FLEXT_SUPPORT |