OSDN Git Service

ReadMe更新
[gefu/Gefu.git] / singleton.hpp
1 #ifndef SINGLETON_HPP\r
2 #define SINGLETON_HPP\r
3 \r
4 #include <memory>\r
5 \r
6 ///\r
7 /// シングルトンパターンの基底クラス\r
8 ///\r
9 template <class T>\r
10 class Singleton\r
11 {\r
12 public:\r
13     static T& instance() {\r
14         static pointer_type instance(createInstance());\r
15 \r
16         return getReference(instance);\r
17     }\r
18 \r
19 protected:\r
20     Singleton() {\r
21     }\r
22 \r
23 private:\r
24     typedef std::auto_ptr<T> pointer_type;\r
25 \r
26     static T* createInstance() { return new T(); }\r
27     static T& getReference(const pointer_type &p) { return *p; }\r
28 \r
29     explicit Singleton(const Singleton&);\r
30     Singleton& operator=(const Singleton&);\r
31 };\r
32 \r
33 #endif // SINGLETON_HPP\r