Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Singleton.h « mert - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: df1386650140dfa639e025cbb7ad721f36154919 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef MERT_SINGLETON_H_
#define MERT_SINGLETON_H_

#include <cstdlib>

namespace MosesTuning
{


// 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() {
    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_