Re: [pygccxml-development] How to manage wrapper classes?
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2006-03-27 08:31:20
|
On 3/27/06, Matthias Baas <ba...@ir...> wrote: > Roman Yakovenko wrote: > > First of all I think you should be able to create custom call policies. > > Take a look on this link: > > http://boost.org/libs/python/doc/v2/CallPolicies.html#CallPolicies-conc= ept > > > > May be, this will be enough, I am not sure. > > Interesting idea. From reading the above page I couldn't say if it is > possible or not. precall() and postcall() are supposed to manage Python > tuples which might indicate that they cannot access the original > arguments....? Well, anyway, I posted a message to the c++-sig list, > let's see what the "experts" have to say about this. > > >> So how should that be accomplished? > > > > There are 2 other ways to solve this problem. > > 1. Create small wrappers in Python. I do not know exactly how it should= be done. > > But, I feel that this is the right way to go. I hope some days > > pyplusplus will have > > 3'rd tree - Python code creators ( they will generate Python code )= . > > I have also thought about that and I might even get away with this for > the Maya SDK, but in general, I think the problem would be that those > Python wrappers would only be active when the object was created on the > Python side and not on the C++ side. > > > 2. Create small wrapper in C++, in the way you did it. Just put that de= claration > > in some namespace and add it to using add_code functions. > > But as I don't want to create the wrappers manually, how could I add > wrappers that I generate automatically to the generated source files > (not the main file)? You don't have to create them manually. pygccxml is your friend. You can find those functions and generate 2 files: header and source with wrappers for them. You just build your own small code generator. > > Using this > > approach you should be carefull. There are so many cases, while exp= orting > > some function to Python. By the way, do we talk about pure virtual > > functions or overloaded ones? > > What do you mean? The functions are not pure virtual, they are already > implemented in the Maya SDK and I only need to access them. They are > neither overloaded.... maybe I didn't understand the actual question...? If you would deal with pure virtual or overloaded function the solution would be much complex. > >> (and how can it be guaranteed that > >> the user's wrapper code doesn't interfere with the wrapper code that > >> might already get generated by pyplusplus?) > > > > 1. Do you still want to expose functions that returns, take by > > reference MStatus object? > > Uhm, yes? (that's what my mail was about...?) Sorry, I meant whether you want to expose original functions and wrappers, or you want to expose only wrappers? > > If the answer is not then we can add replace_code function to decl_wrap= per_t > > class. Then pyplusplus will generate that code. > > What code would replace_code() replace? pyplusplus generates code from declaration, right. We could add next feature: instead of creating code from declaration it will generate code provided by user. Example: instead of doing next steps my_class =3D mb.class_( 'X' ) mstatus_funcs =3D my_class.member_functions( all functions that has MStatus= ) for func in mstatus_funcs: func.exclude() my_class.add_code( wrapper function reference ) You would write something like: my_class =3D mb.class_( 'X' ) mstatus_funcs =3D my_class.member_functions( all functions that has MStatus= ) for func in mstatus_funcs: func.replace_code( wrapper function reference ) This approach has few advances over first one. I hope now I was clear. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |