~ubuntu-branches/ubuntu/breezy/aqsis/breezy

« back to all changes in this revision

Viewing changes to boost/boost/thread/detail/singleton.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Will Newton
  • Date: 2004-12-07 20:06:49 UTC
  • Revision ID: james.westby@ubuntu.com-20041207200649-fccswkrvp4oc8lmn
Tags: upstream-0.9.3
ImportĀ upstreamĀ versionĀ 0.9.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2001
 
2
// Mac Murrett
 
3
//
 
4
// Permission to use, copy, modify, distribute and sell this software
 
5
// and its documentation for any purpose is hereby granted without fee,
 
6
// provided that the above copyright notice appear in all copies and
 
7
// that both that copyright notice and this permission notice appear
 
8
// in supporting documentation.  Mac Murrett makes no representations
 
9
// about the suitability of this software for any purpose.  It is
 
10
// provided "as is" without express or implied warranty.
 
11
//
 
12
// See http://www.boost.org for most recent version including documentation.
 
13
 
 
14
#ifndef BOOST_SINGLETON_MJM012402_HPP
 
15
#define BOOST_SINGLETON_MJM012402_HPP
 
16
 
 
17
namespace boost {
 
18
 
 
19
namespace detail {
 
20
 
 
21
namespace thread {
 
22
 
 
23
// class singleton has the same goal as all singletons: create one instance of a
 
24
//  class on demand, then dish it out as requested.
 
25
 
 
26
template<class T>
 
27
class singleton: private T
 
28
{
 
29
private:
 
30
    singleton();
 
31
    ~singleton();
 
32
 
 
33
public:
 
34
    static T &instance();
 
35
};
 
36
 
 
37
 
 
38
template<class T>
 
39
inline singleton<T>::singleton()
 
40
{   /* no-op */ }
 
41
 
 
42
template<class T>
 
43
inline singleton<T>::~singleton()
 
44
{   /* no-op */ }
 
45
 
 
46
 
 
47
template<class T>
 
48
/*static*/ T &singleton<T>::instance()
 
49
{
 
50
    // function-local static to force this to work correctly at static
 
51
    // initialization time.
 
52
    static singleton<T> s_oT;
 
53
    return(s_oT);
 
54
}
 
55
 
 
56
 
 
57
} // namespace thread
 
58
 
 
59
} // namespace detail
 
60
 
 
61
} // namespace boost
 
62
 
 
63
 
 
64
#endif // BOOST_SINGLETON_MJM012402_HPP