trivial_singleton.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // (C) Copyright Gennadiy Rozental 2005-2008.
  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: 49312 $
  10. //
  11. // Description : simple helpers for creating cusom output manipulators
  12. // ***************************************************************************
  13. #ifndef BOOST_TEST_TRIVIAL_SIGNLETON_HPP_020505GER
  14. #define BOOST_TEST_TRIVIAL_SIGNLETON_HPP_020505GER
  15. #include <boost/config.hpp>
  16. #include <boost/detail/workaround.hpp>
  17. #include <boost/noncopyable.hpp>
  18. #include <boost/test/detail/suppress_warnings.hpp>
  19. //____________________________________________________________________________//
  20. namespace boost {
  21. namespace unit_test {
  22. // ************************************************************************** //
  23. // ************** singleton ************** //
  24. // ************************************************************************** //
  25. template<typename Derived>
  26. class singleton : private boost::noncopyable {
  27. public:
  28. static Derived& instance() { static Derived the_inst; return the_inst; }
  29. protected:
  30. singleton() {}
  31. ~singleton() {}
  32. };
  33. } // namespace unit_test
  34. #define BOOST_TEST_SINGLETON_CONS( type ) \
  35. friend class boost::unit_test::singleton<type>; \
  36. type() {} \
  37. /**/
  38. #if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042))
  39. #define BOOST_TEST_SINGLETON_INST( inst ) \
  40. template class unit_test::singleton< BOOST_JOIN( inst, _t ) > ; \
  41. namespace { BOOST_JOIN( inst, _t)& inst = BOOST_JOIN( inst, _t)::instance(); }
  42. #elif defined(__APPLE_CC__) && defined(__GNUC__) && __GNUC__ < 4
  43. #define BOOST_TEST_SINGLETON_INST( inst ) \
  44. static BOOST_JOIN( inst, _t)& inst = BOOST_JOIN (inst, _t)::instance();
  45. #else
  46. #define BOOST_TEST_SINGLETON_INST( inst ) \
  47. namespace { BOOST_JOIN( inst, _t)& inst = BOOST_JOIN( inst, _t)::instance(); }
  48. #endif
  49. } // namespace boost
  50. //____________________________________________________________________________//
  51. #include <boost/test/detail/enable_warnings.hpp>
  52. #endif // BOOST_TEST_TRIVIAL_SIGNLETON_HPP_020505GER