Reduce the use of shared_ptrs for various Config objects

Ideally they would not be used at all, but the main config lifetime
is a weird mess right now and will require further refactoring.
This commit is contained in:
Martin Hořeňovský 2020-01-25 15:32:56 +01:00
parent 7134ad9913
commit df2379218b
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
7 changed files with 16 additions and 16 deletions

View File

@ -16,14 +16,14 @@
namespace Catch {
ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig )
ReporterConfig::ReporterConfig( IConfig const* _fullConfig )
: m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream )
ReporterConfig::ReporterConfig( IConfig const* _fullConfig, std::ostream& _stream )
: m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
std::ostream& ReporterConfig::stream() const { return *m_stream; }
IConfigPtr ReporterConfig::fullConfig() const { return m_fullConfig; }
IConfig const * ReporterConfig::fullConfig() const { return m_fullConfig; }
TestRunInfo::TestRunInfo( std::string const& _name ) : name( _name ) {}

View File

@ -37,16 +37,16 @@ namespace Catch {
struct TagInfo;
struct ReporterConfig {
explicit ReporterConfig( IConfigPtr const& _fullConfig );
explicit ReporterConfig( IConfig const* _fullConfig );
ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream );
ReporterConfig( IConfig const* _fullConfig, std::ostream& _stream );
std::ostream& stream() const;
IConfigPtr fullConfig() const;
IConfig const* fullConfig() const;
private:
std::ostream* m_stream;
IConfigPtr m_fullConfig;
IConfig const* m_fullConfig;
};
struct ReporterPreferences {
@ -268,7 +268,7 @@ namespace Catch {
using Listeners = std::vector<IReporterFactoryPtr>;
virtual ~IReporterRegistry();
virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0;
virtual IStreamingReporterPtr create( std::string const& name, IConfig const* config ) const = 0;
virtual FactoryMap const& getFactories() const = 0;
virtual Listeners const& getListeners() const = 0;
};

View File

@ -34,7 +34,7 @@ namespace Catch {
ReporterRegistry::~ReporterRegistry() = default;
IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfigPtr const& config ) const {
IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfig const* config ) const {
auto it = m_factories.find( name );
if( it == m_factories.end() )
return nullptr;

View File

@ -20,7 +20,7 @@ namespace Catch {
ReporterRegistry();
~ReporterRegistry() override; // = default, out of line to allow fwd decl
IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const override;
IStreamingReporterPtr create( std::string const& name, IConfig const* config ) const override;
void registerReporter( std::string const& name, IReporterFactoryPtr factory );
void registerListener( IReporterFactoryPtr factory );

View File

@ -33,14 +33,14 @@ namespace Catch {
namespace {
const int MaxExitCode = 255;
IStreamingReporterPtr createReporter(std::string const& reporterName, IConfigPtr const& config) {
IStreamingReporterPtr createReporter(std::string const& reporterName, IConfig const* config) {
auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, config);
CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << "'");
return reporter;
}
IStreamingReporterPtr makeReporter(std::shared_ptr<Config> const& config) {
IStreamingReporterPtr makeReporter(Config const* config) {
if (Catch::getRegistryHub().getReporterRegistry().getListeners().empty()) {
return createReporter(config->getReporterName(), config);
}
@ -273,7 +273,7 @@ namespace Catch {
}
// Create reporter(s) so we can route listings through them
auto reporter = makeReporter(m_config);
auto reporter = makeReporter(m_config.get());
// Handle list request
if (list(*reporter, m_config)) {

View File

@ -81,7 +81,7 @@ namespace Catch {
// It can optionally be overridden in the derived class.
}
IConfigPtr m_config;
IConfig const* m_config;
std::ostream& stream;
LazyStat<TestRunInfo> currentTestRunInfo;
@ -227,7 +227,7 @@ namespace Catch {
void skipTest(TestCaseInfo const&) override {}
IConfigPtr m_config;
IConfig const* m_config;
std::ostream& stream;
std::vector<AssertionStats> m_assertions;
std::vector<std::vector<std::shared_ptr<SectionNode>>> m_sections;