diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2016-11-09 12:17:04 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2016-11-09 12:17:04 +0100 |
commit | cd61f3eb3df492113883d53e75233afcd6a19fab (patch) | |
tree | 6a0c23ee5ea46e4e4f5689ba7340b7e9f1fce64e /include/tools/gen.hxx | |
parent | e74e9586f506652d18c1096ebc4508fe7f7be344 (diff) |
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
Diffstat (limited to 'include/tools/gen.hxx')
-rw-r--r-- | include/tools/gen.hxx | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/include/tools/gen.hxx b/include/tools/gen.hxx index 987dd4398bc3..142f82cbd6b8 100644 --- a/include/tools/gen.hxx +++ b/include/tools/gen.hxx @@ -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,16 +56,16 @@ protected: long nB; }; -inline bool Pair::operator == ( const Pair& rPair ) const -{ - return ((nA == rPair.nA) && (nB == rPair.nB)); -} +namespace tools { namespace detail { -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 class SAL_WARN_UNUSED SAL_DLLPUBLIC_EXPORT Point : public Pair @@ -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 ) |