2009/9/5 Martin Beckett <m...@mgbeckett.com>: > [quote="Paul Martz"]If you can (obviously) change your code to understand > instances of your new custom class, then I don't understand why you can't > change your code to understand instances of ref_ptrs to your new custom > class. Please explain this restriction further. > I have a complicated navigation library with a few objects representing a > position fix, GPS location, range+bearing observation etc. This library > works ! > > I want to re-use this in an OSG app. So I have written an adapter class where > a position is now represented underneath by a PAT (which can be used directly > in my OSG scene) but has the same name and implements the same set/get > position operations as the existing position class. > > But since it is ultimately derived from Referenced it has a virtual dtor, > cannot be create on the stack and cannot be copied with '=' > > I can make the dtor public, but the more complicated part is implementing the > copy operator - since it has to handle copying all the parent class of PAT. > > The alternative of having a bunch of interface functions to copy parameters > to/from the scenegraph nodes into existing 'position' objects seemed a poor > design. > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=17084#17084 > > > > > > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >
Hi Martin, pimpl idiom may help you. That means you won't derive publicly from PositionAttitudeTransform but have pointer to its implementation. This is sometimes called a "has-a" relationship, rather than "is-a" relationship. You may expose the same function interface with PositionAttitudeTransform to outside world. Your methods will call PAT's methods. class MyAdapter { osg::ref_ptr<osg::PositionAttitudeTransform> m_sppat; public: MyAdapter() throw(std::bad_alloc) : m_sppat(new osg::PositionAttitudeTransform) { } // Transform methods inline void setReferenceFrame(osg::ReferenceFrame rf) { m_sppat->setReferenceFrame(rf); } ... // PositionAttitudeTransform methods inline void setPivotPoint(const osg::Vec3d& pivot) { m_sppat->setPivotPoint(pivot); } .. }; you may need to implement all methods you need. I don't think you will need all public methods available in a PositionAttitudeTransform (including those are inherited). I didn't compile it but something like that should work. Does this help you? The constructor may throw. try { MyAdapter adapter; // call your library function } // PAT dies here catch (std::bad_alloc&) { // out of memory } Ismail _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org