Hi Martin, 2009/9/5 Martin Beckett <m...@mgbeckett.com>: > Thanks but not really - then I can't use the new class in the scene graph. > Yes, you can, can't you? Pass your objects to constructor. I wouldn't do it, but you want if you want to.
class MyAdapter { typedef osg::ref_ptr<osg::PAT> osg_pat_type; osg_pat_type m_sppat; public: // we'll you use explicit MyAdapter(osg_pat_type pat) : m_sppat(pat) { } explicit MyAdapter(PAT* pat) : m_sppat(pat) { } MyAdapter() : m_sppat(new osg::PAT) { } osg::PAT* release() { m_sppat.release(); } osg::ref_ptr<osg::PAT> GetPAT() /*const*/ { return m_sppat; } // if you want conversions, provide conversion operators... operator PAT*() { return m_sppat.get(); } }; Pass your object to constructor and call release before scope ends. You may automate this by adding a flag and checking that in destructor. e.g. const bool m_fShouldRelease; public: explicit MyAdapter(osg_pat_type pat) : m_sppat(pat), m_fShouldRelease(true) { } explicit MyAdapter(PAT* pat) : m_sppat(pat), m_fShouldRelease(true) { } MyAdapter() : m_sppat(new osg::PAT), m_fShouldRelease(false) { } ~MyAdapter() { if (m_fShouldRelease) release(); } > The idea was to have a 'location' object in the scenegraph which is a PAT as > far as OSG is concerned but has methods which reflect the interface I'm used > to and fit the needs of my problem domain. That I can do with an Adapter > derived class > > It looks like the only way is to have a set of converter functions. > Unfortunately the naming gets a bit complex because I have an osg::location > class and a my::location class with the same interface but different > internals. You can use namespace aliases, or, typedef your my::location to something else; it may help. namespace my = AdapterNS; typedef AdapterNS::location AdapterLocation; or namespace AdapterNS { typedef ::my::location AdapterLocation; } // use AdapterNS::AdapterLocation. > > I think this is one of those areas where C++ falls behind Java or C# > > Martin > How would you do it in C#? You can do a lot of strange-looking things in C++, which you can't do in a managed language, because run-time will not allow you (unless you explicitly express your intent is a non-verifiable code). > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=17086#17086 > > > > > > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org