[PyKDE] SmartPointer support
mail at fkollmann.de
mail at fkollmann.de
Tue May 9 11:50:13 BST 2006
A non-text attachment was scrubbed...
Name: not available
Type: text/rtf
Size: 65229 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20060509/6fd32f06/attachment.rtf
-------------- next part --------------
Hello there,
due the continous discussion about smart pointers I want to make an approach how an implementation might look like. The main point is that we do not want to have a smart pointer object at all in Python because it is not necessary - Python always uses smart pointer in some POV.
Of course this would require some new language features. Okay, generelly we have a class with two functions. One returning a smart pointer reference and the other simply a pointer:
%Import MySmartPointer.sip
class Test
{
public:
MyClass* GetSmartPointer() /SmartPointerReturned=MySmartPointer/;
MyClass* GetNoSmartPointer();
};
The same for function parameters:
%Import MySmartPointer.sip
class Test2
{
public:
void SetSmartPointer (MyClass* /SmartPointer=MySmartPointer/);
void SetNoSmartPointer (MyClass*);
};
And variables:
%Import MySmartPointer.sip
class Test3
{
public:
MyClass* smartPtr /SmartPointer=MySmartPointer/;
};
It might be usefull to be able to specify a default for modules (may be overwritten at any time):
%Import MySmartPointer.sip
%DefaultSmartPointer MySmartPointer
class Test
{
public:
MyClass* GetSmartPointer() /SmartPointerReturned/;
MyClass* GetNoSmartPointer();
};
class Test2
{
public:
void SetSmartPointer (MyClass* /SmartPointer/);
void SetNoSmartPointer (MyClass*);
};
class Test3
{
public:
MyClass* smartPtr /SmartPointer/;
};
Finally it is required to define a smart pointer:
%SmartPointer MySmartPointer
{
%CreateRefCode // optional; this is the default
/* arguments:
MySmartPointer* sipCppPtr
type = /in this case/ MyClass
MyClass* sipInnerPtr
*/
sipCppPtr = new MySmartCppPointer<type> (sipInnerPtr);
%End
%GetInnerRefCode // optional; this is the default
/* arguments:
MySmartPointer& sipCppRef
MyClass* sipInnerPtr
*/
sipInnerPtr = &*sipCppRef;
%End
%IncRefCode // required
/* arguments:
MySmartPointer& sipCppRef
*/
sipCppRef->AddRef();
%End
%DecRefCode // required
/* arguments:
MySmartPointer& sipCppRef
*/
sipCppRef->Release();
%End
};
What do you think of it? cu Felix
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20060509/6fd32f06/attachment.html
More information about the PyQt
mailing list