From 96cdfc7fa7e893b387dcacfa8d7a5841f5e5b944 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Fri, 12 Apr 2024 23:05:00 -0400 Subject: [PATCH] Update equality overloads for C++20 C++20 added new reverse and rewritten candidates. This can confuse the compiler because it'll test both A==B and B==A for overloads. Because we were defining parent class equality overloads, A==B and B==A was considered ambigious due to both being compatible in casting. So we needed to add explicit child class equality operator overloads --- eeschema/sch_field.cpp | 21 ++++++++++++++------- eeschema/sch_field.h | 1 + eeschema/sch_junction.cpp | 4 ++-- eeschema/sch_pin.cpp | 12 +++++++++--- eeschema/sch_pin.h | 1 + eeschema/sch_tablecell.cpp | 9 ++++++--- eeschema/sch_tablecell.h | 1 + pcbnew/footprint.cpp | 22 ++++++++++++++-------- pcbnew/footprint.h | 1 + pcbnew/pcb_field.cpp | 8 +++++++- pcbnew/pcb_field.h | 1 + pcbnew/pcb_tablecell.cpp | 12 ++++++++---- pcbnew/pcb_tablecell.h | 1 + pcbnew/pcb_track.cpp | 12 ++++++++++-- pcbnew/pcb_track.h | 1 + pcbnew/zone.cpp | 35 ++++++++++++++++++++--------------- pcbnew/zone.h | 1 + 17 files changed, 98 insertions(+), 45 deletions(-) diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index b9862075fb..f59458c3cb 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -1321,29 +1321,36 @@ bool SCH_FIELD::operator <( const SCH_ITEM& aItem ) const return GetName() < field->GetName(); } -bool SCH_FIELD::operator==( const SCH_ITEM& aOther ) const + +bool SCH_FIELD::operator==(const SCH_ITEM& aOther) const { if( Type() != aOther.Type() ) return false; const SCH_FIELD& field = static_cast( aOther ); - if( GetId() != field.GetId() ) + return *this == field; +} + + +bool SCH_FIELD::operator==( const SCH_FIELD& aOther ) const +{ + if( GetId() != aOther.GetId() ) return false; - if( GetPosition() != field.GetPosition() ) + if( GetPosition() != aOther.GetPosition() ) return false; - if( IsNamedVariable() != field.IsNamedVariable() ) + if( IsNamedVariable() != aOther.IsNamedVariable() ) return false; - if( IsNameShown() != field.IsNameShown() ) + if( IsNameShown() != aOther.IsNameShown() ) return false; - if( CanAutoplace() != field.CanAutoplace() ) + if( CanAutoplace() != aOther.CanAutoplace() ) return false; - if( GetText() != field.GetText() ) + if( GetText() != aOther.GetText() ) return false; return true; diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index 663fc715b8..9f3af27fdb 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -284,6 +284,7 @@ public: double Similarity( const SCH_ITEM& aItem ) const override; bool operator==( const SCH_ITEM& aItem ) const override; + bool operator==( const SCH_FIELD& aItem ) const; #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } diff --git a/eeschema/sch_junction.cpp b/eeschema/sch_junction.cpp index aaf35a72f7..f318bb0a4d 100644 --- a/eeschema/sch_junction.cpp +++ b/eeschema/sch_junction.cpp @@ -165,8 +165,8 @@ void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const // XML output: wxString s = GetClass(); - NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << wxS( ", " ) << m_diameter - << wxS( "/>\n" ); + NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << ", " << m_diameter + << "/>\n"; } #endif diff --git a/eeschema/sch_pin.cpp b/eeschema/sch_pin.cpp index 98a16f7de0..cc241e80a8 100644 --- a/eeschema/sch_pin.cpp +++ b/eeschema/sch_pin.cpp @@ -494,13 +494,19 @@ bool SCH_PIN::operator==( const SCH_ITEM& aOther ) const const SCH_PIN& other = static_cast( aOther ); - if( m_number != other.m_number ) + return *this == other; +} + + +bool SCH_PIN::operator==( const SCH_PIN& aOther ) const +{ + if( m_number != aOther.m_number ) return false; - if( m_position != other.m_position ) + if( m_position != aOther.m_position ) return false; - return m_libPin == other.m_libPin; + return m_libPin == aOther.m_libPin; } diff --git a/eeschema/sch_pin.h b/eeschema/sch_pin.h index c7f99b1713..d84033b331 100644 --- a/eeschema/sch_pin.h +++ b/eeschema/sch_pin.h @@ -169,6 +169,7 @@ public: double Similarity( const SCH_ITEM& aItem ) const override; bool operator==( const SCH_ITEM& aItem ) const override; + bool operator==( const SCH_PIN& aItem ) const; bool operator!=( const SCH_PIN& aRhs ) const { return !( *this == aRhs ); } diff --git a/eeschema/sch_tablecell.cpp b/eeschema/sch_tablecell.cpp index 12cde39b9a..e3c56650b7 100644 --- a/eeschema/sch_tablecell.cpp +++ b/eeschema/sch_tablecell.cpp @@ -162,12 +162,15 @@ bool SCH_TABLECELL::operator==( const SCH_ITEM& aOtherItem ) const const SCH_TABLECELL& other = static_cast( aOtherItem ); - return m_colSpan == other.m_colSpan - && m_rowSpan == other.m_rowSpan - && SCH_TEXTBOX::operator==( other ); + return *this == other; } +bool SCH_TABLECELL::operator==( const SCH_TABLECELL& aOtherItem ) const +{ + return m_colSpan == aOtherItem.m_colSpan && m_rowSpan == aOtherItem.m_rowSpan + && SCH_TEXTBOX::operator==( aOtherItem ); +} static struct SCH_TABLECELL_DESC { diff --git a/eeschema/sch_tablecell.h b/eeschema/sch_tablecell.h index 92c7615797..ea69be0c8a 100644 --- a/eeschema/sch_tablecell.h +++ b/eeschema/sch_tablecell.h @@ -74,6 +74,7 @@ public: double Similarity( const SCH_ITEM& aOther ) const override; + bool operator==( const SCH_TABLECELL& aOther ) const; bool operator==( const SCH_ITEM& aOther ) const override; protected: diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index 2558a5d9de..6655dcb09d 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -3312,39 +3312,45 @@ bool FOOTPRINT::operator==( const BOARD_ITEM& aOther ) const const FOOTPRINT& other = static_cast( aOther ); - if( m_pads.size() != other.m_pads.size() ) + return *this == other; +} + + +bool FOOTPRINT::operator==( const FOOTPRINT& aOther ) const +{ + if( m_pads.size() != aOther.m_pads.size() ) return false; for( size_t ii = 0; ii < m_pads.size(); ++ii ) { - if( !( *m_pads[ii] == *other.m_pads[ii] ) ) + if( !( *m_pads[ii] == *aOther.m_pads[ii] ) ) return false; } - if( m_drawings.size() != other.m_drawings.size() ) + if( m_drawings.size() != aOther.m_drawings.size() ) return false; for( size_t ii = 0; ii < m_drawings.size(); ++ii ) { - if( !( *m_drawings[ii] == *other.m_drawings[ii] ) ) + if( !( *m_drawings[ii] == *aOther.m_drawings[ii] ) ) return false; } - if( m_zones.size() != other.m_zones.size() ) + if( m_zones.size() != aOther.m_zones.size() ) return false; for( size_t ii = 0; ii < m_zones.size(); ++ii ) { - if( !( *m_zones[ii] == *other.m_zones[ii] ) ) + if( !( *m_zones[ii] == *aOther.m_zones[ii] ) ) return false; } - if( m_fields.size() != other.m_fields.size() ) + if( m_fields.size() != aOther.m_fields.size() ) return false; for( size_t ii = 0; ii < m_fields.size(); ++ii ) { - if( !( *m_fields[ii] == *other.m_fields[ii] ) ) + if( !( *m_fields[ii] == *aOther.m_fields[ii] ) ) return false; } diff --git a/pcbnew/footprint.h b/pcbnew/footprint.h index 65829b739a..59a6018b1b 100644 --- a/pcbnew/footprint.h +++ b/pcbnew/footprint.h @@ -958,6 +958,7 @@ public: double Similarity( const BOARD_ITEM& aOther ) const override; bool operator==( const BOARD_ITEM& aOther ) const override; + bool operator==( const FOOTPRINT& aOther ) const; #if defined(DEBUG) virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } diff --git a/pcbnew/pcb_field.cpp b/pcbnew/pcb_field.cpp index 6d8d734400..2344c083df 100644 --- a/pcbnew/pcb_field.cpp +++ b/pcbnew/pcb_field.cpp @@ -218,7 +218,13 @@ bool PCB_FIELD::operator==( const BOARD_ITEM& aOther ) const const PCB_FIELD& other = static_cast( aOther ); - return m_id == other.m_id && m_name == other.m_name && EDA_TEXT::operator==( other ); + return *this == other; +} + + +bool PCB_FIELD::operator==( const PCB_FIELD& aOther ) const +{ + return m_id == aOther.m_id && m_name == aOther.m_name && EDA_TEXT::operator==( aOther ); } diff --git a/pcbnew/pcb_field.h b/pcbnew/pcb_field.h index 9beba7f9c0..c05a3e7595 100644 --- a/pcbnew/pcb_field.h +++ b/pcbnew/pcb_field.h @@ -111,6 +111,7 @@ public: double Similarity( const BOARD_ITEM& aOther ) const override; + bool operator==( const PCB_FIELD& aOther ) const; bool operator==( const BOARD_ITEM& aOther ) const override; protected: diff --git a/pcbnew/pcb_tablecell.cpp b/pcbnew/pcb_tablecell.cpp index 80678e0059..24dbb44e0f 100644 --- a/pcbnew/pcb_tablecell.cpp +++ b/pcbnew/pcb_tablecell.cpp @@ -140,7 +140,6 @@ double PCB_TABLECELL::Similarity( const BOARD_ITEM& aBoardItem ) const return similarity; } - bool PCB_TABLECELL::operator==( const BOARD_ITEM& aBoardItem ) const { if( aBoardItem.Type() != Type() ) @@ -148,9 +147,14 @@ bool PCB_TABLECELL::operator==( const BOARD_ITEM& aBoardItem ) const const PCB_TABLECELL& other = static_cast( aBoardItem ); - return m_colSpan == other.m_colSpan - && m_rowSpan == other.m_rowSpan - && PCB_TEXTBOX::operator==( other ); + return *this == other; +} + +bool PCB_TABLECELL::operator==( const PCB_TABLECELL& aOther ) const +{ + return m_colSpan == aOther.m_colSpan + && m_rowSpan == aOther.m_rowSpan + && PCB_TEXTBOX::operator==( aOther ); } diff --git a/pcbnew/pcb_tablecell.h b/pcbnew/pcb_tablecell.h index e98c9e4dec..c364298ebd 100644 --- a/pcbnew/pcb_tablecell.h +++ b/pcbnew/pcb_tablecell.h @@ -71,6 +71,7 @@ public: double Similarity( const BOARD_ITEM& aBoardItem ) const override; + bool operator==( const PCB_TABLECELL& aBoardItem ) const; bool operator==( const BOARD_ITEM& aBoardItem ) const override; protected: diff --git a/pcbnew/pcb_track.cpp b/pcbnew/pcb_track.cpp index faac0c209d..8aea7bd57b 100644 --- a/pcbnew/pcb_track.cpp +++ b/pcbnew/pcb_track.cpp @@ -163,8 +163,16 @@ bool PCB_TRACK::operator==( const BOARD_ITEM& aOther ) const const PCB_TRACK& other = static_cast( aOther ); - return m_Start == other.m_Start && m_End == other.m_End && m_layer == other.m_layer && - m_Width == other.m_Width; + return *this == other; +} + + +bool PCB_TRACK::operator==( const PCB_TRACK& aOther ) const +{ + return m_Start == aOther.m_Start + && m_End == aOther.m_End + && m_layer == aOther.m_layer + && m_Width == aOther.m_Width; } diff --git a/pcbnew/pcb_track.h b/pcbnew/pcb_track.h index bfda00cb07..6dc4a5afc4 100644 --- a/pcbnew/pcb_track.h +++ b/pcbnew/pcb_track.h @@ -244,6 +244,7 @@ public: virtual double Similarity( const BOARD_ITEM& aOther ) const override; virtual bool operator==( const BOARD_ITEM& aOther ) const override; + virtual bool operator==( const PCB_TRACK& aOther ) const; /** * Set the cached scale. diff --git a/pcbnew/zone.cpp b/pcbnew/zone.cpp index 7b006eeda3..5a96d1b9a7 100644 --- a/pcbnew/zone.cpp +++ b/pcbnew/zone.cpp @@ -1393,53 +1393,58 @@ bool ZONE::operator==( const BOARD_ITEM& aOther ) const return false; const ZONE& other = static_cast( aOther ); + return *this == other; +} - if( GetIsRuleArea() != other.GetIsRuleArea() ) + +bool ZONE::operator==( const ZONE& aOther ) const +{ + if( GetIsRuleArea() != aOther.GetIsRuleArea() ) return false; - if( GetLayerSet() != other.GetLayerSet() ) + if( GetLayerSet() != aOther.GetLayerSet() ) return false; - if( GetNetCode() != other.GetNetCode() ) + if( GetNetCode() != aOther.GetNetCode() ) return false; if( GetIsRuleArea() ) { - if( GetDoNotAllowCopperPour() != other.GetDoNotAllowCopperPour() ) + if( GetDoNotAllowCopperPour() != aOther.GetDoNotAllowCopperPour() ) return false; - if( GetDoNotAllowTracks() != other.GetDoNotAllowTracks() ) + if( GetDoNotAllowTracks() != aOther.GetDoNotAllowTracks() ) return false; - if( GetDoNotAllowVias() != other.GetDoNotAllowVias() ) + if( GetDoNotAllowVias() != aOther.GetDoNotAllowVias() ) return false; - if( GetDoNotAllowFootprints() != other.GetDoNotAllowFootprints() ) + if( GetDoNotAllowFootprints() != aOther.GetDoNotAllowFootprints() ) return false; - if( GetDoNotAllowPads() != other.GetDoNotAllowPads() ) + if( GetDoNotAllowPads() != aOther.GetDoNotAllowPads() ) return false; } else { - if( GetAssignedPriority() != other.GetAssignedPriority() ) + if( GetAssignedPriority() != aOther.GetAssignedPriority() ) return false; - if( GetMinThickness() != other.GetMinThickness() ) + if( GetMinThickness() != aOther.GetMinThickness() ) return false; - if( GetCornerSmoothingType() != other.GetCornerSmoothingType() ) + if( GetCornerSmoothingType() != aOther.GetCornerSmoothingType() ) return false; - if( GetCornerRadius() != other.GetCornerRadius() ) + if( GetCornerRadius() != aOther.GetCornerRadius() ) return false; - if( GetTeardropParams() != other.GetTeardropParams() ) + if( GetTeardropParams() != aOther.GetTeardropParams() ) return false; } - if( GetNumCorners() != other.GetNumCorners() ) + if( GetNumCorners() != aOther.GetNumCorners() ) return false; for( int ii = 0; ii < GetNumCorners(); ii++ ) { - if( GetCornerPosition( ii ) != other.GetCornerPosition( ii ) ) + if( GetCornerPosition( ii ) != aOther.GetCornerPosition( ii ) ) return false; } diff --git a/pcbnew/zone.h b/pcbnew/zone.h index e07ae0d06b..17b4d82981 100644 --- a/pcbnew/zone.h +++ b/pcbnew/zone.h @@ -786,6 +786,7 @@ public: double Similarity( const BOARD_ITEM& aOther ) const override; + bool operator==( const ZONE& aOther ) const; bool operator==( const BOARD_ITEM& aOther ) const override; #if defined(DEBUG)