blob: 9fcff0b4c61d477c97cb16e56a50363751e33d7e [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// (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
6// See http://www.boost.org/libs/test for the library home page.
7//
8// File : $RCSfile$
9//
10// Version : $Revision: 49312 $
11//
12// Description : simple helpers for creating cusom output manipulators
13// ***************************************************************************
14
Jeff Thompson3d613fd2013-10-15 15:39:04 -070015#ifndef NDNBOOST_TEST_TRIVIAL_SIGNLETON_HPP_020505GER
16#define NDNBOOST_TEST_TRIVIAL_SIGNLETON_HPP_020505GER
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070017
18#include <ndnboost/config.hpp>
19#include <ndnboost/detail/workaround.hpp>
20
21#include <ndnboost/noncopyable.hpp>
22
23#include <ndnboost/test/detail/suppress_warnings.hpp>
24
25//____________________________________________________________________________//
26
27namespace ndnboost {
28
29namespace unit_test {
30
31// ************************************************************************** //
32// ************** singleton ************** //
33// ************************************************************************** //
34
35template<typename Derived>
36class singleton : private ndnboost::noncopyable {
37public:
38 static Derived& instance() { static Derived the_inst; return the_inst; }
39protected:
40 singleton() {}
41 ~singleton() {}
42};
43
44} // namespace unit_test
45
Jeff Thompson3d613fd2013-10-15 15:39:04 -070046#define NDNBOOST_TEST_SINGLETON_CONS( type ) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070047friend class ndnboost::unit_test::singleton<type>; \
48type() {} \
49/**/
50
Jeff Thompson3d613fd2013-10-15 15:39:04 -070051#if NDNBOOST_WORKAROUND(__DECCXX_VER, NDNBOOST_TESTED_AT(60590042))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070052
Jeff Thompson3d613fd2013-10-15 15:39:04 -070053#define NDNBOOST_TEST_SINGLETON_INST( inst ) \
54template class unit_test::singleton< NDNBOOST_JOIN( inst, _t ) > ; \
55namespace { NDNBOOST_JOIN( inst, _t)& inst = NDNBOOST_JOIN( inst, _t)::instance(); }
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070056
57#elif defined(__APPLE_CC__) && defined(__GNUC__) && __GNUC__ < 4
Jeff Thompson3d613fd2013-10-15 15:39:04 -070058#define NDNBOOST_TEST_SINGLETON_INST( inst ) \
59static NDNBOOST_JOIN( inst, _t)& inst = NDNBOOST_JOIN (inst, _t)::instance();
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070060
61#else
62
Jeff Thompson3d613fd2013-10-15 15:39:04 -070063#define NDNBOOST_TEST_SINGLETON_INST( inst ) \
64namespace { NDNBOOST_JOIN( inst, _t)& inst = NDNBOOST_JOIN( inst, _t)::instance(); }
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070065
66#endif
67
68} // namespace ndnboost
69
70//____________________________________________________________________________//
71
72#include <ndnboost/test/detail/enable_warnings.hpp>
73
Jeff Thompson3d613fd2013-10-15 15:39:04 -070074#endif // NDNBOOST_TEST_TRIVIAL_SIGNLETON_HPP_020505GER