Removed use of dynamic_cast for MultipleReporters

(Thanks to #630, #636 and #648)
This commit is contained in:
Phil Nash 2016-04-28 07:54:57 +01:00
parent e5537842d0
commit 3b19458fed
2 changed files with 9 additions and 1 deletions

View File

@ -219,6 +219,7 @@ namespace Catch
bool aborting; bool aborting;
}; };
class MultipleReporters;
struct IStreamingReporter : IShared { struct IStreamingReporter : IShared {
virtual ~IStreamingReporter(); virtual ~IStreamingReporter();
@ -247,6 +248,8 @@ namespace Catch
virtual void testRunEnded( TestRunStats const& testRunStats ) = 0; virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
virtual void skipTest( TestCaseInfo const& testInfo ) = 0; virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
virtual MultipleReporters* tryAsMulti() { return CATCH_NULL; }
}; };

View File

@ -118,13 +118,18 @@ public: // IStreamingReporter
++it ) ++it )
(*it)->skipTest( testInfo ); (*it)->skipTest( testInfo );
} }
virtual MultipleReporters* tryAsMulti() CATCH_OVERRIDE {
return this;
}
}; };
Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter ) { Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter ) {
Ptr<IStreamingReporter> resultingReporter; Ptr<IStreamingReporter> resultingReporter;
if( existingReporter ) { if( existingReporter ) {
MultipleReporters* multi = dynamic_cast<MultipleReporters*>( existingReporter.get() ); MultipleReporters* multi = existingReporter->tryAsMulti();
if( !multi ) { if( !multi ) {
multi = new MultipleReporters; multi = new MultipleReporters;
resultingReporter = Ptr<IStreamingReporter>( multi ); resultingReporter = Ptr<IStreamingReporter>( multi );