RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
Singleton.h
1#ifndef SINGLETON_H
2#define SINGLETON_H
3
4namespace rxdock {
5
6template <class singleton_type> class Singleton {
7protected:
8 enum action { DESTROY, CREATE, GET };
9 static singleton_type *object(const action &a) {
10 static singleton_type *obj = nullptr;
11 switch (a) {
12 case DESTROY:
13 delete obj;
14 break;
15 case GET:
16 return obj;
17 case CREATE:
18 return (obj = new singleton_type);
19 }
20 return nullptr;
21 }
22
23public:
24 inline static singleton_type &instance() {
25 if (object(GET) != nullptr) {
26 return *object(GET);
27 } else {
28 return *object(CREATE);
29 }
30 }
31
32 virtual ~Singleton() { object(DESTROY); }
33
34protected:
35 Singleton() {}
36};
37
38} // namespace rxdock
39
40#endif
Definition Singleton.h:6