Line | |
---|
1 | // Copyright (C) 2001-2003
|
---|
2 | // Mac Murrett
|
---|
3 | //
|
---|
4 | // Distributed under the Boost Software License, Version 1.0. (See
|
---|
5 | // accompanying file LICENSE_1_0.txt or copy at
|
---|
6 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
7 | //
|
---|
8 | // See http://www.boost.org for most recent version including documentation.
|
---|
9 |
|
---|
10 | #ifndef BOOST_SINGLETON_MJM012402_HPP
|
---|
11 | #define BOOST_SINGLETON_MJM012402_HPP
|
---|
12 |
|
---|
13 | #include <boost/thread/detail/config.hpp>
|
---|
14 |
|
---|
15 | namespace boost {
|
---|
16 | namespace detail {
|
---|
17 | namespace thread {
|
---|
18 |
|
---|
19 | // class singleton has the same goal as all singletons: create one instance of
|
---|
20 | // a class on demand, then dish it out as requested.
|
---|
21 |
|
---|
22 | template <class T>
|
---|
23 | class singleton : private T
|
---|
24 | {
|
---|
25 | private:
|
---|
26 | singleton();
|
---|
27 | ~singleton();
|
---|
28 |
|
---|
29 | public:
|
---|
30 | static T &instance();
|
---|
31 | };
|
---|
32 |
|
---|
33 |
|
---|
34 | template <class T>
|
---|
35 | inline singleton<T>::singleton()
|
---|
36 | {
|
---|
37 | /* no-op */
|
---|
38 | }
|
---|
39 |
|
---|
40 | template <class T>
|
---|
41 | inline singleton<T>::~singleton()
|
---|
42 | {
|
---|
43 | /* no-op */
|
---|
44 | }
|
---|
45 |
|
---|
46 | template <class T>
|
---|
47 | /*static*/ T &singleton<T>::instance()
|
---|
48 | {
|
---|
49 | // function-local static to force this to work correctly at static
|
---|
50 | // initialization time.
|
---|
51 | static singleton<T> s_oT;
|
---|
52 | return(s_oT);
|
---|
53 | }
|
---|
54 |
|
---|
55 | } // namespace thread
|
---|
56 | } // namespace detail
|
---|
57 | } // namespace boost
|
---|
58 |
|
---|
59 | #endif // BOOST_SINGLETON_MJM012402_HPP
|
---|
Note: See
TracBrowser
for help on using the repository browser.