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 return *IMutableContext::currentContext; 50 } 51 getCurrentContext()52 inline IContext& getCurrentContext() 53 { 54 return getCurrentMutableContext(); 55 } 56 57 void cleanUpContext(); 58 } 59 60 #endif // TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED 61