/**
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:
*/
staticvoid 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?
*/
staticbool 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;
I am getting error at the assertion points when i call to the class as follows: