Return plain ptr from ITracker::findChild instead of shared_ptr

This is part of wider rework of trackers to avoid `std::shared_ptr`
everywhere.

Related to #2088
This commit is contained in:
Martin Hořeňovský
2020-12-04 21:37:24 +01:00
parent 21c97f2fad
commit 6350851f9a
3 changed files with 26 additions and 20 deletions
+14 -10
View File
@@ -34,7 +34,7 @@ namespace Catch {
~GeneratorTracker();
static GeneratorTracker& acquire( TrackerContext& ctx, TestCaseTracking::NameAndLocation const& nameAndLocation ) {
std::shared_ptr<GeneratorTracker> tracker;
GeneratorTracker* tracker;
ITracker& currentTracker = ctx.currentTracker();
// Under specific circumstances, the generator we want
@@ -48,18 +48,22 @@ namespace Catch {
// }
//
// without it, the code above creates 5 nested generators.
if (currentTracker.nameAndLocation() == nameAndLocation) {
auto thisTracker = currentTracker.parent().findChild(nameAndLocation);
assert(thisTracker);
assert(thisTracker->isGeneratorTracker());
tracker = std::static_pointer_cast<GeneratorTracker>(thisTracker);
} else if ( TestCaseTracking::ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) {
if ( currentTracker.nameAndLocation() == nameAndLocation ) {
auto thisTracker =
currentTracker.parent().findChild( nameAndLocation );
assert( thisTracker );
assert( thisTracker->isGeneratorTracker() );
tracker = static_cast<GeneratorTracker*>( thisTracker );
} else if ( ITracker* childTracker =
currentTracker.findChild( nameAndLocation ) ) {
assert( childTracker );
assert( childTracker->isGeneratorTracker() );
tracker = std::static_pointer_cast<GeneratorTracker>( childTracker );
tracker = static_cast<GeneratorTracker*>( childTracker );
} else {
tracker = std::make_shared<GeneratorTracker>( nameAndLocation, ctx, &currentTracker );
currentTracker.addChild( tracker );
auto newTracker = std::make_shared<GeneratorTracker>(
nameAndLocation, ctx, &currentTracker );
tracker = newTracker.get();
currentTracker.addChild( std::move(newTracker) );
}
if( !tracker->isComplete() ) {