From e6094a9503f513480d6b01bc174d8ff725c809b3 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 25 Apr 2017 21:08:41 +0100 Subject: [PATCH] migrated (Reporter) Nodes to std::shared_ptr --- include/reporters/catch_reporter_bases.hpp | 46 +++++++++++----------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/include/reporters/catch_reporter_bases.hpp b/include/reporters/catch_reporter_bases.hpp index 6c8e4541..371f9624 100644 --- a/include/reporters/catch_reporter_bases.hpp +++ b/include/reporters/catch_reporter_bases.hpp @@ -105,28 +105,28 @@ namespace Catch { struct CumulativeReporterBase : SharedImpl { template - struct Node : SharedImpl<> { + struct Node { explicit Node( T const& _value ) : value( _value ) {} virtual ~Node() {} - typedef std::vector > ChildNodes; + using ChildNodes = std::vector>; T value; ChildNodes children; }; - struct SectionNode : SharedImpl<> { + struct SectionNode { explicit SectionNode( SectionStats const& _stats ) : stats( _stats ) {} virtual ~SectionNode(); bool operator == ( SectionNode const& other ) const { return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo; } - bool operator == ( Ptr const& other ) const { + bool operator == ( std::shared_ptr const& other ) const { return operator==( *other ); } SectionStats stats; - typedef std::vector > ChildSections; - typedef std::vector Assertions; + using ChildSections = std::vector>; + using Assertions = std::vector; ChildSections childSections; Assertions assertions; std::string stdOut; @@ -136,7 +136,7 @@ namespace Catch { struct BySectionInfo { BySectionInfo( SectionInfo const& other ) : m_other( other ) {} BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {} - bool operator() ( Ptr const& node ) const { + bool operator() ( std::shared_ptr const& node ) const { return node->stats.sectionInfo.lineInfo == m_other.lineInfo; } private: @@ -145,9 +145,9 @@ namespace Catch { }; - typedef Node TestCaseNode; - typedef Node TestGroupNode; - typedef Node TestRunNode; + using TestCaseNode = Node; + using TestGroupNode = Node; + using TestRunNode = Node; CumulativeReporterBase( ReporterConfig const& _config ) : m_config( _config.fullConfig() ), @@ -168,10 +168,10 @@ namespace Catch { virtual void sectionStarting( SectionInfo const& sectionInfo ) override { SectionStats incompleteStats( sectionInfo, Counts(), 0, false ); - Ptr node; + std::shared_ptr node; if( m_sectionStack.empty() ) { if( !m_rootSection ) - m_rootSection = new SectionNode( incompleteStats ); + m_rootSection = std::make_shared( incompleteStats ); node = m_rootSection; } else { @@ -181,7 +181,7 @@ namespace Catch { parentNode.childSections.end(), BySectionInfo( sectionInfo ) ); if( it == parentNode.childSections.end() ) { - node = new SectionNode( incompleteStats ); + node = std::make_shared( incompleteStats ); parentNode.childSections.push_back( node ); } else @@ -212,7 +212,7 @@ namespace Catch { m_sectionStack.pop_back(); } virtual void testCaseEnded( TestCaseStats const& testCaseStats ) override { - Ptr node = new TestCaseNode( testCaseStats ); + auto node = std::make_shared( testCaseStats ); assert( m_sectionStack.size() == 0 ); node->children.push_back( m_rootSection ); m_testCases.push_back( node ); @@ -223,12 +223,12 @@ namespace Catch { m_deepestSection->stdErr = testCaseStats.stdErr; } virtual void testGroupEnded( TestGroupStats const& testGroupStats ) override { - Ptr node = new TestGroupNode( testGroupStats ); + auto node = std::make_shared( testGroupStats ); node->children.swap( m_testCases ); m_testGroups.push_back( node ); } virtual void testRunEnded( TestRunStats const& testRunStats ) override { - Ptr node = new TestRunNode( testRunStats ); + auto node = std::make_shared( testRunStats ); node->children.swap( m_testGroups ); m_testRuns.push_back( node ); testRunEndedCumulative(); @@ -247,15 +247,15 @@ namespace Catch { IConfigPtr m_config; std::ostream& stream; std::vector m_assertions; - std::vector > > m_sections; - std::vector > m_testCases; - std::vector > m_testGroups; + std::vector>> m_sections; + std::vector> m_testCases; + std::vector> m_testGroups; - std::vector > m_testRuns; + std::vector> m_testRuns; - Ptr m_rootSection; - Ptr m_deepestSection; - std::vector > m_sectionStack; + std::shared_ptr m_rootSection; + std::shared_ptr m_deepestSection; + std::vector> m_sectionStack; ReporterPreferences m_reporterPrefs; };