Just return an Item
instance from your getItem(int index)
function. Ohterwise you'll have to overload the functions in order to receive both arguments types (shared_ptr
and Item
references)
Good way to dereference boost::shared_ptr in swig interface
Domanda
Is there a good, automated way to allow me to pass shared_ptr
's into functions that expect references in a SWIG interface?
I have a library that provides functions like:
// Module message
typedef boost::shared_ptr< Item > ItemPtr;
class Message{
public:
ItemPtr getItem( int index) ...
...
};
And then another library that uses them:
// Module client
class Client{
public:
void processItem( const Item& item );
}
These are in separate modules.
Obviously, I want to do something like:
>>> item=message.getItem(4)
>>> client.processItem( item )
in python,
but the types do not line up, the item
is a shared_ptr
while the function expects a reference.
So far my solution is to override the functions in the interface file
%extend client {
void processItem( ItemPtr ptr){
$self->processItem( *ptr);
}
}
Is there an approach where where I can avoid having to duplicate all of the interface functions that expect a reference, but where I'll have shared_ptr
's?
Soluzione
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow