From 4c7471eb794eaf90636651b92cc51000d72f8471 Mon Sep 17 00:00:00 2001 From: Oleg Endo Date: Mon, 13 Apr 2020 04:10:57 +0900 Subject: [PATCH] add more constness to connecivity algo also make ForEachAnchor inlineable, like ForEachItem. remove some unused function declarations. --- pcbnew/connectivity/connectivity_algo.cpp | 10 --------- pcbnew/connectivity/connectivity_algo.h | 26 +++++++++++++++-------- pcbnew/connectivity/connectivity_data.cpp | 2 +- pcbnew/connectivity/connectivity_items.h | 12 ++++++++++- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/pcbnew/connectivity/connectivity_algo.cpp b/pcbnew/connectivity/connectivity_algo.cpp index 44fefe4560..162a25c18d 100644 --- a/pcbnew/connectivity/connectivity_algo.cpp +++ b/pcbnew/connectivity/connectivity_algo.cpp @@ -747,16 +747,6 @@ void CN_CONNECTIVITY_ALGO::Clear() } -void CN_CONNECTIVITY_ALGO::ForEachAnchor( const std::function& aFunc ) -{ - ForEachItem( [aFunc] ( CN_ITEM& item ) { - for( const auto& anchor : item.Anchors() ) - aFunc( *anchor ); - } - ); -} - - void CN_CONNECTIVITY_ALGO::SetProgressReporter( PROGRESS_REPORTER* aReporter ) { m_progressReporter = aReporter; diff --git a/pcbnew/connectivity/connectivity_algo.h b/pcbnew/connectivity/connectivity_algo.h index 9faab25934..4b75f2af6c 100644 --- a/pcbnew/connectivity/connectivity_algo.h +++ b/pcbnew/connectivity/connectivity_algo.h @@ -173,7 +173,7 @@ public: CN_CONNECTIVITY_ALGO() {} ~CN_CONNECTIVITY_ALGO() { Clear(); } - bool ItemExists( const BOARD_CONNECTED_ITEM* aItem ) + bool ItemExists( const BOARD_CONNECTED_ITEM* aItem ) const { return m_itemMap.find( aItem ) != m_itemMap.end(); } @@ -197,7 +197,7 @@ public: *i = false; } - void GetDirtyClusters( CLUSTERS& aClusters ) + void GetDirtyClusters( CLUSTERS& aClusters ) const { for( const auto& cl : m_ratsnestClusters ) { @@ -240,17 +240,25 @@ public: */ void FindIsolatedCopperIslands( std::vector& aZones ); - bool CheckConnectivity( std::vector& aReport ); - const CLUSTERS& GetClusters(); - int GetUnconnectedCount(); - CN_LIST& ItemList() { return m_itemList; } - - void ForEachAnchor( const std::function& aFunc ); + const CN_LIST& ItemList() const + { + return m_itemList; + } template - void ForEachItem( Func&& aFunc ) + void ForEachAnchor( Func&& aFunc ) const + { + for( auto&& item : m_itemList ) + { + for( auto&& anchor : item->Anchors() ) + aFunc( *anchor ); + } + } + + template + void ForEachItem( Func&& aFunc ) const { for( auto&& item : m_itemList ) aFunc( *item ); diff --git a/pcbnew/connectivity/connectivity_data.cpp b/pcbnew/connectivity/connectivity_data.cpp index 8b019847dc..65d960a2bb 100644 --- a/pcbnew/connectivity/connectivity_data.cpp +++ b/pcbnew/connectivity/connectivity_data.cpp @@ -504,7 +504,7 @@ unsigned int CONNECTIVITY_DATA::GetPadCount( int aNet ) const { int n = 0; - for( auto pad : m_connAlgo->ItemList() ) + for( auto&& pad : m_connAlgo->ItemList() ) { if( !pad->Valid() || pad->Parent()->Type() != PCB_PAD_T) continue; diff --git a/pcbnew/connectivity/connectivity_items.h b/pcbnew/connectivity/connectivity_items.h index 1d2c828a25..6ebda48967 100644 --- a/pcbnew/connectivity/connectivity_items.h +++ b/pcbnew/connectivity/connectivity_items.h @@ -425,11 +425,21 @@ public: m_index.RemoveAll(); } - using ITER = decltype(m_items)::iterator; + using ITER = decltype( m_items )::iterator; + using CONST_ITER = decltype( m_items )::const_iterator; ITER begin() { return m_items.begin(); }; ITER end() { return m_items.end(); }; + CONST_ITER begin() const + { + return m_items.begin(); + } + CONST_ITER end() const + { + return m_items.end(); + } + CN_ITEM* operator[] ( int aIndex ) { return m_items[aIndex]; } template