Wrapping C++ class with unnamed union
Hi, I am new to boost.python, so there may be a very simple answer to this. I would like to access the OGRE graphics library from python. But it has several classes with data like this: union { struct { Real r,g,b,a; }; Real val[4]; }; And I cannot access e.g. 'r' with a statement like: .def_readwrite("r", &Ogre::ColourValue::r) I'm assuming this is because there is an unnamed union and unnamed struct in between the class and the 'r'. I could write a new C++ class to wrap this one, and then use boost to wrap *that*. But if there is a simpler way, I would rather use it. Thanks for your advice, kvance
Kevin Vance wrote:
Hi,
I am new to boost.python, so there may be a very simple answer to this. I would like to access the OGRE graphics library from python. But it has several classes with data like this:
union { struct { Real r,g,b,a; }; Real val[4]; };
And I cannot access e.g. 'r' with a statement like:
..def_readwrite("r", &Ogre::ColourValue::r)
I'm assuming this is because there is an unnamed union and unnamed struct in between the class and the 'r'. I could write a new C++ class to wrap this one, and then use boost to wrap *that*. But if there is a simpler way, I would rather use it.
write getter and setter functions and use add_property: Real get_r(Ogre::ColourValue& c) {return c.r;} void set_r(Ogre::ColourValue& c, Real x) { c.r = x;} class_<Ogre::ColourValue>(....) .add_property("r", get_r, set_r) HTH, -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
On Wed, 15 Dec 2004 20:14:10 -0500, David Abrahams wrote:
union { struct { Real r,g,b,a; }; Real val[4]; };
<snip>
Real get_r(Ogre::ColourValue& c) {return c.r;} void set_r(Ogre::ColourValue& c, Real x) { c.r = x;}
class_<Ogre::ColourValue>(....) .add_property("r", get_r, set_r)
I know this is an old topic, but how would you do this when some of the union arguments are arrays, like, for example, the in6_addr structure: struct in6_addr { union { uint8_t u6_addr8[16]; uint16_t u6_addr16[8]; uint32_t u6_addr32[4]; } in6_u; #define s6_addr in6_u.u6_addr8 #define s6_addr16 in6_u.u6_addr16 #define s6_addr32 in6_u.u6_addr32 }; Thanks, -- PreZ :) Founder. The Neuromancy Society (http://www.neuromancy.net)
participants (3)
-
David Abrahams -
Kevin Vance -
Preston A. Elder