[Gridflow-cvs] [svn] commit: r4387 - /trunk/gridflow.h

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Sun Oct 25 09:24:57 EDT 2009


Author: matju
Date: Sun Oct 25 09:24:53 2009
New Revision: 4387

Log:
summarise and tabulate the casts from t_atom2 to various types

Modified:
    trunk/gridflow.h

Modified: trunk/gridflow.h
==============================================================================
--- trunk/gridflow.h (original)
+++ trunk/gridflow.h Sun Oct 25 09:24:53 2009
@@ -237,56 +237,26 @@
 struct t_atom2 : t_atom {
 	bool operator == (t_symbol *b) {return this->a_type==A_SYMBOL && this->a_symbol==b;}
 	bool operator != (t_symbol *b) {return !(*this==b);}
-	operator float32 () const {
-		if (a_type!=A_FLOAT) RAISE("expected float");
-		return a_float;}
-	operator bool () const {float f = round(float32(*this));
-		if (f<0 || f>=2) RAISE("value %f is out of range",f);
-		return (bool)f;}
-	operator uint8 () const {float f = round(float32(*this));
-		if (f<0 || f>=0x100) RAISE("value %f is out of range",f);
-		return (uint8)f;}
-	operator int16 () const {float f = round(float32(*this));
-		if (f<-0x8000 || f>=0x8000) RAISE("value %f is out of range",f);
-		return (int16)f;}
-	operator uint16 () const {float f = round(float32(*this));
-		if (f<0 || f>=0x10000) RAISE("value %f is out of range",f);
-		return (uint16)f;}
-	operator int32 () const {float f = round(float32(*this));
-		if (f<-0x80000000LL || f>=0x80000000LL) RAISE("value %f is out of range",f);
-		return (int32)f;}
-	operator uint32 () const {float f = round(float32(*this));
-		if (f<0 || f>=0x100000000LL) RAISE("value %f is out of range",f);
-		return (uint32)f;}
-	operator long () const {
-		return sizeof(long)==sizeof(int32) ? (int32)*this : (int64)*this;}
-	operator uint64 () const {
-		if (a_type!=A_FLOAT) RAISE("expected float");
-		return (uint64)round(a_float);}
-	operator int64 () const {
-		if (a_type!=A_FLOAT) RAISE("expected float");
-		return (int64)round(a_float);}
-	operator float64 () const {
-		if (a_type!=A_FLOAT) RAISE("expected float");
-		return a_float;}
-	operator t_symbol * () const {
-		if (a_type!=A_SYMBOL) RAISE("expected symbol");
- 		return a_symbol;}
-	operator std::string () const {
-		if (a_type!=A_SYMBOL) RAISE("expected symbol");
-		return std::string(a_symbol->s_name);}
-	operator void * () const {
-		if (a_type!=A_POINTER) RAISE("expected pointer");
- 		return a_gpointer;}
-	operator t_binbuf * () const {
-		if (a_type!=A_LIST) RAISE("expected nested list");
- 		return (t_binbuf *)a_gpointer;}
-	operator Grid * () const {
-		if (a_type!=A_GRID) RAISE("expected grid");
- 		return (Grid *)a_gpointer;}
-	operator GridOutlet * () const {
-		if (a_type!=A_GRIDOUT) RAISE("expected grid outlet");
- 		return (GridOutlet *)a_gpointer;}
+	operator float32 () const {if (a_type!=A_FLOAT) RAISE("expected float"); return a_float;}
+#define FFF float f = round(float32(*this));
+	operator   bool () const {FFF; if (f<0 || f>=2)                        RAISE("value %f is out of range",f); return (bool)f;}
+	operator  uint8 () const {FFF; if (f<0 || f>=0x100)                    RAISE("value %f is out of range",f); return (uint8)f;}
+	operator  int16 () const {FFF; if (f<-0x8000 || f>=0x8000)             RAISE("value %f is out of range",f); return (int16)f;}
+	operator uint16 () const {FFF; if (f<0 || f>=0x10000)                  RAISE("value %f is out of range",f); return (uint16)f;}
+	operator  int32 () const {FFF; if (f<-0x80000000LL || f>=0x80000000LL) RAISE("value %f is out of range",f); return (int32)f;}
+	operator uint32 () const {FFF; if (f<0 || f>=0x100000000LL)            RAISE("value %f is out of range",f); return (uint32)f;}
+#undef FFF
+	operator long () const {return sizeof(long)==sizeof(int32) ? (int32)*this : (int64)*this;}
+	operator  uint64 () const {if (a_type!=A_FLOAT) RAISE("expected float"); return (uint64)round(a_float);}
+	operator   int64 () const {if (a_type!=A_FLOAT) RAISE("expected float"); return  (int64)round(a_float);}
+	operator float64 () const {if (a_type!=A_FLOAT) RAISE("expected float"); return               a_float ;}
+
+	operator std::string  () const {if (a_type!=A_SYMBOL)  RAISE("expected symbol");      return std::string(a_symbol->s_name);}
+	operator t_symbol   * () const {if (a_type!=A_SYMBOL)  RAISE("expected symbol");      return             a_symbol         ;}
+	operator void       * () const {if (a_type!=A_POINTER) RAISE("expected pointer");     return               a_gpointer;}
+	operator t_binbuf   * () const {if (a_type!=A_LIST)    RAISE("expected nested list"); return   (t_binbuf *)a_gpointer;}
+	operator Grid       * () const {if (a_type!=A_GRID)    RAISE("expected grid");        return       (Grid *)a_gpointer;}
+	operator GridOutlet * () const {if (a_type!=A_GRIDOUT) RAISE("expected grid outlet"); return (GridOutlet *)a_gpointer;}
 };
 
 template <class T> T convert(const t_atom &x, T *foo) {const t_atom2 *xx = (const t_atom2 *)&x; return (T)*xx;}



More information about the Gridflow-cvs mailing list