mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-17 03:02:24 +01:00
Eliminate dynamic cast by promoting interface to parent class
This eliminates one use of RTTI in Catch.
This commit is contained in:
parent
c984fc3ecd
commit
218d0bdcc7
@ -226,6 +226,13 @@ namespace Catch
|
||||
// Implementing class must also provide the following static method:
|
||||
// static std::string getDescription();
|
||||
|
||||
virtual bool supportsChainedReporters() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void addChainedReporter( Ptr<IStreamingReporter> const& reporter ) {
|
||||
}
|
||||
|
||||
virtual ReporterPreferences getPreferences() const = 0;
|
||||
|
||||
virtual void noMatchingTestCases( std::string const& spec ) = 0;
|
||||
|
@ -22,6 +22,13 @@ public:
|
||||
}
|
||||
|
||||
public: // IStreamingReporter
|
||||
virtual bool supportsChainedReporters() const CATCH_OVERRIDE {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void addChainedReporter( Ptr<IStreamingReporter> const& reporter ) CATCH_OVERRIDE {
|
||||
add( reporter );
|
||||
}
|
||||
|
||||
virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
|
||||
return m_reporters[0]->getPreferences();
|
||||
@ -124,16 +131,15 @@ Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingRepo
|
||||
Ptr<IStreamingReporter> resultingReporter;
|
||||
|
||||
if( existingReporter ) {
|
||||
MultipleReporters* multi = dynamic_cast<MultipleReporters*>( existingReporter.get() );
|
||||
if( !multi ) {
|
||||
multi = new MultipleReporters;
|
||||
if( !existingReporter->supportsChainedReporters() ) {
|
||||
MultipleReporters* multi = new MultipleReporters;
|
||||
resultingReporter = Ptr<IStreamingReporter>( multi );
|
||||
if( existingReporter )
|
||||
multi->add( existingReporter );
|
||||
multi->addChainedReporter( existingReporter );
|
||||
}
|
||||
else
|
||||
resultingReporter = existingReporter;
|
||||
multi->add( additionalReporter );
|
||||
resultingReporter->addChainedReporter( additionalReporter );
|
||||
}
|
||||
else
|
||||
resultingReporter = additionalReporter;
|
||||
|
Loading…
Reference in New Issue
Block a user