[Gridflow-cvs] [svn] commit: r3228 - in /trunk/base: flow_objects.c flow_objects.rb

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Mon Mar 17 20:23:42 EDT 2008


Author: matju
Date: Mon Mar 17 20:23:41 2008
New Revision: 3228

Log:
[#to_symbol] converted to C++

Modified:
    trunk/base/flow_objects.c
    trunk/base/flow_objects.rb

Modified: trunk/base/flow_objects.c
==============================================================================
--- trunk/base/flow_objects.c (original)
+++ trunk/base/flow_objects.c Mon Mar 17 20:23:41 2008
@@ -75,8 +75,7 @@
 //	if (d->n!=1) RAISE("expecting Dim[n], got %s",d->to_s());}
 
 //****************************************************************
-\class GridCast < GridObject
-struct GridCast : GridObject {
+\class GridCast < GridObject {
 	\attr NumberTypeE nt;
 	\decl void initialize (NumberTypeE nt);
 	\grin 0
@@ -99,8 +98,7 @@
 //****************************************************************
 //{ ?,Dim[B] -> Dim[*Cs] }
 // out0 nt to be specified explicitly
-\class GridImport < GridObject
-struct GridImport : GridObject {
+\class GridImport < GridObject {
 	\attr NumberTypeE cast;
 	\attr P<Dim> dim; // size of grids to send
 	PtrGrid dim_grid;
@@ -162,25 +160,38 @@
 //****************************************************************
 /*{ Dim[*As] -> ? }*/
 /* in0: integer nt */
-\class GridExport < GridObject
-struct GridExport : GridObject {
-	\grin 0
-};
-
-GRID_INLET(GridExport,0) {
-} GRID_FLOW {
-	Ruby a[] = { INT2NUM(0), INT2NUM(0) };
-	for (int i=0; i<n; i++) {a[1]=R(data[i]).r; send_out(COUNT(a),a);}
+\class GridToFloat < GridObject {
+	\grin 0
+};
+
+GRID_INLET(GridToFloat,0) {
+} GRID_FLOW {
+	for (int i=0; i<n; i++) outlet_float(bself->out[0],data[i]);
 } GRID_END
 \classinfo { install("#to_float",1,1); }
-\end class GridExport
+\end class GridToFloat
+
+\class GridToSymbol < GridObject {
+	\grin 0
+};
+
+GRID_INLET(GridToSymbol,0) {
+	in->set_chunk(0);
+} GRID_FLOW {
+	char c[n+1];
+	for (int i=0; i<n; i++) c[i]=(char)data[i];
+	c[n]=0;
+	outlet_symbol(bself->out[0],gensym(c));
+} GRID_END
+\classinfo { install("#to_symbol",1,1); }
+\end class GridToSymbol
+
 
 /* **************************************************************** */
 /*{ Dim[*As] -> ? }*/
 /* in0: integer nt */
 /* exporting floats may be crashy because [#export_list] doesn't handle GC */
-\class GridExportList < GridObject
-struct GridExportList : GridObject {
+\class GridExportList < GridObject {
 	Ruby /*Array*/ list;
 	int n;
 	\grin 0
@@ -215,8 +226,7 @@
 // in0: integer nt
 // in1: whatever nt
 // out0: same nt as in1
-\class GridStore < GridObject
-struct GridStore : GridObject {
+\class GridStore < GridObject {
 	PtrGrid r; // can't be \attr
 	PtrGrid put_at; // can't be //\attr
 	\attr Numop *op;
@@ -401,8 +411,7 @@
 //****************************************************************
 //{ Dim[*As]<T> -> Dim[*As]<T> } or
 //{ Dim[*As]<T>,Dim[*Bs]<T> -> Dim[*As]<T> }
-\class GridOp < GridObject
-struct GridOp : GridObject {
+\class GridOp < GridObject {
 	\attr Numop *op;
 	PtrGrid r;
 	\decl void initialize(Numop *op, Grid *r=0);
@@ -462,8 +471,7 @@
 \end class GridOp
 
 //****************************************************************
-\class GridFold < GridObject
-struct GridFold : GridObject {
+\class GridFold < GridObject {
 	\attr Numop *op;
 	\attr PtrGrid seed;
 	\decl void initialize (Numop *op);
@@ -509,8 +517,7 @@
 \classinfo { install("#fold",1,1); }
 \end class GridFold
 
-\class GridScan < GridObject
-struct GridScan : GridObject {
+\class GridScan < GridObject {
 	\attr Numop *op;
 	\attr PtrGrid seed;
 	\decl void initialize (Numop *op);
@@ -554,8 +561,7 @@
 // Seed   is a Dim[           *ss]<T>
 // result is a Dim[*si,   *sk,*ss]<T>
 // Currently *ss can only be = Dim[]
-\class GridInner < GridObject
-struct GridInner : GridObject {
+\class GridInner < GridObject {
 	\attr Numop *op;
 	\attr Numop *fold;
 	\attr PtrGrid seed;
@@ -703,8 +709,7 @@
 
 /* **************************************************************** */
 /*{ Dim[*As]<T>,Dim[*Bs]<T> -> Dim[*As,*Bs]<T> }*/
-\class GridOuter < GridObject
-struct GridOuter : GridObject {
+\class GridOuter < GridObject {
 	\attr Numop *op;
 	PtrGrid r;
 	\decl void initialize (Numop *op, Grid *r=0);
@@ -767,8 +772,7 @@
 //****************************************************************
 //{ Dim[]<T>,Dim[]<T>,Dim[]<T> -> Dim[A]<T> } or
 //{ Dim[B]<T>,Dim[B]<T>,Dim[B]<T> -> Dim[*As,B]<T> }
-\class GridFor < GridObject
-struct GridFor : GridObject {
+\class GridFor < GridObject {
 	\attr PtrGrid from;
 	\attr PtrGrid to;
 	\attr PtrGrid step;
@@ -853,8 +857,7 @@
 \end class GridFor
 
 //****************************************************************
-\class GridFinished < GridObject
-struct GridFinished : GridObject {
+\class GridFinished < GridObject {
 	\decl void initialize ();
 	\grin 0
 };
@@ -868,8 +871,7 @@
 \classinfo { install("#finished",1,1); }
 \end class GridFinished
 
-\class GridDim < GridObject
-struct GridDim : GridObject {
+\class GridDim < GridObject {
 	\decl void initialize ();
 	\grin 0
 };
@@ -882,8 +884,7 @@
 \classinfo { install("#dim",1,1); }
 \end class GridDim
 
-\class GridType < GridObject
-struct GridType : GridObject {
+\class GridType < GridObject {
 	\decl void initialize ();
 	\grin 0
 };
@@ -899,8 +900,7 @@
 
 //****************************************************************
 //{ Dim[*As]<T>,Dim[B] -> Dim[*Cs]<T> }
-\class GridRedim < GridObject
-struct GridRedim : GridObject {
+\class GridRedim < GridObject {
 	\attr P<Dim> dim;
 	PtrGrid dim_grid;
 	PtrGrid temp; // temp->dim is not of the same shape as dim
@@ -955,8 +955,7 @@
 \end class GridRedim
 
 //****************************************************************
-\class GridJoin < GridObject
-struct GridJoin : GridObject {
+\class GridJoin < GridObject {
 	\attr int which_dim;
 	PtrGrid r;
 	\grin 0
@@ -1032,8 +1031,7 @@
 \end class GridJoin
 
 //****************************************************************
-\class GridGrade < GridObject
-struct GridGrade : GridObject {
+\class GridGrade < GridObject {
 	\grin 0
 };
 
@@ -1071,8 +1069,7 @@
 //\class GridMedian < GridObject
 //****************************************************************
 
-\class GridTranspose < GridObject
-struct GridTranspose : GridObject {
+\class GridTranspose < GridObject {
 	\attr int dim1;
 	\attr int dim2;
 	int d1,d2,na,nb,nc,nd; // temporaries
@@ -1132,8 +1129,7 @@
 \end class GridTranspose
 
 //****************************************************************
-\class GridReverse < GridObject
-struct GridReverse : GridObject {
+\class GridReverse < GridObject {
 	\attr int dim1; // dimension to act upon
 	int d; // temporaries
 	\decl void initialize (int dim1=0);
@@ -1171,8 +1167,7 @@
 \end class GridReverse
 
 //****************************************************************
-\class GridCentroid < GridObject
-struct GridCentroid : GridObject {
+\class GridCentroid < GridObject {
 	\decl void initialize ();
 	\grin 0 int
 	int sumx,sumy,sum,y; // temporaries
@@ -1213,8 +1208,7 @@
 \end class GridCentroid
 
 //****************************************************************
-\class GridMoment < GridObject
-struct GridMoment : GridObject {
+\class GridMoment < GridObject {
 	\decl void initialize (int order=1);
 	\grin 0 int
 	\grin 1 int
@@ -1297,8 +1291,7 @@
 \end class GridMoment
 
 //****************************************************************
-\class GridLabeling < GridObject
-struct GridLabeling : GridObject {
+\class GridLabeling < GridObject {
 	\grin 0
 	\attr int form();
 	\attr int form_val;
@@ -1394,8 +1387,7 @@
 \end class GridLabeling
 
 //****************************************************************
-\class GridPerspective < GridObject
-struct GridPerspective : GridObject {
+\class GridPerspective < GridObject {
 	\attr int32 z;
 	\grin 0
 	\decl void initialize (int32 z=256);
@@ -1423,8 +1415,7 @@
 \end class GridPerspective
 
 //****************************************************************
-\class GridBorder < GridObject
-struct GridBorder : GridObject {
+\class GridBorder < GridObject {
 	\attr P<Dim> diml;
 	\attr P<Dim> dimr;
 	PtrGrid diml_grid;
@@ -1493,8 +1484,7 @@
 // entry in a compiled convolution kernel
 struct PlanEntry { long y,x; bool neutral; };
 
-\class GridConvolve < GridObject
-struct GridConvolve : GridObject {
+\class GridConvolve < GridObject {
 	\attr Numop *op;
 	\attr Numop *fold;
 	\attr PtrGrid seed;
@@ -1623,8 +1613,7 @@
 /* ---------------------------------------------------------------- */
 /* "#scale_by" does quick scaling of pictures by integer factors */
 /*{ Dim[A,B,3]<T> -> Dim[C,D,3]<T> }*/
-\class GridScaleBy < GridObject
-struct GridScaleBy : GridObject {
+\class GridScaleBy < GridObject {
 	\attr PtrGrid scale; // integer scale factor
 	int scaley;
 	int scalex;
@@ -1685,8 +1674,7 @@
 
 // ----------------------------------------------------------------
 //{ Dim[A,B,3]<T> -> Dim[C,D,3]<T> }
-\class GridDownscaleBy < GridObject
-struct GridDownscaleBy : GridObject {
+\class GridDownscaleBy < GridObject {
 	\attr PtrGrid scale;
 	\attr bool smoothly;
 	int scaley;
@@ -1776,8 +1764,7 @@
 \end class GridDownscaleBy
 
 //****************************************************************
-\class GridLayer < GridObject
-struct GridLayer : GridObject {
+\class GridLayer < GridObject {
 	PtrGrid r;
 	GridLayer() { r.constrain(expect_rgb_picture); }
 	\grin 0 int
@@ -1820,8 +1807,7 @@
 	if (d->n!=2 || d->get(1)!=2) RAISE("expecting Dim[n,2] polygon");
 }
 
-\class DrawPolygon < GridObject
-struct DrawPolygon : GridObject {
+\class DrawPolygon < GridObject {
 	\attr Numop *op;
 	\attr PtrGrid color;
 	\attr PtrGrid polygon;
@@ -1946,8 +1932,7 @@
 	if (d->v[0]!=2) RAISE("position dim 0 should have 2 elements, not %d", d->v[0]);
 }
 
-\class DrawImage < GridObject
-struct DrawImage : GridObject {
+\class DrawImage < GridObject {
 	\attr Numop *op;
 	\attr PtrGrid image;
 	\attr PtrGrid position;
@@ -2064,8 +2049,7 @@
 // Dim[*A],Dim[*B],Dim[C,size(A)-size(B)] -> Dim[*A]
 
 /* NOT FINISHED */
-\class GridDrawPoints < GridObject
-struct GridDrawPoints : GridObject {
+\class GridDrawPoints < GridObject {
 	\attr Numop *op;
 	\attr PtrGrid color;
 	\attr PtrGrid points;
@@ -2112,8 +2096,7 @@
 \end class GridDrawPoints
 
 //****************************************************************
-\class GridPolygonize < GridObject
-struct GridPolygonize : GridObject {
+\class GridPolygonize < GridObject {
 	\grin 0
 };
 
@@ -2128,8 +2111,7 @@
 \end class GridPolygonize
 
 //****************************************************************
-\class GridNoiseGateYuvs < GridObject
-struct GridNoiseGateYuvs : GridObject {
+\class GridNoiseGateYuvs < GridObject {
 	\grin 0
 	int thresh;
 	\decl void _1_float(int v);
@@ -2160,8 +2142,7 @@
 
 //****************************************************************
 
-\class GridPack < GridObject
-struct GridPack : GridObject {
+\class GridPack < GridObject {
 	int n;
 	PtrGrid a;
 	GridPack() : n(0xdeadbeef) {}
@@ -2201,8 +2182,7 @@
 \classinfo { install("#pack",1,1); }
 \end class GridPack
 
-\class GridUnpack < GridObject
-struct GridUnpack : GridObject {
+\class GridUnpack < GridObject {
 	int n;
 	\decl void initialize (int n=2);
 	\decl void initialize2 ();
@@ -2231,8 +2211,7 @@
 
 //****************************************************************
 
-\class ForEach < FObject
-struct ForEach : FObject {
+\class ForEach < FObject {
 	\decl void _0_list (...);
 };
 

Modified: trunk/base/flow_objects.rb
==============================================================================
--- trunk/base/flow_objects.rb (original)
+++ trunk/base/flow_objects.rb Mon Mar 17 20:23:41 2008
@@ -210,14 +210,6 @@
 	end
 }
 
-GridObject.subclass("#to_symbol",1,1) {
-	install_rgrid 0
-	def _0_rgrid_begin; @data="" end
-	def _0_rgrid_flow data; @data << data; end
-	def _0_rgrid_end
-		send_out 0, :symbol, @data.unpack("I*").pack("c*").intern
-	end
-}
 GridObject.subclass("unix_time",1,3) {
   install_rgrid 0
   def _0_bang



More information about the Gridflow-cvs mailing list