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