2012-03-20 00:49:10 +04:00
|
|
|
#ifndef MERT_SINGLETON_H_
|
|
|
|
#define MERT_SINGLETON_H_
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
2012-06-30 23:23:45 +04:00
|
|
|
namespace MosesTuning
|
|
|
|
{
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2012-06-30 23:23:45 +04:00
|
|
|
|
2012-03-20 00:49:10 +04:00
|
|
|
// thread *un*safe singleton.
|
|
|
|
// TODO: replace this with thread-safe singleton.
|
|
|
|
template <typename T>
|
2013-05-29 21:16:15 +04:00
|
|
|
class Singleton
|
|
|
|
{
|
|
|
|
public:
|
2012-03-20 00:49:10 +04:00
|
|
|
static T* GetInstance() {
|
|
|
|
if (m_instance == NULL) {
|
|
|
|
m_instance = new T;
|
|
|
|
}
|
|
|
|
return m_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Delete() {
|
2014-02-26 14:43:37 +04:00
|
|
|
delete m_instance;
|
|
|
|
m_instance = NULL;
|
2012-03-20 00:49:10 +04:00
|
|
|
}
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
private:
|
2012-03-20 00:49:10 +04:00
|
|
|
Singleton();
|
|
|
|
static T* m_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T* Singleton<T>::m_instance = NULL;
|
|
|
|
|
2012-06-30 23:23:45 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 00:49:10 +04:00
|
|
|
#endif // MERT_SINGLETON_H_
|