[Gridflow-cvs] [svn] commit: r6146 - in /trunk/src: classes1.cxx classes3.cxx gridflow.hxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Mon Aug 16 12:04:25 EDT 2010


Author: matju
Date: Mon Aug 16 12:04:23 2010
New Revision: 6146

Log:
successor to the DimConstraint feature : uses a macro and passes the nt

Modified:
    trunk/src/classes1.cxx
    trunk/src/classes3.cxx
    trunk/src/gridflow.hxx

Modified: trunk/src/classes1.cxx
==============================================================================
--- trunk/src/classes1.cxx (original)
+++ trunk/src/classes1.cxx Mon Aug 16 12:04:23 2010
@@ -52,10 +52,10 @@
 
 Numop *op_add, *op_sub, *op_mul, *op_div, *op_mod, *op_shl, *op_and, *op_put;
 
-static void   expect_dim_dim_list    (const Dim &d) {if (d.n!=1) RAISE("dimension list should be Dim[n], not %s",d.to_s());}
-//static void expect_min_one_dim     (const Dim &d) {if (d.n<1 ) RAISE("minimum 1 dimension");}
-static void   expect_max_one_dim     (const Dim &d) {if (d.n>1 ) RAISE("expecting Dim[] or Dim[n], got %s",d.to_s());}
-//static void expect_exactly_one_dim (const Dim &d) {if (d.n!=1) RAISE("expecting Dim[n], got %s",d.to_s());}
+static CONSTRAINT(expect_dim_dim_list) {if (d.n!=1) RAISE("dimension list should be Dim[n], not %s",d.to_s());}
+//static CONSTRAINT(expect_min_one_dim) {if (d.n<1 ) RAISE("minimum 1 dimension");}
+static CONSTRAINT(expect_max_one_dim) {if (d.n>1 ) RAISE("expecting Dim[] or Dim[n], got %s",d.to_s());}
+//static CONSTRAINT(expect_exactly_one_dim) {if (d.n!=1) RAISE("expecting Dim[n], got %s",d.to_s());}
 
 //****************************************************************
 \class GridCast : FObject {
@@ -342,9 +342,9 @@
 	PtrGrid r; // can't be \attr
 	PtrGrid put_at; // can't be //\attr
 	\attr Numop *op;
-	int32 *wdex ; // temporary buffer, copy of put_at
-	int32 *fromb;
-	int32 *to2  ;
+	int32 *wdex ; // temporary buffer, copy of put_at //! vector<>
+	int32 *fromb; //! vector<>
+	int32 *to2  ; //! vector<>
 	int lsd; // lsd = Last Same Dimension (for put_at)
 	int d; // goes with wdex
 	long cs; // chunksize used in put_at
@@ -851,7 +851,6 @@
 		this->to  =to;
 		this->step=step;
 	}
-	//\decl 0 set (Grid *l=0) {from=new Grid(argv[0]);}
 	\decl 0 set (Grid *l=0) {from=l;}
 	\decl 0 bang () {
 		SAME_TYPE(*from,to);

Modified: trunk/src/classes3.cxx
==============================================================================
--- trunk/src/classes3.cxx (original)
+++ trunk/src/classes3.cxx Mon Aug 16 12:04:23 2010
@@ -18,8 +18,8 @@
 	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
 #include "gridflow.hxx.fcs"
-static void expect_max_one_dim (const Dim &d) {if (d.n>1)  RAISE("expecting Dim[] or Dim[n], got %s",d.to_s());}
-static void     expect_one_dim (const Dim &d) {if (d.n!=1) RAISE("expecting Dim[n], got %s",d.to_s());}
+static CONSTRAINT(expect_max_one_dim) {if (d.n>1)  RAISE("expecting Dim[] or Dim[n], got %s",d.to_s());}
+static CONSTRAINT(expect_one_dim)     {if (d.n!=1) RAISE("expecting Dim[n], got %s",d.to_s());}
 // BAD HACK: GCC complains: unimplemented (--debug mode only) (i don't remember which GCC this was)
 #ifdef HAVE_DEBUG
 #define SCOPY(a,b,n) COPY(a,b,n)
@@ -348,7 +348,7 @@
 \end class {install("#centroid",1,3);}
 
 //****************************************************************
-static void expect_pair (const Dim &dim) {if (dim.prod()!=2) RAISE("expecting only two numbers. Dim(2)");}
+static CONSTRAINT(expect_pair) {if (d.prod()!=2) RAISE("expecting only two numbers. Dim(2)");}
 
 \class GridMoment : FObject {
 	\constructor (int order=1) {
@@ -579,14 +579,14 @@
 
 \end class {install("#border",3,1);}
 
-static void expect_picture (const Dim &d) {if (d.n!=3) RAISE("(height,width,chans) dimensions please");}
-static void expect_rgb_picture  (const Dim &d) {expect_picture(d); if (d[2]!=3) RAISE("(red,green,blue) channels please");}
-static void expect_rgba_picture (const Dim &d) {expect_picture(d); if (d[2]!=4) RAISE("(red,green,blue,alpha) channels please");}
+static CONSTRAINT(expect_picture) {if (d.n!=3) RAISE("(height,width,chans) dimensions please");}
+static CONSTRAINT(expect_rgb_picture)  {expect_picture(d,nt); if (d[2]!=3) RAISE("(red,green,blue) channels please");}
+static CONSTRAINT(expect_rgba_picture) {expect_picture(d,nt); if (d[2]!=4) RAISE("(red,green,blue,alpha) channels please");}
 
 //****************************************************************
 //{ Dim[A,B,*Cs]<T>,Dim[D,E]<T> -> Dim[A,B,*Cs]<T> }
 
-static void expect_convolution_matrix (const Dim &d) {
+static CONSTRAINT(expect_convolution_matrix) {
 	if (d.n!=2) RAISE("only exactly two dimensions allowed for now (got %d)",d.n);
 }
 
@@ -721,9 +721,9 @@
 /* "#scale_by" does quick scaling of pictures by integer factors */
 /*{ Dim[A,B,3]<T> -> Dim[C,D,3]<T> }*/
 
-static void expect_scale_factor (const Dim &dim) {
-	if (dim.n>1) RAISE("expecting no more than one dimension");
-	if (dim.prod()!=1 && dim.prod()!=2) RAISE("expecting only one or two numbers");
+static CONSTRAINT(expect_scale_factor) {
+	if (d.n>1) RAISE("expecting no more than one dimension");
+	if (d.prod()!=1 && d.prod()!=2) RAISE("expecting only one or two numbers");
 }
 
 \class GridScaleBy : FObject {
@@ -746,7 +746,7 @@
 
 GRID_INLET(0) {
 	Dim &a = in.dim;
-	expect_picture(a);
+	expect_picture(a,in.nt);
 	go=new GridOut(this,0,Dim(a[0]*scaley,a[1]*scalex,a[2]),in.nt);
 	in.set_chunk(1);
 } GRID_FLOW {
@@ -872,7 +872,7 @@
 GRID_INLET(0) {
 	SAME_TYPE(in,r);
 	Dim &a = in.dim;
-	expect_rgba_picture(a);
+	expect_rgba_picture(a,in.nt);
 	if (a[1]!=r->dim[1]) RAISE("same width please");
 	if (a[0]!=r->dim[0]) RAISE("same height please");
 	in.set_chunk(2);
@@ -899,7 +899,7 @@
 // pad1,pad2 only are there for 32-byte alignment
 struct Line {int32 y1,x1,y2,x2,x,m,ox,pad2;};
 
-static void expect_polygon (const Dim &d) {if (d.n!=2 || d[1]!=2) RAISE("expecting Dim[n,2] polygon");}
+static CONSTRAINT(expect_polygon) {if (d.n!=2 || d[1]!=2) RAISE("expecting Dim[n,2] polygon");}
 
 enum DrawMode {DRAW_FILL,DRAW_LINE,DRAW_POINT};
 enum OmitMode {OMIT_NONE,OMIT_LAST,OMIT_ODD};
@@ -1053,7 +1053,7 @@
 \end class {install("#draw_polygon",3,1); add_creator("@draw_polygon");}
 
 //****************************************************************
-static void expect_position(const Dim &d) {
+static CONSTRAINT(expect_position) {
 	if (d.n!=1) RAISE("position should have 1 dimension, not %d", d.n);
 	if (d[0]!=2) RAISE("position dim 0 should have 2 elements, not %d", d[0]);
 }
@@ -1304,7 +1304,7 @@
 };
 \end class {install("#rotatificator",2,1);}
 
-static void expect_min_one_dim (const Dim &d) {
+static CONSTRAINT(expect_min_one_dim) {
 	if (d.n<1) RAISE("expecting at least one dimension, got %s",d.to_s());}
 
 #define OP(x) op_dict[string(#x)]

Modified: trunk/src/gridflow.hxx
==============================================================================
--- trunk/src/gridflow.hxx (original)
+++ trunk/src/gridflow.hxx Mon Aug 16 12:04:23 2010
@@ -586,7 +586,8 @@
 		if (clear) CLEAR((char *)data,bytes());
 	}
 	Grid(const t_atom &x) {data=0; state=1; init_from_atom(x);}
-	Grid(int n, t_atom *a, NumberTypeE nt_=int32_e) {data=0; state=1; init_from_list(n,a,nt_);}
+	Grid(int n, t_atom2 *a, NumberTypeE nt_=int32_e) {data=0; state=1; init_from_list(n,a,nt_);}
+	Grid(int n, t_atom  *a, NumberTypeE nt_=int32_e) {data=0; state=1; init_from_list(n,a,nt_);}
 	template <class T> Grid(const Dim &dim, T *data) {
 		state=0; this->dim=dim;
 		this->nt=NumberTypeE_type_of((T *)0);
@@ -617,21 +618,21 @@
 };
 static inline Grid *convert (const t_atom &r, Grid **bogus) {return new Grid(r);}
 
-// DimConstraint interface:
-// return if d is acceptable
-// else RAISE with proper descriptive message
-typedef void (*DimConstraint)(const Dim &d);
+// GridConstraint interface: (only a GRID_BEGIN time constraint)
+// return if d and nt are acceptable, else RAISE with proper descriptive message
+#define CONSTRAINT(NAME) void NAME (const Dim &d, NumberTypeE nt)
+typedef CONSTRAINT((*GridConstraint));
 
 struct PtrGrid : public P<Grid> {
-	DimConstraint dc;
-	void constrain(DimConstraint dc_) { dc=dc_; }
+	GridConstraint dc;
+	void constrain(GridConstraint dc_) {dc=dc_;}
 	P<Grid> next;
 	PtrGrid()                  : P<Grid>(), dc(0), next(0) {}
 	PtrGrid(const PtrGrid &_p) : P<Grid>(), dc(0), next(0) {dc=_p.dc; p=_p.p; INCR;}
 	PtrGrid(         Grid *_p) : P<Grid>(), dc(0), next(0) {            p=_p; INCR;}
-	PtrGrid &operator =(  Grid *_p) {if(dc&&_p)dc(_p->dim); DECR; p=_p;   INCR; return *this;}
-	PtrGrid &operator =(P<Grid> _p) {if(dc&&_p)dc(_p->dim); DECR; p=_p.p; INCR; return *this;}
-	PtrGrid &operator =(PtrGrid _p) {if(dc&&_p)dc(_p->dim); DECR; p=_p.p; INCR; return *this;}
+	PtrGrid &operator =(  Grid *_p) {if(dc&&_p)dc(_p->dim,_p->nt); DECR; p=_p;   INCR; return *this;}
+	PtrGrid &operator =(P<Grid> _p) {if(dc&&_p)dc(_p->dim,_p->nt); DECR; p=_p.p; INCR; return *this;}
+	PtrGrid &operator =(PtrGrid _p) {if(dc&&_p)dc(_p->dim,_p->nt); DECR; p=_p.p; INCR; return *this;}
 };
 #undef INCR
 #undef DECR



More information about the Gridflow-cvs mailing list