[C++-sig] Pyplusplus - anonymous union

Jan Langer jan at langernetz.de
Wed Aug 2 20:06:08 CEST 2006


Roman Yakovenko wrote:
> On 8/2/06, Jan Langer <jan at langernetz.de> wrote:
>>Roman Yakovenko wrote:
>>>>I'm using pyplusplus to generate python-bindings for a C API.
>>>
>>>mb = module_builder_t( ... )
>>>#The code in subversion does it for you
>>>mb.classes( name='' ).exclude()
>>>
>>>Next code is copied from Python-OGRE bindings:
>>>
>>>[...]
>>>
>>>This should work.
>>>
>>>P.S. You project is 3rd project that need this feature, may be this is a time
>>>to implement it :-)
>>
>>Thank you. Actually this behavior does not work like I want, but gave me
>>more insight into the workings of pyplusplus. I now use a different
>>strategy. First, I generate a union wrapper to give the anonymous union
>>a name. Then, I provide getter and setter functions for each union
>>member and getter/setter for the union itself. The access to the union
>>members and the union is then accomplished by the .add_property calls. I
>>paste the relevant boost.python code below. However, I omit the
>>pyplusplus code, but in case someone is interested I can send it, too.
> 
> [...]
>
> Cool! Can you post pyplusplus code? I will create a FAQ entry.

Hello Roman,
actually, I am not very happy with my code, because I probably do many
things not the right pyplusplus way and not even the right (safe) c++
way (see my other post today). Anyway, I attached the script and I
think I don't need to explain in further detail :-[. The std::memcpy
part of it works for this library, but it probably does not for other
more advanced libraries. In case it is relevant, I am trying to wrap the
FrameMaker FDK library.

The union_wrapper.hpp file basically just contains the following code:

template <typename Union>
struct union_wrapper
{
  typedef Union union_type;
  Union u;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: build.py
Type: application/x-python
Size: 9583 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060802/2ee3641e/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060802/2ee3641e/attachment.pgp>


More information about the Cplusplus-sig mailing list