[C++-sig] Indexing_suite when container is newed

Niall Douglas s_sourceforge at nedprod.com
Wed Oct 15 18:30:55 CEST 2003

Right, last error in the last file - everything else compiles! I have 
a method called lasso() in FXGLViewer which returns an array of 
FXGLObject pointers falling within the specified coordinates.

Unfortunately the list returned is malloced and if not freed after 
python is done with it would leak memory. My initial attempt was as 

static indexing::iterator_pair<FXGLObject **> 
FXGLViewer_lasso(FXGLViewer &c, FXint x1,FXint y1,FXint x2,FXint y2)
	typedef indexing::iterator_pair<FXGLObject **> IterPair;
	class_<IterPair>( "FXGLViewer_lassoIndirect", init<FXGLObject **, 
FXGLObject **>())
	FXGLObject **data=c.lasso(x1,y1,x2,y2);
	return IterPair(data, data+(1<<16));

However it would appear that setting a policy at the container_suite 
level sets it for the iterator_pair which isn't what I want. Anyway 
besides the list is malloced and not newed, though in fact I've 
replaced new and delete with my own versions which do call malloc.

What one would want is the ability to call a destructor when the 
iterator_pair is destroyed. Unfortunately I can't hack in a 
destructor because it gets lost in the downcast and I can't use 
auto_ptr because both of the iterators must be the same type (and the 
end of array is not a valid memory location). So I'm guessing it 
needs added support.

I'd imagine copy construction needs to be destructive so myBegin and 
myEnd would need to become mutable and one would need a user-
overridable destructor.

Or perhaps one could create a new custom type of return policy and 
set that instead?



-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 208 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20031015/e3033c03/attachment.pgp>

More information about the Cplusplus-sig mailing list