On 10/11/06, Matthias Baas <ba...@ir...> wrote:
> Allen Bierbaum wrote:
> > Does anyone have any code that "automatically" creates a __str__
> > operator for a class if it has an ostream op<< that can write it out in C++?
>
> For the Maya bindings I manually create __str__ methods and use cdef to
> assign them to the classes (luckily I don't need such a method for every
> class). I don't remember the details but I had some problems when I
> tried to wrap the << operator directly.
>
> As to a fully automatic solution, isn't one of the problems that Py++
> doesn't take friend functions into account? (or does it meanwhile?)
I am not sure whether GCC-XML reports friendship or not. Py++ do take into
account free operators. It injects them directly into the class. Take a look on
creator_t._adopt_free_operator method.
For next release I plan to add "add_method" to the decl_wrappers.class_t.
And an algorithm that will find all functions, that could be exposed as methods.
For example:
struct data{
X x;
Y y;
};
std::auto_ptr< data > create();
could be added as "init" method
void initialize( data& )
could be added as new method
User will be able to write in Python:
d = data();
d.initialize()
This feature + FT will make Py++ to handle C code much better than now.
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
|