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.
*/
template<class T>
class Singleton
{
public:
/**
* Init the actual singleton.
* Must be called BEFORE the class is used, like this:
*/
static void init()
{
assert( singletonClass_.get() == NULL);
singletonClass_ = new T;
}
/**
* Get Pointer of the actual class
* @return Pointer of the actual class
*/
static T* getPtr()
{
assert( singletonClass_.get() != NULL);
return singletonClass_.release();
}
/**
* Get reference of the actual class
* @return reference of the actual class
*/
static T& getRef()
{
assert( singletonClass_.get() != NULL );
return *singletonClass_;
}
/**
* Has the actual class been inited?
*/
static bool isInited()
{
return (singletonClass_.valid());
}
private:
static osg::ref_ptr<T> singletonClass_;
};
/// init static pointers with 0
template<class T>
osg::ref_ptr<T> Singleton<T>::singletonClass_ = 0;
} // namespace
#endif // TGT_SINGLETON_H
But it crashes at the assertion. I tried without assertion , then debugger
simply exits at the point where i call:
Code:
//pull out the singleton context
//get the singleton context - which will be widely used in the rest of
this function definition
osgOpenCL::Context *cxt =
osgOpenCL::Singleton<osgOpenCL::Context>::getPtr();
Any idea how to get around these issues ?
Thanks,
Sajjadul
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=56762#56762
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org