[C++-sig] Deleting the C++ part of a Boost.Python exposed Python object from C++
Lucy Devlin
lucy.devlin at hotmail.co.uk
Mon May 14 14:14:43 CEST 2007
Hi Everyone,Apologies for the verbose subject/title :-pI am very new to Boost.Python so I am still finding my feet...I've spent a couple of days looking at a problem that I just can't figure out how to solve. What look like similar problems and solutions don't appear to suit my needs, so if someone can point me in the right direction I would be very grateful.I'm working on interfacing with a C++ application for which the source code should not be affected (if possible) and the following situation seems like a reasonable pattern of behaviour, but I can't see how to wrap it with Boost.Python. Look at the following C++ code snippet...ProcessX* process = new ProcessX;ProcessManager* manager = ...; // Get the process managermanager->addProcess(process);if (!manager->isValid()){ // Prompt for user input and modify the process // Note that process is still accessible at this point process->doSomething();}// The manager has ownership of process which
// will be deleted by the manager after execution
manager->executeProcesses();Now, I was hoping to find a way to wrap the C++ classes involved (ProcessX and ProcessManager) such that a python ProcessX instance wraps a C++ ProcessX instance and knows when the C++ instance is deleted. Such as...ProcessX process = myapi.ProcessX()ProcessManager manager = ...# Get the process managermanager.addProcess(process);if not manager.isValid(): # User input, etc process.doSomething() # process instance is still validmanager.executeProcesses()try: process.doSomething() # The wrapped C++ object was deletedexcept DeleteCPPException: print "Exception raised" # And rightly so!I don't really need the Python process instance to endure after the deletion of its C++ counterpart but I need to transfer ownership to the process manager and maintain temporary access to the Python instance in order to doSomething.Any suggestions? Reading material? Good advice?I apologise if this has come up a few times before! I would expect it to have but didn't find anything in the archives.Many thanks in advance,L
_________________________________________________________________
Try Live.com: where your online world comes together - with news, sports, weather, and much more.
http://www.live.com/getstarted
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070514/25f0b79e/attachment.htm>
More information about the Cplusplus-sig
mailing list