trivial_singleton.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. // File : $RCSfile$
  8. //
  9. // Version : $Revision$
  10. //
  11. // Description : simple helpers for creating cusom output manipulators
  12. // ***************************************************************************
  13. #ifndef BOOST_TEST_UTILS_TRIVIAL_SIGNLETON_HPP
  14. #define BOOST_TEST_UTILS_TRIVIAL_SIGNLETON_HPP
  15. // Boost.Test
  16. #include <boost/config.hpp>
  17. #include <boost/detail/workaround.hpp>
  18. // Boost
  19. #include <boost/test/detail/suppress_warnings.hpp>
  20. //____________________________________________________________________________//
  21. namespace boost {
  22. namespace unit_test {
  23. // ************************************************************************** //
  24. // ************** singleton ************** //
  25. // ************************************************************************** //
  26. template<typename Derived>
  27. class singleton {
  28. public:
  29. static Derived& instance() { static Derived the_inst; return the_inst; }
  30. BOOST_DELETED_FUNCTION(singleton(singleton const&))
  31. BOOST_DELETED_FUNCTION(singleton& operator=(singleton const&))
  32. protected:
  33. BOOST_DEFAULTED_FUNCTION(singleton(), {})
  34. BOOST_DEFAULTED_FUNCTION(~singleton(), {})
  35. };
  36. //____________________________________________________________________________//
  37. #define BOOST_TEST_SINGLETON_CONS( type ) \
  38. friend class boost::unit_test::singleton<type>; \
  39. type() {} \
  40. /**/
  41. #if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042))
  42. #define BOOST_TEST_SINGLETON_INST( inst ) \
  43. template class unit_test::singleton< BOOST_JOIN( inst, _t ) > ; \
  44. namespace { BOOST_JOIN( inst, _t)& inst = BOOST_JOIN( inst, _t)::instance(); }
  45. #elif defined(__APPLE_CC__) && defined(__GNUC__) && __GNUC__ < 4
  46. #define BOOST_TEST_SINGLETON_INST( inst ) \
  47. static BOOST_JOIN( inst, _t)& inst = BOOST_JOIN (inst, _t)::instance();
  48. #else
  49. #define BOOST_TEST_SINGLETON_INST( inst ) \
  50. namespace { BOOST_JOIN( inst, _t)& inst = BOOST_JOIN( inst, _t)::instance(); }
  51. #endif
  52. //____________________________________________________________________________//
  53. } // namespace unit_test
  54. } // namespace boost
  55. #include <boost/test/detail/enable_warnings.hpp>
  56. #endif // BOOST_TEST_UTILS_TRIVIAL_SIGNLETON_HPP