catch_context.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #include "catch_context.h"
  9. #include "catch_common.h"
  10. #include "catch_random_number_generator.h"
  11. namespace Catch {
  12. class Context : public IMutableContext, NonCopyable {
  13. public: // IContext
  14. IResultCapture* getResultCapture() override {
  15. return m_resultCapture;
  16. }
  17. IRunner* getRunner() override {
  18. return m_runner;
  19. }
  20. IConfigPtr const& getConfig() const override {
  21. return m_config;
  22. }
  23. ~Context() override;
  24. public: // IMutableContext
  25. void setResultCapture( IResultCapture* resultCapture ) override {
  26. m_resultCapture = resultCapture;
  27. }
  28. void setRunner( IRunner* runner ) override {
  29. m_runner = runner;
  30. }
  31. void setConfig( IConfigPtr const& config ) override {
  32. m_config = config;
  33. }
  34. friend IMutableContext& getCurrentMutableContext();
  35. private:
  36. IConfigPtr m_config;
  37. IRunner* m_runner = nullptr;
  38. IResultCapture* m_resultCapture = nullptr;
  39. };
  40. IMutableContext *IMutableContext::currentContext = nullptr;
  41. void IMutableContext::createContext()
  42. {
  43. currentContext = new Context();
  44. }
  45. void cleanUpContext() {
  46. delete IMutableContext::currentContext;
  47. IMutableContext::currentContext = nullptr;
  48. }
  49. IContext::~IContext() = default;
  50. IMutableContext::~IMutableContext() = default;
  51. Context::~Context() = default;
  52. SimplePcg32& rng() {
  53. static SimplePcg32 s_rng;
  54. return s_rng;
  55. }
  56. }