diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index ef88063cd3..4475aa9cc6 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -51,12 +51,7 @@ namespace std { size_t hash::operator()( const SCH_SHEET_PATH& path ) const { - size_t seed = 0; - - for( auto sheet : path ) - boost::hash_combine( seed, sheet->GetTimeStamp() ); - - return seed; + return path.GetCurrentHash(); } } @@ -64,6 +59,16 @@ namespace std SCH_SHEET_PATH::SCH_SHEET_PATH() { m_pageNumber = 0; + m_current_hash = 0; +} + + +void SCH_SHEET_PATH::Rehash() +{ + m_current_hash = 0; + + for( auto sheet : m_sheets ) + boost::hash_combine( m_current_hash, sheet->GetTimeStamp() ); } @@ -339,16 +344,7 @@ bool SCH_SHEET_PATH::SetComponentFootprint( const wxString& aReference, const wx bool SCH_SHEET_PATH::operator==( const SCH_SHEET_PATH& d1 ) const { - if( size() != d1.size() ) - return false; - - for( unsigned i = 0; i < size(); i++ ) - { - if( at( i ) != d1[i] ) - return false; - } - - return true; + return m_current_hash == d1.GetCurrentHash(); } diff --git a/eeschema/sch_sheet_path.h b/eeschema/sch_sheet_path.h index 94b1f56f21..8bb0680d82 100644 --- a/eeschema/sch_sheet_path.h +++ b/eeschema/sch_sheet_path.h @@ -89,8 +89,6 @@ class SCH_REFERENCE_LIST; #define SHEET_NOT_FOUND -1 -typedef std::vector< SCH_SHEET* > SCH_SHEETS; // no ownership over contained SCH_SHEETs - /** * Type SCH_MULTI_UNIT_REFERENCE_MAP @@ -111,13 +109,52 @@ typedef std::map SCH_MULTI_UNIT_REFERENCE_MAP; * "path" from the first to the last sheet. *

*/ -class SCH_SHEET_PATH : public SCH_SHEETS +class SCH_SHEET_PATH { +protected: + std::vector< SCH_SHEET* > m_sheets; + + size_t m_current_hash; + int m_pageNumber; /// Page numbers are maintained by the sheet load order. public: SCH_SHEET_PATH(); + /// Forwarded method from std::vector + SCH_SHEET* at( size_t aIndex ) const { return m_sheets.at( aIndex ); } + + /// Forwarded method from std::vector + void clear() + { + m_sheets.clear(); + Rehash(); + } + + /// Forwarded method from std::vector + bool empty() const { return m_sheets.empty(); } + + /// Forwarded method from std::vector + void pop_back() + { + m_sheets.pop_back(); + Rehash(); + } + + /// Forwarded method from std::vector + void push_back( SCH_SHEET* aSheet ) + { + m_sheets.push_back( aSheet ); + Rehash(); + } + + /// Forwarded method from std::vector + size_t size() const { return m_sheets.size(); } + + void Rehash(); + + size_t GetCurrentHash() const { return m_current_hash; } + void SetPageNumber( int aPageNumber ) { m_pageNumber = aPageNumber; } int GetPageNumber() const { return m_pageNumber; } @@ -303,6 +340,9 @@ public: bool operator==( const SCH_SHEET_PATH& d1 ) const; bool operator!=( const SCH_SHEET_PATH& d1 ) const { return !( *this == d1 ) ; } + + bool operator<( const SCH_SHEET_PATH& d1 ) const { return m_sheets < d1.m_sheets; } + };