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

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Tue Sep 21 20:11:35 EDT 2010


Author: matju
Date: Tue Sep 21 20:11:33 2010
New Revision: 6318

Log:
PtrGrid::next moved to Grid::next

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

Modified: trunk/src/classes1.cxx
==============================================================================
--- trunk/src/classes1.cxx (original)
+++ trunk/src/classes1.cxx Tue Sep 21 20:11:33 2010
@@ -375,7 +375,7 @@
 // takes the backstore of a grid and puts it back into place. a backstore
 // is a grid that is filled while the grid it would replace has not
 // finished being used.
-static void snap_backstore (PtrGrid &r) {if (r.next) {r=r.next.p; r.next=0;}}
+static void snap_backstore (PtrGrid &r) {if (r && r->next) {P<Grid> tmp=r->next; r=tmp;}}
 
 template <class T> void GridStore::compute_indices(T *v, long nc, long nd) {
 	for (int i=0; i<nc; i++) {
@@ -465,8 +465,8 @@
 	NumberTypeE nt = NumberTypeE_type_of(data);
 	if (!put_at) { // reassign
 		//!@#$ this was supposed to be inlets[0].sender i suppose... but it's not.
-		if (in.sender) r.next = new Grid(in.dim,nt);
-		else           r      = new Grid(in.dim,nt);
+		if (in.sender) r->next = new Grid(in.dim,nt);
+		else           r       = new Grid(in.dim,nt);
 		return;
 	}
 	// put_at ( ... )
@@ -497,7 +497,7 @@
 	cs = in.dim.prod(chunk);
 } GRID_FLOW {
 	if (!put_at) { // reassign
-		COPY(((T *)*(r.next ? r.next.p : &*r.p))+in.dex, data, n);
+		COPY(((T *)*(r->next ? r->next.p : &*r.p))+in.dex, data, n);
 		return;
 	}
 	// put_at (...)

Modified: trunk/src/gridflow.hxx
==============================================================================
--- trunk/src/gridflow.hxx (original)
+++ trunk/src/gridflow.hxx Tue Sep 21 20:11:33 2010
@@ -302,13 +302,12 @@
 //note: T <= CObject
 //used mostly as P<Grid>, P<BitPacking>
 extern char *short_backtrace (int start=3, int end=4);
-template <class T> class P {
+template <class T> struct P {
 public:
-
-//#define INCR if (p) {p->refcount++; if (p->refcount>1) post("refcount++ to %d at %s",p->refcount,short_backtrace());}
-//#define DECR if (p) {if (p->refcount>1) post("refcount-- from %d at %s",p->refcount,short_backtrace()); p->refcount--; if (!p->refcount) delete p;}
-#define INCR if (p) {p->refcount++;}
-#define DECR if (p) {p->refcount--; if (!p->refcount) delete p;}
+	//#define INCR if (p) {p->refcount++; if (p->refcount>1) post("refcount++ to %d at %s",p->refcount,short_backtrace());}
+	//#define DECR if (p) {if (p->refcount>1) post("refcount-- from %d at %s",p->refcount,short_backtrace()); p->refcount--; if (!p->refcount) delete p;}
+	#define INCR if (p) {p->refcount++;}
+	#define DECR if (p) {p->refcount--; if (!p->refcount) delete p;}
 	T *p;
 	P()               {p=0;}
 	P(T *_p)          {p=_p  ; INCR;}
@@ -323,8 +322,8 @@
 	T &operator *()   {return  *p;}
 	T *operator ->()  {return   p;}
 	operator T *() {return p;}
-//#undef INCR
-//#undef DECR
+	//#undef INCR
+	//#undef DECR
 };
 
 void gfmemcopy(uint8 *out, const uint8 *in, long n);
@@ -428,7 +427,7 @@
 EACH_NUMBER_TYPE(FOO)
 #undef FOO
 
-struct NumberType : CObject {
+struct NumberType {
 	const char *alias;
 	const char *name;
 	int size;
@@ -586,6 +585,7 @@
 	NumberTypeE nt;
 	void *data;
 	int state; /* 0:borrowing 1:owning -1:expired(TODO) */
+	P<Grid> next; /* used for reentrancy */
 	Grid(const Dim &dim=Dim(), NumberTypeE nt=int32_e, bool clear=false) {
 		data=0; state=1;
 		init(dim,nt);
@@ -635,10 +635,9 @@
 struct PtrGrid : public P<Grid> {
 	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()                  : P<Grid>(), dc(0) {}
+	PtrGrid(const PtrGrid &_p) : P<Grid>(), dc(0) {dc=_p.dc; p=_p.p; INCR;}
+	PtrGrid(         Grid *_p) : P<Grid>(), dc(0) {            p=_p; INCR;}
 	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;}
@@ -672,8 +671,8 @@
 // V is a PtrGrid instance-var
 #define GRID_INPUT(I,V) \
 	GRID_INLET(I) {V=new Grid(in.dim,NumberTypeE_type_of(data));} GRID_FLOW {COPY((T *)*(V)+in.dex,data,n);} GRID_FINISH
-#define GRID_INPUT2(I,V) GRID_INLET(I) {V.next = new Grid(in.dim,NumberTypeE_type_of(data));} \
-	GRID_FLOW {COPY(((T *)*(V.next?V.next.p:&*V.p))+in.dex,data,n);} GRID_FINISH
+#define GRID_INPUT2(I,V) GRID_INLET(I) {V->next = new Grid(in.dim,NumberTypeE_type_of(data));} \
+	GRID_FLOW {COPY(((T *)*(V->next?V->next.p:&*V.p))+in.dex,data,n);} GRID_FINISH
 
 typedef struct GridInlet GridInlet;
 typedef struct GridHandler {

Modified: trunk/src/opencv.cxx
==============================================================================
--- trunk/src/opencv.cxx (original)
+++ trunk/src/opencv.cxx Tue Sep 21 20:11:33 2010
@@ -202,7 +202,7 @@
 \end class {}
 
 // from flow_objects.c
-static void snap_backstore (PtrGrid &r) {if (r.next) {r=r.next.p; r.next=0;}}
+static void snap_backstore (PtrGrid &r) {if (r && r->next) {r=r->next.p; r->next=0;}}
 
 \class CvOp2 : CvOp1 {
 	PtrGrid r;



More information about the Gridflow-cvs mailing list