diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-01-26 09:50:06 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-03 10:37:51 +0200 |
commit | 8bc951daf79decbd8a599a409c6d33c5456710e0 (patch) | |
tree | 61d220d83e90a176fbcbe667827eee4b9631a4ca /include/tools/gen.hxx | |
parent | 10eefdfa6c0250c6069e641e404f34e5a91fe993 (diff) |
long->sal_Int32 in tools/gen.hxx
which triggered a lot of changes in sw/
Change-Id: Ia2aa22ea3f76463a85ea077a411246fcfed00bf6
Reviewed-on: https://gerrit.libreoffice.org/48806
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/tools/gen.hxx')
-rw-r--r-- | include/tools/gen.hxx | 225 |
1 files changed, 116 insertions, 109 deletions
diff --git a/include/tools/gen.hxx b/include/tools/gen.hxx index 90486536c401..3254d2cba844 100644 --- a/include/tools/gen.hxx +++ b/include/tools/gen.hxx @@ -25,6 +25,7 @@ #include <algorithm> #include <ostream> #include <cstdlib> +#include <cassert> class SvStream; namespace rtl @@ -34,27 +35,30 @@ namespace rtl enum TriState { TRISTATE_FALSE, TRISTATE_TRUE, TRISTATE_INDET }; +#define RECT_MAX (SAL_MAX_INT32) +#define RECT_MIN (SAL_MIN_INT32) + // Pair class SAL_WARN_UNUSED Pair { public: Pair() : nA(0), nB(0) {} - Pair( long _nA, long _nB ) : nA(_nA), nB(_nB) {} + Pair( sal_Int32 _nA, sal_Int32 _nB ) : nA(_nA), nB(_nB) {} - long A() const { return nA; } - long B() const { return nB; } + sal_Int32 A() const { return nA; } + sal_Int32 B() const { return nB; } - long& A() { return nA; } - long& B() { return nB; } + sal_Int32& A() { return nA; } + sal_Int32& B() { return nB; } TOOLS_DLLPUBLIC rtl::OString toString() const; TOOLS_DLLPUBLIC friend SvStream& ReadPair( SvStream& rIStream, Pair& rPair ); TOOLS_DLLPUBLIC friend SvStream& WritePair( SvStream& rOStream, const Pair& rPair ); protected: - long nA; - long nB; + sal_Int32 nA; + sal_Int32 nB; }; namespace tools { namespace detail { @@ -74,33 +78,35 @@ class SAL_WARN_UNUSED SAL_DLLPUBLIC_EXPORT Point final : protected Pair { public: Point() {} - Point( long nX, long nY ) : Pair( nX, nY ) {} + Point( sal_Int32 nX, sal_Int32 nY ) : Pair( nX, nY ) + { + } - long X() const { return nA; } - long Y() const { return nB; } + sal_Int32 X() const { return nA; } + sal_Int32 Y() const { return nB; } - void Move( long nHorzMove, long nVertMove ); + void Move( sal_Int32 nHorzMove, sal_Int32 nVertMove ); void Move( Size const & s ); - long AdjustX( long nHorzMove ) { nA += nHorzMove; return nA; } - long AdjustY( long nVertMove ) { nB += nVertMove; return nB; } + sal_Int32 AdjustX( sal_Int32 nHorzMove ) { nA += nHorzMove; return nA; } + sal_Int32 AdjustY( sal_Int32 nVertMove ) { nB += nVertMove; return nB; } - void RotateAround( long& rX, long& rY, short nOrientation ) const; + void RotateAround( sal_Int32& rX, sal_Int32& rY, short nOrientation ) const; void RotateAround( Point&, short nOrientation ) const; Point& operator += ( const Point& rPoint ); Point& operator -= ( const Point& rPoint ); - Point& operator *= ( const long nVal ); - Point& operator /= ( const long nVal ); + Point& operator *= ( const sal_Int32 nVal ); + Point& operator /= ( const sal_Int32 nVal ); friend inline Point operator+( const Point &rVal1, const Point &rVal2 ); friend inline Point operator-( const Point &rVal1, const Point &rVal2 ); - friend inline Point operator*( const Point &rVal1, const long nVal2 ); - friend inline Point operator/( const Point &rVal1, const long nVal2 ); + friend inline Point operator*( const Point &rVal1, const sal_Int32 nVal2 ); + friend inline Point operator/( const Point &rVal1, const sal_Int32 nVal2 ); - long getX() const { return X(); } - long getY() const { return Y(); } - void setX(long nX) { nA = nX; } - void setY(long nY) { nB = nY; } + sal_Int32 getX() const { return X(); } + sal_Int32 getY() const { return Y(); } + void setX(sal_Int32 nX) { nA = nX; } + void setY(sal_Int32 nY) { nB = nY; } Pair const & toPair() const { return *this; } Pair & toPair() { return *this; } @@ -108,7 +114,7 @@ public: using Pair::toString; }; -inline void Point::Move( long nHorzMove, long nVertMove ) +inline void Point::Move( sal_Int32 nHorzMove, sal_Int32 nVertMove ) { nA += nHorzMove; nB += nVertMove; @@ -128,14 +134,14 @@ inline Point& Point::operator -= ( const Point& rPoint ) return *this; } -inline Point& Point::operator *= ( const long nVal ) +inline Point& Point::operator *= ( const sal_Int32 nVal ) { nA *= nVal; nB *= nVal; return *this; } -inline Point& Point::operator /= ( const long nVal ) +inline Point& Point::operator /= ( const sal_Int32 nVal ) { nA /= nVal; nB /= nVal; @@ -152,12 +158,12 @@ inline Point operator-( const Point &rVal1, const Point &rVal2 ) return Point( rVal1.nA-rVal2.nA, rVal1.nB-rVal2.nB ); } -inline Point operator*( const Point &rVal1, const long nVal2 ) +inline Point operator*( const Point &rVal1, const sal_Int32 nVal2 ) { return Point( rVal1.nA*nVal2, rVal1.nB*nVal2 ); } -inline Point operator/( const Point &rVal1, const long nVal2 ) +inline Point operator/( const Point &rVal1, const sal_Int32 nVal2 ) { return Point( rVal1.nA/nVal2, rVal1.nB/nVal2 ); } @@ -185,18 +191,20 @@ class SAL_WARN_UNUSED Size final : protected Pair { public: Size() {} - Size( long nWidth, long nHeight ) : Pair( nWidth, nHeight ) {} + Size( sal_Int32 nWidth, sal_Int32 nHeight ) : Pair( nWidth, nHeight ) + { + } - long Width() const { return nA; } - long Height() const { return nB; } + sal_Int32 Width() const { return nA; } + sal_Int32 Height() const { return nB; } - long AdjustWidth( long n ) { nA += n; return nA; } - long AdjustHeight( long n ) { nB += n; return nB; } + sal_Int32 AdjustWidth( sal_Int32 n ) { nA += n; return nA; } + sal_Int32 AdjustHeight( sal_Int32 n ) { nB += n; return nB; } - long getWidth() const { return Width(); } - long getHeight() const { return Height(); } - void setWidth(long nWidth) { nA = nWidth; } - void setHeight(long nHeight) { nB = nHeight; } + sal_Int32 getWidth() const { return Width(); } + sal_Int32 getHeight() const { return Height(); } + void setWidth(sal_Int32 nWidth) { nA = nWidth; } + void setHeight(sal_Int32 nHeight) { nB = nHeight; } Pair const & toPair() const { return *this; } Pair & toPair() { return *this; } @@ -229,22 +237,22 @@ inline void Point::Move( Size const & s ) // Range -#define RANGE_MAX LONG_MAX +#define RANGE_MAX SAL_MAX_INT32 class SAL_WARN_UNUSED Range final : protected Pair { public: Range() {} - Range( long nMin, long nMax ) : Pair( nMin, nMax ) {} + Range( sal_Int32 nMin, sal_Int32 nMax ) : Pair( nMin, nMax ) {} - long Min() const { return nA; } - long Max() const { return nB; } - long Len() const { return nB - nA + 1; } + sal_Int32 Min() const { return nA; } + sal_Int32 Max() const { return nB; } + sal_Int32 Len() const { return nB - nA + 1; } - long& Min() { return nA; } - long& Max() { return nB; } + sal_Int32& Min() { return nA; } + sal_Int32& Max() { return nB; } - bool IsInside( long nIs ) const; + bool IsInside( sal_Int32 nIs ) const; void Justify(); @@ -254,7 +262,7 @@ public: using Pair::toString; }; -inline bool Range::IsInside( long nIs ) const +inline bool Range::IsInside( sal_Int32 nIs ) const { return ((nA <= nIs) && (nIs <= nB )); } @@ -263,7 +271,7 @@ inline void Range::Justify() { if ( nA > nB ) { - long nHelp = nA; + sal_Int32 nHelp = nA; nA = nB; nB = nHelp; } @@ -288,32 +296,32 @@ inline std::basic_ostream<charT, traits> & operator <<( // Selection -#define SELECTION_MIN LONG_MIN -#define SELECTION_MAX LONG_MAX +#define SELECTION_MIN SAL_MIN_INT32 +#define SELECTION_MAX SAL_MAX_INT32 class SAL_WARN_UNUSED Selection final : protected Pair { public: Selection() {} - Selection( long nPos ) : Pair( nPos, nPos ) {} - Selection( long nMin, long nMax ) : Pair( nMin, nMax ) {} + Selection( sal_Int32 nPos ) : Pair( nPos, nPos ) {} + Selection( sal_Int32 nMin, sal_Int32 nMax ) : Pair( nMin, nMax ) {} - long Min() const { return nA; } - long Max() const { return nB; } - long Len() const { return nB - nA; } + sal_Int32 Min() const { return nA; } + sal_Int32 Max() const { return nB; } + sal_Int32 Len() const { return nB - nA; } - long& Min() { return nA; } - long& Max() { return nB; } + sal_Int32& Min() { return nA; } + sal_Int32& Max() { return nB; } - bool IsInside( long nIs ) const; + bool IsInside( sal_Int32 nIs ) const; void Justify(); bool operator !() const { return !Len(); } - long getMin() const { return Min(); } - void setMin(long nMin) { Min() = nMin; } - void setMax(long nMax) { Max() = nMax; } + sal_Int32 getMin() const { return Min(); } + void setMin(sal_Int32 nMin) { Min() = nMin; } + void setMax(sal_Int32 nMax) { Max() = nMax; } Pair const & toPair() const { return *this; } Pair & toPair() { return *this; } @@ -321,7 +329,7 @@ public: using Pair::toString; }; -inline bool Selection::IsInside( long nIs ) const +inline bool Selection::IsInside( sal_Int32 nIs ) const { return ((nA <= nIs) && (nIs < nB )); } @@ -330,7 +338,7 @@ inline void Selection::Justify() { if ( nA > nB ) { - long nHelp = nA; + sal_Int32 nHelp = nA; nA = nB; nB = nHelp; } @@ -354,9 +362,6 @@ inline std::basic_ostream<charT, traits> & operator <<( } // Rectangle -#define RECT_MAX LONG_MAX -#define RECT_MIN LONG_MIN - /// Note: this class is a true marvel of engineering: because the author /// could not decide whether it's better to have a closed or half-open /// interval, they just implemented *both* in the same class! @@ -368,27 +373,28 @@ inline std::basic_ostream<charT, traits> & operator <<( /// Ok, now is the time for despair. namespace tools { + class SAL_WARN_UNUSED TOOLS_DLLPUBLIC Rectangle final { - static constexpr short RECT_EMPTY = -32767; + static constexpr sal_Int32 RECT_EMPTY = -32767; public: Rectangle(); Rectangle( const Point& rLT, const Point& rRB ); - Rectangle( long nLeft, long nTop, - long nRight, long nBottom ); + Rectangle( sal_Int32 nLeft, sal_Int32 nTop, + sal_Int32 nRight, sal_Int32 nBottom ); /// Constructs an empty Rectangle, with top/left at the specified params - Rectangle( long nLeft, long nTop ); + Rectangle( sal_Int32 nLeft, sal_Int32 nTop ); Rectangle( const Point& rLT, const Size& rSize ); - long Left() const { return nLeft; } - long Right() const { return nRight; } - long Top() const { return nTop; } - long Bottom() const { return nBottom; } + sal_Int32 Left() const { return nLeft; } + sal_Int32 Right() const { return nRight; } + sal_Int32 Top() const { return nTop; } + sal_Int32 Bottom() const { return nBottom; } - void SetLeft(long v) { nLeft = v; } - void SetRight(long v) { nRight = v; } - void SetTop(long v) { nTop = v; } - void SetBottom(long v) { nBottom = v; } + void SetLeft(sal_Int32 v) { nLeft = v; } + void SetRight(sal_Int32 v) { nRight = v; } + void SetTop(sal_Int32 v) { nTop = v; } + void SetBottom(sal_Int32 v) { nBottom = v; } inline Point TopLeft() const; inline Point TopRight() const; @@ -401,20 +407,21 @@ public: inline Point Center() const; /// Move the top and left edges by a delta, preserving width and height - inline void Move( long nHorzMoveDelta, long nVertMoveDelta ); + inline void Move( sal_Int32 nHorzMoveDelta, sal_Int32 nVertMoveDelta ); void Move( Size const & s ) { Move(s.Width(), s.Height()); } - long AdjustLeft( long nHorzMoveDelta ) { nLeft += nHorzMoveDelta; return nLeft; } - long AdjustRight( long nHorzMoveDelta ) { nRight += nHorzMoveDelta; return nRight; } - long AdjustTop( long nVertMoveDelta ) { nTop += nVertMoveDelta; return nTop; } - long AdjustBottom( long nVertMoveDelta ) { nBottom += nVertMoveDelta; return nBottom; } + sal_Int32 AdjustLeft( sal_Int32 nHorzMoveDelta ) { nLeft += nHorzMoveDelta; return nLeft; } + sal_Int32 AdjustRight( sal_Int32 nHorzMoveDelta ) { nRight += nHorzMoveDelta; return nRight; } + sal_Int32 AdjustTop( sal_Int32 nVertMoveDelta ) { nTop += nVertMoveDelta; return nTop; } + sal_Int32 AdjustBottom( sal_Int32 nVertMoveDelta ) { nBottom += nVertMoveDelta; return nBottom; } + inline void SetPos( const Point& rPoint ); void SetSize( const Size& rSize ); inline Size GetSize() const; /// Returns the difference between right and left, assuming the range is inclusive. - inline long GetWidth() const; + inline sal_Int32 GetWidth() const; /// Returns the difference between bottom and top, assuming the range is inclusive. - inline long GetHeight() const; + inline sal_Int32 GetHeight() const; tools::Rectangle& Union( const tools::Rectangle& rRect ); tools::Rectangle& Intersection( const tools::Rectangle& rRect ); @@ -447,39 +454,39 @@ public: TOOLS_DLLPUBLIC friend SvStream& WriteRectangle( SvStream& rOStream, const tools::Rectangle& rRect ); // ONE - long getX() const { return nLeft; } - long getY() const { return nTop; } + sal_Int32 getX() const { return nLeft; } + sal_Int32 getY() const { return nTop; } /// Returns the difference between right and left, assuming the range includes one end, but not the other. - long getWidth() const { return nRight - nLeft; } + sal_Int32 getWidth() const { return nRight - nLeft; } /// Returns the difference between bottom and top, assuming the range includes one end, but not the other. - long getHeight() const { return nBottom - nTop; } + sal_Int32 getHeight() const { return nBottom - nTop; } /// Set the left edge of the rectangle to x, preserving the width - void setX( long x ) { nRight += x - nLeft; nLeft = x; } + void setX( sal_Int32 x ) { nRight += x - nLeft; nLeft = x; } /// Set the top edge of the rectangle to y, preserving the height - void setY( long y ) { nBottom += y - nTop; nTop = y; } - void setWidth( long n ) { nRight = nLeft + n; } - void setHeight( long n ) { nBottom = nTop + n; } + void setY( sal_Int32 y ) { nBottom += y - nTop; nTop = y; } + void setWidth( sal_Int32 n ) { nRight = nLeft + n; } + void setHeight( sal_Int32 n ) { nBottom = nTop + n; } /// Returns the string representation of the rectangle, format is "x, y, width, height". rtl::OString toString() const; /** * Expands the rectangle in all directions by the input value. */ - inline void expand(long nExpandBy); - inline void shrink(long nShrinkBy); + inline void expand(sal_Int32 nExpandBy); + inline void shrink(sal_Int32 nShrinkBy); /** * Sanitizing variants for handling data from the outside */ void SaturatingSetSize(const Size& rSize); - void SaturatingSetX(long x); - void SaturatingSetY(long y); + void SaturatingSetX(sal_Int32 x); + void SaturatingSetY(sal_Int32 y); private: - long nLeft; - long nTop; - long nRight; - long nBottom; + sal_Int32 nLeft; + sal_Int32 nTop; + sal_Int32 nRight; + sal_Int32 nBottom; }; } @@ -497,8 +504,8 @@ inline tools::Rectangle::Rectangle( const Point& rLT, const Point& rRB ) nBottom = rRB.Y(); } -inline tools::Rectangle::Rectangle( long _nLeft, long _nTop, - long _nRight, long _nBottom ) +inline tools::Rectangle::Rectangle( sal_Int32 _nLeft, sal_Int32 _nTop, + sal_Int32 _nRight, sal_Int32 _nBottom ) { nLeft = _nLeft; nTop = _nTop; @@ -506,7 +513,7 @@ inline tools::Rectangle::Rectangle( long _nLeft, long _nTop, nBottom = _nBottom; } -inline tools::Rectangle::Rectangle( long _nLeft, long _nTop ) +inline tools::Rectangle::Rectangle( sal_Int32 _nLeft, sal_Int32 _nTop ) { nLeft = _nLeft; nTop = _nTop; @@ -589,7 +596,7 @@ inline Point tools::Rectangle::Center() const return Point( nLeft+(nRight-nLeft)/2 , nTop+(nBottom-nTop)/2 ); } -inline void tools::Rectangle::Move( long nHorzMove, long nVertMove ) +inline void tools::Rectangle::Move( sal_Int32 nHorzMove, sal_Int32 nVertMove ) { nLeft += nHorzMove; nTop += nVertMove; @@ -609,9 +616,9 @@ inline void tools::Rectangle::SetPos( const Point& rPoint ) nTop = rPoint.Y(); } -inline long tools::Rectangle::GetWidth() const +inline sal_Int32 tools::Rectangle::GetWidth() const { - long n; + sal_Int32 n; if ( nRight == RECT_EMPTY ) n = 0; else @@ -626,9 +633,9 @@ inline long tools::Rectangle::GetWidth() const return n; } -inline long tools::Rectangle::GetHeight() const +inline sal_Int32 tools::Rectangle::GetHeight() const { - long n; + sal_Int32 n; if ( nBottom == RECT_EMPTY ) n = 0; else @@ -717,7 +724,7 @@ inline Rectangle operator - ( const Rectangle& rRect, const Point& rPt ) } } -inline void tools::Rectangle::expand(long nExpandBy) +inline void tools::Rectangle::expand(sal_Int32 nExpandBy) { nLeft -= nExpandBy; nTop -= nExpandBy; @@ -725,7 +732,7 @@ inline void tools::Rectangle::expand(long nExpandBy) nBottom += nExpandBy; } -inline void tools::Rectangle::shrink(long nShrinkBy) +inline void tools::Rectangle::shrink(sal_Int32 nShrinkBy) { nLeft += nShrinkBy; nTop += nShrinkBy; |