Kaydet (Commit) cd61f3eb authored tarafından Stephan Bergmann's avatar Stephan Bergmann

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
üst e74e9586
...@@ -48,9 +48,6 @@ public: ...@@ -48,9 +48,6 @@ public:
long& A() { return nA; } long& A() { return nA; }
long& B() { return nB; } 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& ReadPair( SvStream& rIStream, Pair& rPair );
TOOLS_DLLPUBLIC friend SvStream& WritePair( SvStream& rOStream, const Pair& rPair ); TOOLS_DLLPUBLIC friend SvStream& WritePair( SvStream& rOStream, const Pair& rPair );
...@@ -59,16 +56,16 @@ protected: ...@@ -59,16 +56,16 @@ protected:
long nB; long nB;
}; };
inline bool Pair::operator == ( const Pair& rPair ) const namespace tools { namespace detail {
{
return ((nA == rPair.nA) && (nB == rPair.nB));
}
inline bool Pair::operator != ( const Pair& rPair ) const // 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();
} }
} }
// Point // Point
class SAL_WARN_UNUSED SAL_DLLPUBLIC_EXPORT Point : public Pair class SAL_WARN_UNUSED SAL_DLLPUBLIC_EXPORT Point : public Pair
...@@ -158,6 +155,16 @@ inline Point operator/( const Point &rVal1, const long nVal2 ) ...@@ -158,6 +155,16 @@ inline Point operator/( const Point &rVal1, const long nVal2 )
return Point( rVal1.nA/nVal2, rVal1.nB/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 > template< typename charT, typename traits >
inline std::basic_ostream<charT, traits> & operator <<( inline std::basic_ostream<charT, traits> & operator <<(
std::basic_ostream<charT, traits> & stream, const Point& point ) std::basic_ostream<charT, traits> & stream, const Point& point )
...@@ -185,6 +192,16 @@ public: ...@@ -185,6 +192,16 @@ public:
void setHeight(long nHeight) { Height() = nHeight; } 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 > template< typename charT, typename traits >
inline std::basic_ostream<charT, traits> & operator <<( inline std::basic_ostream<charT, traits> & operator <<(
std::basic_ostream<charT, traits> & stream, const Size& size ) std::basic_ostream<charT, traits> & stream, const Size& size )
...@@ -229,6 +246,16 @@ inline void Range::Justify() ...@@ -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 > template< typename charT, typename traits >
inline std::basic_ostream<charT, traits> & operator <<( inline std::basic_ostream<charT, traits> & operator <<(
std::basic_ostream<charT, traits> & stream, const Range& range ) std::basic_ostream<charT, traits> & stream, const Range& range )
...@@ -281,6 +308,16 @@ inline void Selection::Justify() ...@@ -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 > template< typename charT, typename traits >
inline std::basic_ostream<charT, traits> & operator <<( inline std::basic_ostream<charT, traits> & operator <<(
std::basic_ostream<charT, traits> & stream, const Selection& selection ) std::basic_ostream<charT, traits> & stream, const Selection& selection )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment