mosesdecoder/mert/Singleton.h

39 lines
564 B
C
Raw Normal View History

#ifndef MERT_SINGLETON_H_
#define MERT_SINGLETON_H_
#include <cstdlib>
namespace MosesTuning
{
2013-05-29 21:16:15 +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:
static T* GetInstance() {
if (m_instance == NULL) {
m_instance = new T;
}
return m_instance;
}
static void Delete() {
delete m_instance;
m_instance = NULL;
}
2013-05-29 21:16:15 +04:00
private:
Singleton();
static T* m_instance;
};
template <typename T>
T* Singleton<T>::m_instance = NULL;
}
#endif // MERT_SINGLETON_H_