catch_context.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Created by Phil on 31/12/2010.
  3. * Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
  4. *
  5. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
  9. #define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
  10. #include <memory>
  11. namespace Catch {
  12. struct IResultCapture;
  13. struct IRunner;
  14. struct IConfig;
  15. struct IMutableContext;
  16. using IConfigPtr = std::shared_ptr<IConfig const>;
  17. struct IContext
  18. {
  19. virtual ~IContext();
  20. virtual IResultCapture* getResultCapture() = 0;
  21. virtual IRunner* getRunner() = 0;
  22. virtual IConfigPtr const& getConfig() const = 0;
  23. };
  24. struct IMutableContext : IContext
  25. {
  26. virtual ~IMutableContext();
  27. virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
  28. virtual void setRunner( IRunner* runner ) = 0;
  29. virtual void setConfig( IConfigPtr const& config ) = 0;
  30. private:
  31. static IMutableContext *currentContext;
  32. friend IMutableContext& getCurrentMutableContext();
  33. friend void cleanUpContext();
  34. static void createContext();
  35. };
  36. inline IMutableContext& getCurrentMutableContext()
  37. {
  38. if( !IMutableContext::currentContext )
  39. IMutableContext::createContext();
  40. // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn)
  41. return *IMutableContext::currentContext;
  42. }
  43. inline IContext& getCurrentContext()
  44. {
  45. return getCurrentMutableContext();
  46. }
  47. void cleanUpContext();
  48. class SimplePcg32;
  49. SimplePcg32& rng();
  50. }
  51. #endif // TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED