[C++-sig] Questions about doing advanced things with pyplusplus

Allen Bierbaum abierbaum at gmail.com
Fri Feb 17 16:44:10 CET 2006


On 2/16/06, Matthias Baas <baas at ira.uka.de> wrote:
> Roman Yakovenko wrote:
> >> q1: How do I rename a method, class, or namespace?
> > [...]
>   > x.alias = "new_name"
> >
> >> q2: How do I finalize a virtual class or method (so it doesn't get an
> >> polymorphic wrapper)?
> >
> > x.finalize()
> > [...]
> >
> >> q3: How do I set a call policy on a method?  (can you provide example
> >> code to do this directly)
> >
> > x.call_policies = code_creators.return_value_policy(
> > code_creators.return_by_value )
> > [...]
> >
> >> q4: How do I add support for smart ptrs and holders?  (like pyste's
> >> use_shared_ptr() and hold_with_shared_ptr())
> > [...]
> > x.held_type = smart_ptr #string that will be added/generated
>
> Isn't there sort of a duality between the declaration tree and the code
> creator tree? From what I understand at the moment, at least every
> exposed node in the declaration tree will have a corresponding node in
> the code creator tree (is this correct?).
> Then I think it would also be possible (and useful) to attach all of the
> above things to the declaration tree and pass them to the constructor of
> the corresponding code creator. This way I don't have to search for
> virtually the "same" node twice (once in the declaration tree and once
> in the code creator tree).

I agree and I am working on an extension to my proposed API that does
these things.  This is actually the reasons I asked all these
questions was because I wanted to know how to do it "manually" so I
could get the interface to do it more automatically from information
injected into the decl tree.

>  >> q5: How do I add methods?  (can you provide example code to do this)
>  >
>  > Take a look on py_date_time example, _customize_classes method.
>  > http://tinyurl.com/e44kh
>
> This is extremely low level, isn't it? Aren't you virtually bypassing
> pyplusplus if you directly set things like
>
>   def( "min", &%s::min, bp::default_call_policies() )
>
> pyplusplus then has no chance of knowing the semantics of this text.
> What if this definition should be involved in the reordering process? Is
> it really guaranteed that the Boost.Python namespace is always called
> "bp"? I couldn't use the standard mechanism for assigning doc strings
> (once there is one).
> I would prefer a solution where I can manipulate such a new method just
> as if it was part of the C++ class (hence the suggestion for an
> add_method() function).

What would you want the interface for add_method() to look like?  What
arguments should it take?  Do you think it should actually create a
new gccxml declaration or should it just pass information to the code
creators?

-Allen

>
> - Matthias -
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>



More information about the Cplusplus-sig mailing list