Make sure not to compare different subclasses of Pair

(A related option would be to make those subclasses derive privately from Pair,
but there are a few places that generically operate on any Pair instances, like
Pair::Read/WritePair or SvxShape::ForceMetricToItemPoolMetric/100th_mm.)

Change-Id: I6c638fe65ee5684593fdeab29b144f547e173f4e
This commit is contained in:
Stephan Bergmann 2016-11-09 12:17:04 +01:00
parent e74e9586f5
commit cd61f3eb3d

View File

@ -48,9 +48,6 @@ public:
long& A() { return nA; }
long& B() { return nB; }
bool operator == ( const Pair& rPair ) const;
bool operator != ( const Pair& rPair ) const;
TOOLS_DLLPUBLIC friend SvStream& ReadPair( SvStream& rIStream, Pair& rPair );
TOOLS_DLLPUBLIC friend SvStream& WritePair( SvStream& rOStream, const Pair& rPair );
@ -59,15 +56,15 @@ protected:
long nB;
};
inline bool Pair::operator == ( const Pair& rPair ) const
namespace tools { namespace detail {
// Used to implement operator == for subclasses of Pair:
inline bool equal(Pair const & p1, Pair const & p2)
{
return ((nA == rPair.nA) && (nB == rPair.nB));
return p1.A() == p2.A() && p1.B() == p2.B();
}
inline bool Pair::operator != ( const Pair& rPair ) const
{
return ((nA != rPair.nA) || (nB != rPair.nB));
}
} }
// Point
@ -158,6 +155,16 @@ inline Point operator/( const Point &rVal1, const long nVal2 )
return Point( rVal1.nA/nVal2, rVal1.nB/nVal2 );
}
inline bool operator ==(Point const & p1, Point const & p2)
{
return tools::detail::equal(p1, p2);
}
inline bool operator !=(Point const & p1, Point const & p2)
{
return !(p1 == p2);
}
template< typename charT, typename traits >
inline std::basic_ostream<charT, traits> & operator <<(
std::basic_ostream<charT, traits> & stream, const Point& point )
@ -185,6 +192,16 @@ public:
void setHeight(long nHeight) { Height() = nHeight; }
};
inline bool operator ==(Size const & s1, Size const & s2)
{
return tools::detail::equal(s1, s2);
}
inline bool operator !=(Size const & s1, Size const & s2)
{
return !(s1 == s2);
}
template< typename charT, typename traits >
inline std::basic_ostream<charT, traits> & operator <<(
std::basic_ostream<charT, traits> & stream, const Size& size )
@ -229,6 +246,16 @@ inline void Range::Justify()
}
}
inline bool operator ==(Range const & r1, Range const & r2)
{
return tools::detail::equal(r1, r2);
}
inline bool operator !=(Range const & r1, Range const & r2)
{
return !(r1 == r2);
}
template< typename charT, typename traits >
inline std::basic_ostream<charT, traits> & operator <<(
std::basic_ostream<charT, traits> & stream, const Range& range )
@ -281,6 +308,16 @@ inline void Selection::Justify()
}
}
inline bool operator ==(Selection const & s1, Selection const & s2)
{
return tools::detail::equal(s1, s2);
}
inline bool operator !=(Selection const & s1, Selection const & s2)
{
return !(s1 == s2);
}
template< typename charT, typename traits >
inline std::basic_ostream<charT, traits> & operator <<(
std::basic_ostream<charT, traits> & stream, const Selection& selection )