source: NonGTP/Boost/boost/test/utils/trivial_singleton.hpp @ 857

Revision 857, 2.6 KB checked in by igarcia, 18 years ago (diff)
Line 
1//  (C) Copyright Gennadiy Rozental 2005.
2//  Distributed under the Boost Software License, Version 1.0.
3//  (See accompanying file LICENSE_1_0.txt or copy at
4//  http://www.boost.org/LICENSE_1_0.txt)
5
6//  See http://www.boost.org/libs/test for the library home page.
7//
8//  File        : $RCSfile: trivial_singleton.hpp,v $
9//
10//  Version     : $Revision: 1.2 $
11//
12//  Description : simple helpers for creating cusom output manipulators
13// ***************************************************************************
14
15#ifndef BOOST_TEST_TRIVIAL_SIGNLETON_HPP_020505GER
16#define BOOST_TEST_TRIVIAL_SIGNLETON_HPP_020505GER
17
18#include <boost/noncopyable.hpp>
19
20#include <boost/test/detail/suppress_warnings.hpp>
21
22//____________________________________________________________________________//
23
24namespace boost {
25
26namespace unit_test {
27
28// ************************************************************************** //
29// **************                   singleton                  ************** //
30// ************************************************************************** //
31
32template<typename Derived>
33class singleton : private boost::noncopyable {
34public:
35    static Derived& instance() { static Derived the_inst; return the_inst; }   
36protected:
37    singleton()  {}
38    ~singleton() {}
39};
40
41} // namespace unit_test
42
43#define BOOST_TEST_SINGLETON_CONS( type )       \
44friend class boost::unit_test::singleton<type>; \
45type() {}                                       \
46/**/
47
48#if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042))
49
50#define BOOST_TEST_SINGLETON_INST( inst ) \
51template class unit_test::singleton< BOOST_JOIN( inst, _t ) > ; \
52namespace { BOOST_JOIN( inst, _t)& inst = BOOST_JOIN( inst, _t)::instance(); }
53
54#else
55
56#define BOOST_TEST_SINGLETON_INST( inst ) \
57namespace { BOOST_JOIN( inst, _t)& inst = BOOST_JOIN( inst, _t)::instance(); }
58
59#endif
60
61} // namespace boost
62
63//____________________________________________________________________________//
64
65#include <boost/test/detail/enable_warnings.hpp>
66
67// ***************************************************************************
68//  Revision History :
69// 
70//  $Log: trivial_singleton.hpp,v $
71//  Revision 1.2  2005/06/15 07:21:51  schoepflin
72//  Tru64 needs an explicit instantiation of the singleton template. Otherwise we
73//  end up with multiple singleton instances.
74//
75//  Revision 1.1  2005/02/20 08:27:08  rogeeff
76//  This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
77//
78// ***************************************************************************
79
80#endif // BOOST_TEST_TRIVIAL_SIGNLETON_HPP_020505GER
Note: See TracBrowser for help on using the repository browser.