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
This commit is contained in:
Marek Roszko 2024-04-12 23:05:00 -04:00
parent 7a67151a22
commit 96cdfc7fa7
17 changed files with 98 additions and 45 deletions

View File

@ -1321,29 +1321,36 @@ bool SCH_FIELD::operator <( const SCH_ITEM& aItem ) const
return GetName() < field->GetName(); 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() ) if( Type() != aOther.Type() )
return false; return false;
const SCH_FIELD& field = static_cast<const SCH_FIELD&>( aOther ); const SCH_FIELD& field = static_cast<const SCH_FIELD&>( aOther );
if( GetId() != field.GetId() ) return *this == field;
}
bool SCH_FIELD::operator==( const SCH_FIELD& aOther ) const
{
if( GetId() != aOther.GetId() )
return false; return false;
if( GetPosition() != field.GetPosition() ) if( GetPosition() != aOther.GetPosition() )
return false; return false;
if( IsNamedVariable() != field.IsNamedVariable() ) if( IsNamedVariable() != aOther.IsNamedVariable() )
return false; return false;
if( IsNameShown() != field.IsNameShown() ) if( IsNameShown() != aOther.IsNameShown() )
return false; return false;
if( CanAutoplace() != field.CanAutoplace() ) if( CanAutoplace() != aOther.CanAutoplace() )
return false; return false;
if( GetText() != field.GetText() ) if( GetText() != aOther.GetText() )
return false; return false;
return true; return true;

View File

@ -284,6 +284,7 @@ public:
double Similarity( const SCH_ITEM& aItem ) const override; double Similarity( const SCH_ITEM& aItem ) const override;
bool operator==( const SCH_ITEM& aItem ) const override; bool operator==( const SCH_ITEM& aItem ) const override;
bool operator==( const SCH_FIELD& aItem ) const;
#if defined(DEBUG) #if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }

View File

@ -165,8 +165,8 @@ void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const
// XML output: // XML output:
wxString s = GetClass(); wxString s = GetClass();
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << wxS( ", " ) << m_diameter NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << ", " << m_diameter
<< wxS( "/>\n" ); << "/>\n";
} }
#endif #endif

View File

@ -494,13 +494,19 @@ bool SCH_PIN::operator==( const SCH_ITEM& aOther ) const
const SCH_PIN& other = static_cast<const SCH_PIN&>( aOther ); const SCH_PIN& other = static_cast<const SCH_PIN&>( 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; return false;
if( m_position != other.m_position ) if( m_position != aOther.m_position )
return false; return false;
return m_libPin == other.m_libPin; return m_libPin == aOther.m_libPin;
} }

View File

@ -169,6 +169,7 @@ public:
double Similarity( const SCH_ITEM& aItem ) const override; double Similarity( const SCH_ITEM& aItem ) const override;
bool operator==( 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 ); } bool operator!=( const SCH_PIN& aRhs ) const { return !( *this == aRhs ); }

View File

@ -162,12 +162,15 @@ bool SCH_TABLECELL::operator==( const SCH_ITEM& aOtherItem ) const
const SCH_TABLECELL& other = static_cast<const SCH_TABLECELL&>( aOtherItem ); const SCH_TABLECELL& other = static_cast<const SCH_TABLECELL&>( aOtherItem );
return m_colSpan == other.m_colSpan return *this == other;
&& m_rowSpan == other.m_rowSpan
&& SCH_TEXTBOX::operator==( 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 static struct SCH_TABLECELL_DESC
{ {

View File

@ -74,6 +74,7 @@ public:
double Similarity( const SCH_ITEM& aOther ) const override; double Similarity( const SCH_ITEM& aOther ) const override;
bool operator==( const SCH_TABLECELL& aOther ) const;
bool operator==( const SCH_ITEM& aOther ) const override; bool operator==( const SCH_ITEM& aOther ) const override;
protected: protected:

View File

@ -3312,39 +3312,45 @@ bool FOOTPRINT::operator==( const BOARD_ITEM& aOther ) const
const FOOTPRINT& other = static_cast<const FOOTPRINT&>( aOther ); const FOOTPRINT& other = static_cast<const FOOTPRINT&>( 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; return false;
for( size_t ii = 0; ii < m_pads.size(); ++ii ) 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; return false;
} }
if( m_drawings.size() != other.m_drawings.size() ) if( m_drawings.size() != aOther.m_drawings.size() )
return false; return false;
for( size_t ii = 0; ii < m_drawings.size(); ++ii ) 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; return false;
} }
if( m_zones.size() != other.m_zones.size() ) if( m_zones.size() != aOther.m_zones.size() )
return false; return false;
for( size_t ii = 0; ii < m_zones.size(); ++ii ) 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; return false;
} }
if( m_fields.size() != other.m_fields.size() ) if( m_fields.size() != aOther.m_fields.size() )
return false; return false;
for( size_t ii = 0; ii < m_fields.size(); ++ii ) 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; return false;
} }

View File

@ -958,6 +958,7 @@ public:
double Similarity( const BOARD_ITEM& aOther ) const override; double Similarity( const BOARD_ITEM& aOther ) const override;
bool operator==( const BOARD_ITEM& aOther ) const override; bool operator==( const BOARD_ITEM& aOther ) const override;
bool operator==( const FOOTPRINT& aOther ) const;
#if defined(DEBUG) #if defined(DEBUG)
virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }

View File

@ -218,7 +218,13 @@ bool PCB_FIELD::operator==( const BOARD_ITEM& aOther ) const
const PCB_FIELD& other = static_cast<const PCB_FIELD&>( aOther ); const PCB_FIELD& other = static_cast<const PCB_FIELD&>( 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 );
} }

View File

@ -111,6 +111,7 @@ public:
double Similarity( const BOARD_ITEM& aOther ) const override; double Similarity( const BOARD_ITEM& aOther ) const override;
bool operator==( const PCB_FIELD& aOther ) const;
bool operator==( const BOARD_ITEM& aOther ) const override; bool operator==( const BOARD_ITEM& aOther ) const override;
protected: protected:

View File

@ -140,7 +140,6 @@ double PCB_TABLECELL::Similarity( const BOARD_ITEM& aBoardItem ) const
return similarity; return similarity;
} }
bool PCB_TABLECELL::operator==( const BOARD_ITEM& aBoardItem ) const bool PCB_TABLECELL::operator==( const BOARD_ITEM& aBoardItem ) const
{ {
if( aBoardItem.Type() != Type() ) if( aBoardItem.Type() != Type() )
@ -148,9 +147,14 @@ bool PCB_TABLECELL::operator==( const BOARD_ITEM& aBoardItem ) const
const PCB_TABLECELL& other = static_cast<const PCB_TABLECELL&>( aBoardItem ); const PCB_TABLECELL& other = static_cast<const PCB_TABLECELL&>( aBoardItem );
return m_colSpan == other.m_colSpan return *this == other;
&& m_rowSpan == other.m_rowSpan }
&& PCB_TEXTBOX::operator==( 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 );
} }

View File

@ -71,6 +71,7 @@ public:
double Similarity( const BOARD_ITEM& aBoardItem ) const override; double Similarity( const BOARD_ITEM& aBoardItem ) const override;
bool operator==( const PCB_TABLECELL& aBoardItem ) const;
bool operator==( const BOARD_ITEM& aBoardItem ) const override; bool operator==( const BOARD_ITEM& aBoardItem ) const override;
protected: protected:

View File

@ -163,8 +163,16 @@ bool PCB_TRACK::operator==( const BOARD_ITEM& aOther ) const
const PCB_TRACK& other = static_cast<const PCB_TRACK&>( aOther ); const PCB_TRACK& other = static_cast<const PCB_TRACK&>( aOther );
return m_Start == other.m_Start && m_End == other.m_End && m_layer == other.m_layer && return *this == other;
m_Width == other.m_Width; }
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;
} }

View File

@ -244,6 +244,7 @@ public:
virtual double Similarity( const BOARD_ITEM& aOther ) const override; virtual double Similarity( const BOARD_ITEM& aOther ) const override;
virtual bool operator==( 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. * Set the cached scale.

View File

@ -1393,53 +1393,58 @@ bool ZONE::operator==( const BOARD_ITEM& aOther ) const
return false; return false;
const ZONE& other = static_cast<const ZONE&>( aOther ); const ZONE& other = static_cast<const ZONE&>( aOther );
return *this == other;
}
if( GetIsRuleArea() != other.GetIsRuleArea() )
bool ZONE::operator==( const ZONE& aOther ) const
{
if( GetIsRuleArea() != aOther.GetIsRuleArea() )
return false; return false;
if( GetLayerSet() != other.GetLayerSet() ) if( GetLayerSet() != aOther.GetLayerSet() )
return false; return false;
if( GetNetCode() != other.GetNetCode() ) if( GetNetCode() != aOther.GetNetCode() )
return false; return false;
if( GetIsRuleArea() ) if( GetIsRuleArea() )
{ {
if( GetDoNotAllowCopperPour() != other.GetDoNotAllowCopperPour() ) if( GetDoNotAllowCopperPour() != aOther.GetDoNotAllowCopperPour() )
return false; return false;
if( GetDoNotAllowTracks() != other.GetDoNotAllowTracks() ) if( GetDoNotAllowTracks() != aOther.GetDoNotAllowTracks() )
return false; return false;
if( GetDoNotAllowVias() != other.GetDoNotAllowVias() ) if( GetDoNotAllowVias() != aOther.GetDoNotAllowVias() )
return false; return false;
if( GetDoNotAllowFootprints() != other.GetDoNotAllowFootprints() ) if( GetDoNotAllowFootprints() != aOther.GetDoNotAllowFootprints() )
return false; return false;
if( GetDoNotAllowPads() != other.GetDoNotAllowPads() ) if( GetDoNotAllowPads() != aOther.GetDoNotAllowPads() )
return false; return false;
} }
else else
{ {
if( GetAssignedPriority() != other.GetAssignedPriority() ) if( GetAssignedPriority() != aOther.GetAssignedPriority() )
return false; return false;
if( GetMinThickness() != other.GetMinThickness() ) if( GetMinThickness() != aOther.GetMinThickness() )
return false; return false;
if( GetCornerSmoothingType() != other.GetCornerSmoothingType() ) if( GetCornerSmoothingType() != aOther.GetCornerSmoothingType() )
return false; return false;
if( GetCornerRadius() != other.GetCornerRadius() ) if( GetCornerRadius() != aOther.GetCornerRadius() )
return false; return false;
if( GetTeardropParams() != other.GetTeardropParams() ) if( GetTeardropParams() != aOther.GetTeardropParams() )
return false; return false;
} }
if( GetNumCorners() != other.GetNumCorners() ) if( GetNumCorners() != aOther.GetNumCorners() )
return false; return false;
for( int ii = 0; ii < GetNumCorners(); ii++ ) for( int ii = 0; ii < GetNumCorners(); ii++ )
{ {
if( GetCornerPosition( ii ) != other.GetCornerPosition( ii ) ) if( GetCornerPosition( ii ) != aOther.GetCornerPosition( ii ) )
return false; return false;
} }

View File

@ -786,6 +786,7 @@ public:
double Similarity( const BOARD_ITEM& aOther ) const override; double Similarity( const BOARD_ITEM& aOther ) const override;
bool operator==( const ZONE& aOther ) const;
bool operator==( const BOARD_ITEM& aOther ) const override; bool operator==( const BOARD_ITEM& aOther ) const override;
#if defined(DEBUG) #if defined(DEBUG)