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 8 #include "catch_singletons.hpp" 9 10 #include <vector> 11 12 namespace Catch { 13 14 namespace { getSingletons()15 static auto getSingletons() -> std::vector<ISingleton*>*& { 16 static std::vector<ISingleton*>* g_singletons = nullptr; 17 if( !g_singletons ) 18 g_singletons = new std::vector<ISingleton*>(); 19 return g_singletons; 20 } 21 } 22 ~ISingleton()23 ISingleton::~ISingleton() {} 24 addSingleton(ISingleton * singleton)25 void addSingleton(ISingleton* singleton ) { 26 getSingletons()->push_back( singleton ); 27 } cleanupSingletons()28 void cleanupSingletons() { 29 auto& singletons = getSingletons(); 30 for( auto singleton : *singletons ) 31 delete singleton; 32 delete singletons; 33 singletons = nullptr; 34 } 35 36 } // namespace Catch 37