1 
2 /*
3  *  Created by Phil on 31/12/2010.
4  *  Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
5  *
6  *  Distributed under the Boost Software License, Version 1.0. (See accompanying
7  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8  */
9 #ifndef TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
10 #define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
11 
12 #include "catch_interfaces_registry_hub.h"
13 
14 namespace Catch {
15 
16     template<typename T>
17     class ReporterRegistrar {
18 
19         class ReporterFactory : public IReporterFactory {
20 
create(ReporterConfig const & config) const21             virtual IStreamingReporterPtr create( ReporterConfig const& config ) const override {
22                 return std::unique_ptr<T>( new T( config ) );
23             }
24 
getDescription() const25             virtual std::string getDescription() const override {
26                 return T::getDescription();
27             }
28         };
29 
30     public:
31 
ReporterRegistrar(std::string const & name)32         explicit ReporterRegistrar( std::string const& name ) {
33             getMutableRegistryHub().registerReporter( name, std::make_shared<ReporterFactory>() );
34         }
35     };
36 
37     template<typename T>
38     class ListenerRegistrar {
39 
40         class ListenerFactory : public IReporterFactory {
41 
create(ReporterConfig const & config) const42             virtual IStreamingReporterPtr create( ReporterConfig const& config ) const override {
43                 return std::unique_ptr<T>( new T( config ) );
44             }
getDescription() const45             virtual std::string getDescription() const override {
46                 return std::string();
47             }
48         };
49 
50     public:
51 
ListenerRegistrar()52         ListenerRegistrar() {
53             getMutableRegistryHub().registerListener( std::make_shared<ListenerFactory>() );
54         }
55     };
56 }
57 
58 #if !defined(CATCH_CONFIG_DISABLE)
59 
60 #define CATCH_REGISTER_REPORTER( name, reporterType ) \
61     CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS          \
62     namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); } \
63     CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
64 
65 #define CATCH_REGISTER_LISTENER( listenerType ) \
66      CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS   \
67      namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } \
68      CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
69 #else // CATCH_CONFIG_DISABLE
70 
71 #define CATCH_REGISTER_REPORTER(name, reporterType)
72 #define CATCH_REGISTER_LISTENER(listenerType)
73 
74 #endif // CATCH_CONFIG_DISABLE
75 
76 #endif // TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
77