sl@0: // Copyright (C) 2001-2003 sl@0: // Mac Murrett sl@0: // sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: // sl@0: // See http://www.boost.org for most recent version including documentation. sl@0: sl@0: #ifndef BOOST_SINGLETON_MJM012402_HPP sl@0: #define BOOST_SINGLETON_MJM012402_HPP sl@0: sl@0: #include sl@0: sl@0: namespace boost { sl@0: namespace detail { sl@0: namespace thread { sl@0: sl@0: // class singleton has the same goal as all singletons: create one instance of sl@0: // a class on demand, then dish it out as requested. sl@0: sl@0: template sl@0: class singleton : private T sl@0: { sl@0: private: sl@0: singleton(); sl@0: ~singleton(); sl@0: sl@0: public: sl@0: static T &instance(); sl@0: }; sl@0: sl@0: sl@0: template sl@0: inline singleton::singleton() sl@0: { sl@0: /* no-op */ sl@0: } sl@0: sl@0: template sl@0: inline singleton::~singleton() sl@0: { sl@0: /* no-op */ sl@0: } sl@0: sl@0: template sl@0: /*static*/ T &singleton::instance() sl@0: { sl@0: // function-local static to force this to work correctly at static sl@0: // initialization time. sl@0: static singleton s_oT; sl@0: return(s_oT); sl@0: } sl@0: sl@0: } // namespace thread sl@0: } // namespace detail sl@0: } // namespace boost sl@0: sl@0: #endif // BOOST_SINGLETON_MJM012402_HPP