1 | // (C) Copyright Gennadiy Rozental 2001. |
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$ |
9 | // |
10 | // Version : $Revision$ |
11 | // |
12 | // Description : simple helpers for creating cusom output manipulators |
13 | // *************************************************************************** |
14 | |
15 | #ifndef BOOST_TEST_UTILS_TRIVIAL_SIGNLETON_HPP |
16 | #define BOOST_TEST_UTILS_TRIVIAL_SIGNLETON_HPP |
17 | |
18 | // Boost.Test |
19 | #include <boost/config.hpp> |
20 | #include <boost/detail/workaround.hpp> |
21 | |
22 | // Boost |
23 | #include <boost/test/detail/suppress_warnings.hpp> |
24 | |
25 | //____________________________________________________________________________// |
26 | |
27 | namespace boost { |
28 | namespace unit_test { |
29 | |
30 | // ************************************************************************** // |
31 | // ************** singleton ************** // |
32 | // ************************************************************************** // |
33 | |
34 | template<typename Derived> |
35 | class singleton { |
36 | public: |
37 | static Derived& instance() { static Derived the_inst; return the_inst; } |
38 | |
39 | BOOST_DELETED_FUNCTION(singleton(singleton const&)) |
40 | BOOST_DELETED_FUNCTION(singleton& operator=(singleton const&)) |
41 | |
42 | protected: |
43 | BOOST_DEFAULTED_FUNCTION(singleton(), {}) |
44 | BOOST_DEFAULTED_FUNCTION(~singleton(), {}) |
45 | }; |
46 | |
47 | //____________________________________________________________________________// |
48 | |
49 | #define BOOST_TEST_SINGLETON_CONS( type ) \ |
50 | friend class boost::unit_test::singleton<type>; \ |
51 | type() {} \ |
52 | /**/ |
53 | |
54 | #if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042)) |
55 | |
56 | #define BOOST_TEST_SINGLETON_INST( inst ) \ |
57 | template class unit_test::singleton< BOOST_JOIN( inst, _t ) > ; \ |
58 | namespace { BOOST_JOIN( inst, _t)& inst = BOOST_JOIN( inst, _t)::instance(); } |
59 | |
60 | #elif defined(__APPLE_CC__) && defined(__GNUC__) && __GNUC__ < 4 |
61 | #define BOOST_TEST_SINGLETON_INST( inst ) \ |
62 | static BOOST_JOIN( inst, _t)& inst = BOOST_JOIN (inst, _t)::instance(); |
63 | |
64 | #else |
65 | |
66 | #define BOOST_TEST_SINGLETON_INST( inst ) \ |
67 | namespace { BOOST_JOIN( inst, _t)& inst = BOOST_JOIN( inst, _t)::instance(); } |
68 | |
69 | #endif |
70 | |
71 | //____________________________________________________________________________// |
72 | |
73 | } // namespace unit_test |
74 | } // namespace boost |
75 | |
76 | |
77 | #include <boost/test/detail/enable_warnings.hpp> |
78 | |
79 | #endif // BOOST_TEST_UTILS_TRIVIAL_SIGNLETON_HPP |
80 | |