1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #ifndef TWOBLUECUBES_CATCH_SINGLETONS_HPP_INCLUDED
- #define TWOBLUECUBES_CATCH_SINGLETONS_HPP_INCLUDED
- namespace Catch {
- struct ISingleton {
- virtual ~ISingleton();
- };
- void addSingleton( ISingleton* singleton );
- void cleanupSingletons();
- template<typename SingletonImplT, typename InterfaceT = SingletonImplT, typename MutableInterfaceT = InterfaceT>
- class Singleton : SingletonImplT, public ISingleton {
- static auto getInternal() -> Singleton* {
- static Singleton* s_instance = nullptr;
- if( !s_instance ) {
- s_instance = new Singleton;
- addSingleton( s_instance );
- }
- return s_instance;
- }
- public:
- static auto get() -> InterfaceT const& {
- return *getInternal();
- }
- static auto getMutable() -> MutableInterfaceT& {
- return *getInternal();
- }
- };
- }
- #endif
|