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             IStreamingReporterPtr create( ReporterConfig const& config ) const override {
22                 return std::unique_ptr<T>( new T( config ) );
23             }
24 
getDescription() const25             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             IStreamingReporterPtr create( ReporterConfig const& config ) const override {
43                 return std::unique_ptr<T>( new T( config ) );
44             }
getDescription() const45             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_START_WARNINGS_SUPPRESSION         \
62     CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS          \
63     namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); } \
64     CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
65 
66 #define CATCH_REGISTER_LISTENER( listenerType ) \
67     CATCH_INTERNAL_START_WARNINGS_SUPPRESSION   \
68     CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS    \
69     namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } \
70     CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
71 #else // CATCH_CONFIG_DISABLE
72 
73 #define CATCH_REGISTER_REPORTER(name, reporterType)
74 #define CATCH_REGISTER_LISTENER(listenerType)
75 
76 #endif // CATCH_CONFIG_DISABLE
77 
78 #endif // TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
79