Update of /cvsroot/pure-data/externals/grill/flext/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29940/source
Modified Files: flatom_pr.cpp flsupport.h Log Message: more robust string->atom conversion eliminate jmax code
Index: flatom_pr.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/flext/source/flatom_pr.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** flatom_pr.cpp 26 Jan 2005 05:01:24 -0000 1.21 --- flatom_pr.cpp 6 Oct 2005 19:53:34 -0000 1.22 *************** *** 89,128 ****
! bool flext::ScanAtom(t_atom &a,const char *buf) { ! // skip whitespace ! while(*buf && isspace(*buf)) ++buf; ! if(!*buf) return false;
! char tmp[1024]; ! strcpy(tmp,buf); ! char *c = tmp;
! // check for word type (s = 0,1,2 ... int,float,symbol) ! int s = 0; ! for(; *c && !isspace(*c); ++c) { ! if(!isdigit(*c)) ! s = (*c != '.' || s == 1)?2:1; }
! switch(s) { ! case 0: // integer ! #if FLEXT_SYS == FLEXT_SYS_MAX ! SetInt(a,atol(tmp)); ! break; ! #endif ! case 1: // float ! SetFloat(a,(float)atof(tmp)); ! break; ! default: { // anything else is a symbol ! char t = *c; *c = 0; ! SetString(a,tmp); ! *c = t; ! break; ! } ! }
! return true; } - - --- 89,121 ----
! const char *flext::ScanAtom(t_atom &a,const char *c) { ! // skip leading whitespace ! while(*c && isspace(*c)) ++c; ! if(!*c) return NULL;
! // go to next space and save character ! char *end = const_cast<char *>(c); ! while(*end && !isspace(*end)) ++end; ! char sv = *end;
! float fres; ! // first try float ! char *endp; ! // see if it's a float - thanks to Frank Barknecht ! fres = (float)strtod(c,&endp); ! if(!*c && endp != c) { ! int ires = (int)fres; // try a cast ! if(fres == ires) ! SetInt(a,ires); ! else ! SetFloat(a,fres); } + // no, it's a symbol + else + SetString(a,c);
! *end = sv;
! return c; }
Index: flsupport.h =================================================================== RCS file: /cvsroot/pure-data/externals/grill/flext/source/flsupport.h,v retrieving revision 1.97 retrieving revision 1.98 diff -C2 -d -r1.97 -r1.98 *** flsupport.h 12 Sep 2005 10:27:40 -0000 1.97 --- flsupport.h 6 Oct 2005 19:53:34 -0000 1.98 *************** *** 171,177 **** */
- // not for Jmax at the moment - #if FLEXT_SYS != FLEXT_SYS_JMAX - //! Class for platform independent buffer handling class FLEXT_SHARE buffer: --- 171,174 ---- *************** *** 315,319 **** };
- #endif // jmax
//! @} FLEXT_S_BUFFER --- 312,315 ---- *************** *** 330,335 **** //! Print an atom static bool PrintAtom(const t_atom &a,char *buf,size_t bufsz); ! //! Scan an atom ! static bool ScanAtom(t_atom &a,const char *buf);
//! Copy a list of atoms --- 326,334 ---- //! Print an atom static bool PrintAtom(const t_atom &a,char *buf,size_t bufsz); ! ! /*! Scan an atom until whitespace ! \return next token position, or NULL on failure ! */ ! static const char *ScanAtom(t_atom &a,const char *buf);
//! Copy a list of atoms *************** *** 390,404 **** static const t_symbol *MakeSymbol(const t_symbol *s) { return s; }
- #if FLEXT_SYS == FLEXT_SYS_JMAX - //! Make a symbol from a string - static const t_symbol *MakeSymbol(const char *s) { return ::fts_new_symbol(s); } - //! Get symbol string - static const char *GetString(const t_symbol *s); // ** TODO ** - #else //! Make a symbol from a string static const t_symbol *MakeSymbol(const char *s) { return ::gensym(const_cast<char *>(s)); } //! Get symbol string static const char *GetString(const t_symbol *s) { return s->s_name; } - #endif //! Check for symbol and get string static const char *GetAString(const t_symbol *s,const char *def = NULL) { return s?GetString(s):def; } --- 389,396 ---- *************** *** 413,428 **** // there are some more comparison functions for t_atom types outside the class
- #if FLEXT_SYS == FLEXT_SYS_JMAX - //! Set atom from another atom - static int GetType(const t_atom &a); // ** TODO ** - - //! Check whether the atom is nothing - static bool IsNothing(const t_atom &a) { return fts_is_a(&a,fts_void_class); } - //! Set the atom to represent nothing - static void SetNothing(t_atom &a) { fts_set_void(&a); } - - //! Check whether the atom is a float - static bool IsFloat(const t_atom &a) { return fts_is_a(&a,fts_float_class); } - #else //! Set atom from another atom static int GetType(const t_atom &a) { return a.a_type; } --- 405,408 ---- *************** *** 435,452 **** //! Check whether the atom is a float static bool IsFloat(const t_atom &a) { return a.a_type == A_FLOAT; } - #endif
//! Check whether the atom can be represented as a float static bool CanbeFloat(const t_atom &a) { return IsFloat(a) || IsInt(a); }
- #if FLEXT_SYS == FLEXT_SYS_JMAX - //! Access the float value (without type check) - static float GetFloat(const t_atom &a) { return fts_get_float(&a); } - //! Set the atom to represent a float - static void SetFloat(t_atom &a,float v) { fts_set_float(&a,v); } - - //! Check whether the atom is a symbol - static bool IsSymbol(const t_atom &a) { return fts_is_a(&a,fts_symbol_class); } - #else //! Access the float value (without type check) static float GetFloat(const t_atom &a) { return a.a_w.w_float; } --- 415,422 ---- *************** *** 456,460 **** //! Check whether the atom is a symbol static bool IsSymbol(const t_atom &a) { return a.a_type == A_SYMBOL; } - #endif
#if FLEXT_SYS == FLEXT_SYS_PD --- 426,429 ---- *************** *** 468,476 **** //! Set the atom to represent a symbol static void SetSymbol(t_atom &a,const t_symbol *s) { a.a_type = A_SYMBOL; a.a_w.w_sym = const_cast<t_symbol *>(s); } - #elif FLEXT_SYS == FLEXT_SYS_JMAX - //! Access the symbol value (without type check) - static t_symbol *GetSymbol(const t_atom &a); // ** TODO ** - //! Set the atom to represent a symbol - static void SetSymbol(t_atom &a,const t_symbol *s) { fts_set_symbol(&a,s); } #else #error --- 437,440 ---- *************** *** 540,566 **** //! Set the atom to represent a pointer static void SetPointer(t_atom &a,void *p) { SetInt(a,(int)p); } - #elif FLEXT_SYS == FLEXT_SYS_JMAX - //! Check for a float and get its value - static float GetAFloat(const t_atom &a,float def = 0) { return IsFloat(a)?GetFloat(a):(IsInt(a)?GetInt(a):def); } - - //! Check whether the atom is an int - static bool IsInt(const t_atom &a) { return fts_is_a(&a,fts_int_class); } - //! Access the integer value (without type check) - static int GetInt(const t_atom &a) { return fts_get_int(&a); } - //! Check for an integer and get its value - static int GetAInt(const t_atom &a,int def = 0) { return IsInt(a)?GetInt(a):(IsFloat(a)?(int)GetFloat(a):def); } - //! Set the atom to represent an integer - static void SetInt(t_atom &a,int v) { fts_set_int(&a,v); } - - //! Check whether the atom strictly is a pointer - static bool IsPointer(const t_atom &a) { return fts_is_a(&a,fts_pointer_class); } - //! Check whether the atom can be a pointer - static bool CanbePointer(const t_atom &a) { return IsPointer(a); } - //! Access the pointer value (without type check) - static void *GetPointer(const t_atom &a) { return fts_get_pointer(&a); } - //! Check for a pointer and get its value - static void *GetAPointer(const t_atom &a,void *def = NULL) { return IsPointer(a)?GetPointer(a):def; } - //! Set the atom to represent a pointer - static void SetPointer(t_atom &a,void *p) { fts_set_pointer(&a,p); } #else #error "Platform not supported" --- 504,507 ---- *************** *** 711,721 **** public: explicit AtomAnything(): hdr(NULL) {} ! #if FLEXT_SYS != FLEXT_SYS_JMAX ! //! Construct anything explicit AtomAnything(const t_symbol *h,int argc = 0,const t_atom *argv = NULL) : AtomList(argc,argv),hdr(h?h:sym__) {} ! #endif ! //! Construct anything explicit AtomAnything(const char *h,int argc = 0,const t_atom *argv = NULL) : AtomList(argc,argv),hdr(MakeSymbol(h)) --- 652,662 ---- public: explicit AtomAnything(): hdr(NULL) {} ! ! //! Construct anything explicit AtomAnything(const t_symbol *h,int argc = 0,const t_atom *argv = NULL) : AtomList(argc,argv),hdr(h?h:sym__) {} ! ! //! Construct anything explicit AtomAnything(const char *h,int argc = 0,const t_atom *argv = NULL) : AtomList(argc,argv),hdr(MakeSymbol(h))