From 18e32b9b9fc0d00e84d8cf0c1c7c3f8d8c8e8294 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Fri, 31 Dec 2010 22:46:51 +0000 Subject: [PATCH] Only Hub #includes report_registry. Seperated reporter registrars from registry. --- catch_reporter_basic.hpp | 3 +- catch_reporter_junit.hpp | 3 +- catch_reporter_xml.hpp | 3 +- ...registry.h => catch_interfaces_reporter.h} | 2 +- internal/catch_reporter_registrars.hpp | 58 +++++++++++++++++++ internal/catch_reporter_registry.hpp | 51 +++++++--------- internal/catch_runner_impl.hpp | 2 +- internal/catch_runnerconfig.hpp | 2 +- 8 files changed, 88 insertions(+), 36 deletions(-) rename internal/{catch_ireporterregistry.h => catch_interfaces_reporter.h} (99%) create mode 100644 internal/catch_reporter_registrars.hpp diff --git a/catch_reporter_basic.hpp b/catch_reporter_basic.hpp index 2f9ecdab..182cb06d 100644 --- a/catch_reporter_basic.hpp +++ b/catch_reporter_basic.hpp @@ -13,7 +13,8 @@ #define TWOBLUECUBES_CATCH_REPORTER_BASIC_HPP_INCLUDED #include "internal/catch_capture.hpp" -#include "internal/catch_reporter_registry.hpp" +#include "internal/catch_interfaces_reporter.h" +#include "internal/catch_reporter_registrars.hpp" namespace Catch { diff --git a/catch_reporter_junit.hpp b/catch_reporter_junit.hpp index da8d9640..98c192eb 100644 --- a/catch_reporter_junit.hpp +++ b/catch_reporter_junit.hpp @@ -13,7 +13,8 @@ #define TWOBLUECUBES_CATCH_REPORTER_JUNIT_HPP_INCLUDED #include "internal/catch_capture.hpp" -#include "internal/catch_reporter_registry.hpp" +#include "internal/catch_interfaces_reporter.h" +#include "internal/catch_reporter_registrars.hpp" #include "internal/catch_xmlwriter.hpp" namespace Catch diff --git a/catch_reporter_xml.hpp b/catch_reporter_xml.hpp index 6ab0531c..4dc0e791 100644 --- a/catch_reporter_xml.hpp +++ b/catch_reporter_xml.hpp @@ -13,7 +13,8 @@ #define TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED #include "internal/catch_capture.hpp" -#include "internal/catch_reporter_registry.hpp" +#include "internal/catch_interfaces_reporter.h" +#include "internal/catch_reporter_registrars.hpp" #include "internal/catch_xmlwriter.hpp" namespace Catch diff --git a/internal/catch_ireporterregistry.h b/internal/catch_interfaces_reporter.h similarity index 99% rename from internal/catch_ireporterregistry.h rename to internal/catch_interfaces_reporter.h index e4f303a5..a4024418 100644 --- a/internal/catch_ireporterregistry.h +++ b/internal/catch_interfaces_reporter.h @@ -1,5 +1,5 @@ /* - * catch_ireporterregistry.h + * catch_interfaces_reporter.h * Test * * Created by Phil on 31/12/2010. diff --git a/internal/catch_reporter_registrars.hpp b/internal/catch_reporter_registrars.hpp new file mode 100644 index 00000000..7b233803 --- /dev/null +++ b/internal/catch_reporter_registrars.hpp @@ -0,0 +1,58 @@ +/* + * catch_reporter_registrars.hpp + * Test + * + * Created by Phil on 31/12/2010. + * Copyright 2010 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + * + */ +#ifndef TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED +#define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED + +#include "catch_hub.hpp" + +namespace Catch +{ + template + class ReporterRegistrar + { + class ReporterFactory : public IReporterFactory + { + /////////////////////////////////////////////////////////////////// + virtual IReporter* create + ( + const IReporterConfig& config + ) + const + { + return new T( config ); + } + /////////////////////////////////////////////////////////////////// + virtual std::string getDescription + () + const + { + return T::getDescription(); + } + }; + + public: + + /////////////////////////////////////////////////////////////////////// + ReporterRegistrar + ( + const std::string& name + ) + { + Hub::getReporterRegistry().registerReporter( name, new ReporterFactory() ); + } + }; +} + +#define CATCH_REGISTER_REPORTER( name, reporterType ) \ + Catch::ReporterRegistrar catch_internal_RegistrarFor##reporterType( name ); + +#endif // TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED diff --git a/internal/catch_reporter_registry.hpp b/internal/catch_reporter_registry.hpp index 5b193550..70837845 100644 --- a/internal/catch_reporter_registry.hpp +++ b/internal/catch_reporter_registry.hpp @@ -12,18 +12,19 @@ #ifndef TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED #define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED -#include "catch_ireporterregistry.h" +#include "catch_interfaces_reporter.h" #include namespace Catch { - class ReporterRegistry : public IReporterRegistry { public: - ~ReporterRegistry() + /////////////////////////////////////////////////////////////////////// + ~ReporterRegistry + () { FactoryMap::const_iterator it = m_factories.begin(); FactoryMap::const_iterator itEnd = m_factories.end(); @@ -33,7 +34,13 @@ namespace Catch } } - virtual IReporter* create( const std::string& name, const IReporterConfig& config ) const + /////////////////////////////////////////////////////////////////////// + virtual IReporter* create + ( + const std::string& name, + const IReporterConfig& config + ) + const { FactoryMap::const_iterator it = m_factories.find( name ); if( it == m_factories.end() ) @@ -41,12 +48,20 @@ namespace Catch return it->second->create( config ); } - void registerReporter( const std::string& name, IReporterFactory* factory ) + /////////////////////////////////////////////////////////////////////// + void registerReporter + ( + const std::string& name, + IReporterFactory* factory + ) { m_factories.insert( std::make_pair( name, factory ) ); } - const FactoryMap& getFactories() const + /////////////////////////////////////////////////////////////////////// + const FactoryMap& getFactories + () + const { return m_factories; } @@ -54,30 +69,6 @@ namespace Catch private: FactoryMap m_factories; }; - - template - class ReporterFactory : public IReporterFactory - { - virtual IReporter* create( const IReporterConfig& config ) const - { - return new T( config ); - } - virtual std::string getDescription() const - { - return T::getDescription(); - } - }; - - template - struct ReporterRegistrar - { - ReporterRegistrar( const std::string& name ) - { - Hub::getReporterRegistry().registerReporter( name, new ReporterFactory() ); - } - }; } -#define CATCH_REGISTER_REPORTER( name, reporterType ) Catch::ReporterRegistrar catch_internal_RegistrarFor##reporterType( name ); - #endif // TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED \ No newline at end of file diff --git a/internal/catch_runner_impl.hpp b/internal/catch_runner_impl.hpp index e9ec030c..e7b96072 100644 --- a/internal/catch_runner_impl.hpp +++ b/internal/catch_runner_impl.hpp @@ -12,7 +12,7 @@ #ifndef TWOBLUECUBES_INTERNAL_CATCH_RUNNER_HPP_INCLUDED #define TWOBLUECUBES_INTERNAL_CATCH_RUNNER_HPP_INCLUDED -#include "catch_reporter_registry.hpp" +#include "catch_interfaces_reporter.h" #include "catch_runnerconfig.hpp" #include "catch_registry.hpp" #include "catch_capture.hpp" diff --git a/internal/catch_runnerconfig.hpp b/internal/catch_runnerconfig.hpp index cce92901..f66f8f38 100644 --- a/internal/catch_runnerconfig.hpp +++ b/internal/catch_runnerconfig.hpp @@ -13,7 +13,7 @@ #ifndef TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED #define TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED -#include "catch_reporter_registry.hpp" +#include "catch_interfaces_reporter.h" #include #include