File indexing completed on 2025-01-18 09:54:06
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef CATCH_SINGLETONS_HPP_INCLUDED
0009 #define CATCH_SINGLETONS_HPP_INCLUDED
0010
0011 namespace Catch {
0012
0013 struct ISingleton {
0014 virtual ~ISingleton();
0015 };
0016
0017
0018 void addSingleton( ISingleton* singleton );
0019 void cleanupSingletons();
0020
0021
0022 template<typename SingletonImplT, typename InterfaceT = SingletonImplT, typename MutableInterfaceT = InterfaceT>
0023 class Singleton : SingletonImplT, public ISingleton {
0024
0025 static auto getInternal() -> Singleton* {
0026 static Singleton* s_instance = nullptr;
0027 if( !s_instance ) {
0028 s_instance = new Singleton;
0029 addSingleton( s_instance );
0030 }
0031 return s_instance;
0032 }
0033
0034 public:
0035 static auto get() -> InterfaceT const& {
0036 return *getInternal();
0037 }
0038 static auto getMutable() -> MutableInterfaceT& {
0039 return *getInternal();
0040 }
0041 };
0042
0043 }
0044
0045 #endif