On Tue, Jun 10, 2008 at 6:21 PM, Vincent Ferries
<vin...@gm...> wrote:
> I'll try to be more precise.
Now you are talking :-)
> Py++ generate the file dataBase.pypp.cpp two times, one for the class
> ::postLib::generic::dataBase and another for the class
> ::postLib::nastran::dataBase for example.
> The second declaration remove the first one and I'm only able to call
> the second one.
> So, when I instanciate one class in my python code, I don't have
> access to the superclass methods, nore the other classes of the same
> name. The only one which is recognized is the last defined.
>
> This problem doesn't appear in C++ code cause they are in different namespaces.
> But in python, they are in the same module and the declarations in the
> wrapper have superposed, so that there is only one instead of two or
> more.
>
> The solutions I imagine are to generate many python modules or to
> rename the classes so that they doesn't destroy themselves.
> I could for example rename them NastranDataBase and GenericDataBase to
> be called in python code for example, or use generic.dataBase or
> nastran.dataBase in my python code (using modules).
> I remember I've seen class name redefinition somewhere in py++ but I'm
> searching for some hours and doesn't find it anymore...
Here is solution for you:
mb = module_builder_t()
for cls in mb.classes():
#find out all classes with the same name
other_classes = mb.classes( cls.name )
other_classes = filter( lambda other_cls: not other_cls is cls )
for other_cls in other_classes:
#use parent name to mangle the final name of the class
#You can implement any logic you want here
other_cls.rename( other_cls.parent.name + '_' + other_cls.name )
You also can do this for all classes - add namespace name to the class name.
Another solution could be to create module per namespace + one module
that will contain common stuff. If you will decide to go with this
approach be sure to read this:
http://language-binding.net/pyplusplus/documentation/multi_module_development.html
HTH
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
|