On Tuesday 11 July 2006 11:15 pm, Nigel Stewart wrote: > Hello all, > > I'm sure this issue has come up before, in one way or another. > > Our issue is to do with static const class member variables > such as: > > class A > { > public: > static const A zero; > static const A one; > ... > } > > ...In much the same manner as Qt provides QString::null. > > The problem we're having is that without a concept of constness > in Python, we have the risk of python-code changing A::zero, > A::one or QString::null. > > So, we were thinking of using %AccessCode (or something similar) > to provide copies to Python that can be changed, leaving the > C++ static const safe from modification.... > > class A > { > ... > static const A zero; > %AccessCode > return new A(A::zero); > %End > ... > > But then, it seems likely that these copies will be leaked, so > we seem to be stuck... > > Perhaps SIP could support a variable annotation that indicates > that a copy should be passed to Python, rather than a reference, > as an approximation to const in C++. > > (For a static member function we would be able to use > TransferBack to transfer ownership of the copy to Python) > > Perhaps more ideally, a const-flavored SIP wrapper object could > omit the non-const methods - resulting in a lighter-weight and > more general purpose solution to the problem.
Proper support for const has been on the TODO list for a long time - just haven't got around to it yet. Phil _______________________________________________ PyKDE mailing list PyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde