[C++-sig] Questions about doing advanced things with pyplusplus
Matthias Baas
baas at ira.uka.de
Thu Feb 16 18:47:56 CET 2006
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).
>> 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).
- Matthias -
More information about the Cplusplus-sig
mailing list