Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
catch_singletons.hpp
Go to the documentation of this file.
1/*
2 * Created by Phil Nash on 15/6/2018.
3 *
4 * Distributed under the Boost Software License, Version 1.0. (See accompanying
5 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 */
7#ifndef TWOBLUECUBES_CATCH_SINGLETONS_HPP_INCLUDED
8#define TWOBLUECUBES_CATCH_SINGLETONS_HPP_INCLUDED
9
10namespace Catch {
11
12 struct ISingleton {
13 virtual ~ISingleton();
14 };
15
16
17 void addSingleton( ISingleton* singleton );
18 void cleanupSingletons();
19
20
21 template<typename SingletonImplT, typename InterfaceT = SingletonImplT, typename MutableInterfaceT = InterfaceT>
22 class Singleton : SingletonImplT, public ISingleton {
23
24 static auto getInternal() -> Singleton* {
25 static Singleton* s_instance = nullptr;
26 if( !s_instance ) {
27 s_instance = new Singleton;
28 addSingleton( s_instance );
29 }
30 return s_instance;
31 }
32
33 public:
34 static auto get() -> InterfaceT const& {
35 return *getInternal();
36 }
37 static auto getMutable() -> MutableInterfaceT& {
38 return *getInternal();
39 }
40 };
41
42} // namespace Catch
43
44#endif // TWOBLUECUBES_CATCH_SINGLETONS_HPP_INCLUDED
static auto getMutable() -> MutableInterfaceT &
static auto get() -> InterfaceT const &
void addSingleton(ISingleton *singleton)
void cleanupSingletons()