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 
11 #include <memory>
12 
13 namespace Catch {
14 
15     struct IResultCapture;
16     struct IRunner;
17     struct IConfig;
18     struct IMutableContext;
19 
20     using IConfigPtr = std::shared_ptr<IConfig const>;
21 
22     struct IContext
23     {
24         virtual ~IContext();
25 
26         virtual IResultCapture* getResultCapture() = 0;
27         virtual IRunner* getRunner() = 0;
28         virtual IConfigPtr const& getConfig() const = 0;
29     };
30 
31     struct IMutableContext : IContext
32     {
33         virtual ~IMutableContext();
34         virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
35         virtual void setRunner( IRunner* runner ) = 0;
36         virtual void setConfig( IConfigPtr const& config ) = 0;
37 
38     private:
39         static IMutableContext *currentContext;
40         friend IMutableContext& getCurrentMutableContext();
41         friend void cleanUpContext();
42         static void createContext();
43     };
44 
getCurrentMutableContext()45     inline IMutableContext& getCurrentMutableContext()
46     {
47         if( !IMutableContext::currentContext )
48             IMutableContext::createContext();
49         // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn)
50         return *IMutableContext::currentContext;
51     }
52 
getCurrentContext()53     inline IContext& getCurrentContext()
54     {
55         return getCurrentMutableContext();
56     }
57 
58     void cleanUpContext();
59 
60     class SimplePcg32;
61     SimplePcg32& rng();
62 }
63 
64 #endif // TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
65