Re: [osg-users] singleton instane

2013-10-18 Thread Ulrich Hertlein
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Sajjadul, On 13/10/2013 1:12, Sajjadul Islam wrote: > Thanks for the suggestion of the singleton design . I tried to design a > template base > class as follows : > > Code: ... template class Singleton { public: /** * Init the actual > singleton.

Re: [osg-users] singleton instane

2013-10-12 Thread Sajjadul Islam
Hi David, Thanks for the suggestion of the singleton design . I tried to design a template base class as follows : Code: namespace osgOpenCL { /** This class helps to build the singleton design pattern. Here you have full control over construction and deconstruction of the object. */

Re: [osg-users] singleton instane

2013-04-26 Thread David Callu
Hi Jan, This is not for reference counting but to not forget to delete the instance when program end. Regards David 2013/4/26 Jan Ciger > On 04/26/2013 11:18 AM, David Callu wrote: > >> oups beter like this, or with any other smart pointer >> >> MyClass & getInstance() >> { >> static osg:

Re: [osg-users] singleton instane

2013-04-26 Thread Jan Ciger
On 04/26/2013 11:18 AM, David Callu wrote: oups beter like this, or with any other smart pointer MyClass & getInstance() { static osg::ref_ptr myClass( new MyClass() ); return *myClass; } I wonder, why would you want a reference counting smart pointer for a singleton? There will be

Re: [osg-users] singleton instane

2013-04-26 Thread Jan Ciger
On Fri, Apr 26, 2013 at 11:18 AM, David Callu wrote: > oups beter like this, or with any other smart pointer > > MyClass & getInstance() > { > static osg::ref_ptr myClass( new MyClass() ); > return *myClass; > > } > > Do not forget to make all constructors private, though, otherwise you m

Re: [osg-users] singleton instane

2013-04-26 Thread David Callu
oups beter like this, or with any other smart pointer MyClass & getInstance() { static osg::ref_ptr myClass( new MyClass() ); return *myClass; } 2013/4/26 David Callu > Hi Sajjadul, > > There are nothing in OSG to do this, but make a class a singleton is > really straightforward. > >

Re: [osg-users] singleton instane

2013-04-26 Thread David Callu
Hi Sajjadul, There are nothing in OSG to do this, but make a class a singleton is really straightforward. - make constructor protected or private, - add a static getInstance function MyClass & getInstance() { static MyClass * myClass = new MyClass(); return *myClass; } then use it in yo

Re: [osg-users] singleton instane

2013-04-26 Thread Robert Osfield
Hi Sajjadul, There isn't any general signleton template or base class in the OSG, but it's doesn't take much code to implement so when we use singleton's they tend to get implemented locally in the code via a static access method. Getting singleton's to work cross platform with thread safety on in