diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-04-03 03:49:53 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-04-03 03:49:53 +0000 |
commit | f4c20290509d7ed3a8fd5304577e7a4cc0b9d974 (patch) | |
tree | 13cdf64f7cf134f397a7165b7a3fe0807e37026b /src/singleton.h | |
parent | 74d4c8cd27334fc7204d5a8773deb3d424565778 (diff) | |
download | libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.gz libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.bz2 libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.xz libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.zip |
Ok, no code is left in src, it's all in src/old. We'll gradually move code back
into src as it's fixed and re-org'd. This includes tests, which, I may write a
unit test system into libbu++ just to make my life easier.
Diffstat (limited to 'src/singleton.h')
-rw-r--r-- | src/singleton.h | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/src/singleton.h b/src/singleton.h deleted file mode 100644 index 47adbd5..0000000 --- a/src/singleton.h +++ /dev/null | |||
@@ -1,59 +0,0 @@ | |||
1 | #ifndef SINGLETON_H | ||
2 | #define SINGLETON_H | ||
3 | |||
4 | #include <stdio.h> | ||
5 | |||
6 | /** | ||
7 | * Provides singleton functionality in a modular sort of way. Make this the | ||
8 | * base class of any other class and you immediately gain singleton | ||
9 | * functionality. Be sure to make your constructor and various functions use | ||
10 | * intellegent scoping. Cleanup and instantiation are performed automatically | ||
11 | * for you at first use and program exit. There are two things that you must | ||
12 | * do when using this template, first is to inherit from it with the name of | ||
13 | * your class filling in for T and then make this class a friend of your class. | ||
14 | *@code | ||
15 | * // Making the Single Singleton: | ||
16 | * class Single : public Singleton<Single> | ||
17 | * { | ||
18 | * friend class Singleton<Single>; | ||
19 | * protected: | ||
20 | * Single(); | ||
21 | * ... | ||
22 | * }; | ||
23 | @endcode | ||
24 | * You can still add public functions and variables to your new Singleton child | ||
25 | * class, but your constructor should be protected (hence the need for the | ||
26 | * friend decleration). | ||
27 | *@author Mike Buland | ||
28 | */ | ||
29 | template <class T> | ||
30 | class Singleton | ||
31 | { | ||
32 | protected: | ||
33 | /** | ||
34 | * Private constructor. This constructor is empty but has a body so that | ||
35 | * you can make your own override of it. Be sure that you're override is | ||
36 | * also protected. | ||
37 | */ | ||
38 | Singleton() {}; | ||
39 | |||
40 | private: | ||
41 | /** | ||
42 | * Copy constructor, defined so that you could write your own as well. | ||
43 | */ | ||
44 | Singleton( const Singleton& ); | ||
45 | |||
46 | public: | ||
47 | /** | ||
48 | * Get a handle to the contained instance of the contained class. It is | ||
49 | * a reference. | ||
50 | *@returns A reference to the contained object. | ||
51 | */ | ||
52 | static T &getInstance() | ||
53 | { | ||
54 | static T i; | ||
55 | return i; | ||
56 | } | ||
57 | }; | ||
58 | |||
59 | #endif | ||