[PyKDE] SIP: adding code to methods?
Giovanni Bajo
rasky at develer.com
Tue Mar 21 14:22:55 GMT 2006
Hello,
I'm wrapping a C++ class which is defined like this:
class Foo
{
public:
[ many methods that can fail...]
int Error();
};
The idea is that instead of returning error codes, the C++ methods silenty
succeed, and whenever the client sees fit, he can check Error() to see if
there were errors. What I wanted to do is to generate some code in the SIP
module so that Error() is automatically called after each method invokation,
and if it returns non-zero, a Python exception is raised.
I don't know how to do this in SIP. In details:
- I was thinking of defining a common utility function with %TypeCode, and
then calling it for each method. How can I define C++ code which is executed
after the method invokation? I don't want to use %MethodCode because I don't
want to rewrite the method invokation code itself, since the default is
perfectly fine.
- How can I make my module export a custom Python exception class (the
equivalent of "class MyException(Exception): pass") which has no match in
the C++ code?
- Should I use the %Exception support instead? If so, how? The documentation
for exception support is sparse at best.
Thanks
--
Giovanni Bajo
More information about the PyQt
mailing list