catch_singletons.cpp 945 B

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