MappedType for unique_ptr

Nyall Dawson nyall.dawson at gmail.com
Wed Nov 20 04:57:06 GMT 2024


Hi list,

I'm wondering if any one has had any luck in creating a MappedType to
handle unique_ptr objects.

I've been experimenting with the following implementation, which seems to
work well for converting from unique_ptrs to Python owned objects. But I
can't find any way to implement the ConvertToTypeCode so that I can wrap
functions which have unique_ptr arguments.

I'm really hoping to modernize some API and move away from raw pointers,
but this is a stumbling block...

template <TYPE>
%MappedType std::unique_ptr< TYPE >
/NoRelease,AllowNone,TypeHint="Optional[TYPE]",TypeHintValue="TYPE"/
{
%TypeHeaderCode
#include <memory>
%End

%ConvertFromTypeCode
  const sipTypeDef *sip_type = sipFindType("TYPE*");
  return sipConvertFromNewType(sipCpp->release(), sip_type, NULL);
%End

%ConvertToTypeCode
  // only one way for now...
  return 0;
%End
};


Thanks,
Nyall
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20241120/10d9555e/attachment.htm>


More information about the PyQt mailing list