mosesdecoder/mert/Singleton.h
Tetsuo Kiso 8987fed667 Add thread unsafe Singleton class.
- Add Vocabulary factory and the unit test.
- Remove Scorer::ClearVocabulary().
2012-03-20 05:49:10 +09:00

34 lines
569 B
C++

#ifndef MERT_SINGLETON_H_
#define MERT_SINGLETON_H_
#include <cstdlib>
// thread *un*safe singleton.
// TODO: replace this with thread-safe singleton.
template <typename T>
class Singleton {
public:
static T* GetInstance() {
if (m_instance == NULL) {
m_instance = new T;
}
return m_instance;
}
static void Delete() {
if (m_instance) {
delete m_instance;
m_instance = NULL;
}
}
private:
Singleton();
static T* m_instance;
};
template <typename T>
T* Singleton<T>::m_instance = NULL;
#endif // MERT_SINGLETON_H_