summaryrefslogtreecommitdiff
path: root/include/tools
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2018-04-07 11:45:13 +0200
committerStephan Bergmann <sbergman@redhat.com>2018-04-07 14:13:18 +0200
commitd36f7c5bd2115fcdd26ba8ff7b6a0446dea70bd4 (patch)
tree5ae4b15f3302a538ac55d714ba0529ca4c1de87a /include/tools
parent61d57bcebd1a246603cbcd9ad5e0a7df1a8d66cd (diff)
Revert "long->sal_Int32 in tools/gen.hxx"
This reverts commit 8bc951daf79decbd8a599a409c6d33c5456710e0. As discussed at <https://lists.freedesktop.org/archives/libreoffice/2018-April/079955.html> "long->sal_Int32 in tools/gen.hxx", that commit caused lots of problems with signed integer overflow, and the original plan was to redo it to consistently use sal_Int64 instead of sal_Int32. <https://gerrit.libreoffice.org/#/c/52471/> "sal_Int32->sal_Int64 in tools/gen.hxx" tried that. However, it failed miserably on Windows, causing odd failures like not writing out Pictures/*.svm streams out into .odp during CppunitTest_sd_export_ooxml2. So the next best approach is to just revert the original commit, at least for now. Includes revert of follow-up 8c50aff2175e85c54957d98ce32af40a3a87e168 "Fix Library_vclplug_qt5". Change-Id: Ia8bf34272d1ed38aac00e5d07a9d13fb03f439ae Reviewed-on: https://gerrit.libreoffice.org/52532 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include/tools')
-rw-r--r--include/tools/gen.hxx225
1 files changed, 109 insertions, 116 deletions
diff --git a/include/tools/gen.hxx b/include/tools/gen.hxx
index 3254d2cba844..90486536c401 100644
--- a/include/tools/gen.hxx
+++ b/include/tools/gen.hxx
@@ -25,7 +25,6 @@
#include <algorithm>
#include <ostream>
#include <cstdlib>
-#include <cassert>
class SvStream;
namespace rtl
@@ -35,30 +34,27 @@ 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( sal_Int32 _nA, sal_Int32 _nB ) : nA(_nA), nB(_nB) {}
+ Pair( long _nA, long _nB ) : nA(_nA), nB(_nB) {}
- sal_Int32 A() const { return nA; }
- sal_Int32 B() const { return nB; }
+ long A() const { return nA; }
+ long B() const { return nB; }
- sal_Int32& A() { return nA; }
- sal_Int32& B() { return nB; }
+ long& A() { return nA; }
+ long& 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:
- sal_Int32 nA;
- sal_Int32 nB;
+ long nA;
+ long nB;
};
namespace tools { namespace detail {
@@ -78,35 +74,33 @@ class SAL_WARN_UNUSED SAL_DLLPUBLIC_EXPORT Point final : protected Pair
{
public:
Point() {}
- Point( sal_Int32 nX, sal_Int32 nY ) : Pair( nX, nY )
- {
- }
+ Point( long nX, long nY ) : Pair( nX, nY ) {}
- sal_Int32 X() const { return nA; }
- sal_Int32 Y() const { return nB; }
+ long X() const { return nA; }
+ long Y() const { return nB; }
- void Move( sal_Int32 nHorzMove, sal_Int32 nVertMove );
+ void Move( long nHorzMove, long nVertMove );
void Move( Size const & s );
- sal_Int32 AdjustX( sal_Int32 nHorzMove ) { nA += nHorzMove; return nA; }
- sal_Int32 AdjustY( sal_Int32 nVertMove ) { nB += nVertMove; return nB; }
+ long AdjustX( long nHorzMove ) { nA += nHorzMove; return nA; }
+ long AdjustY( long nVertMove ) { nB += nVertMove; return nB; }
- void RotateAround( sal_Int32& rX, sal_Int32& rY, short nOrientation ) const;
+ void RotateAround( long& rX, long& rY, short nOrientation ) const;
void RotateAround( Point&, short nOrientation ) const;
Point& operator += ( const Point& rPoint );
Point& operator -= ( const Point& rPoint );
- Point& operator *= ( const sal_Int32 nVal );
- Point& operator /= ( const sal_Int32 nVal );
+ Point& operator *= ( const long nVal );
+ Point& operator /= ( const long 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 sal_Int32 nVal2 );
- friend inline Point operator/( const Point &rVal1, const sal_Int32 nVal2 );
+ friend inline Point operator*( const Point &rVal1, const long nVal2 );
+ friend inline Point operator/( const Point &rVal1, const long nVal2 );
- 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; }
+ long getX() const { return X(); }
+ long getY() const { return Y(); }
+ void setX(long nX) { nA = nX; }
+ void setY(long nY) { nB = nY; }
Pair const & toPair() const { return *this; }
Pair & toPair() { return *this; }
@@ -114,7 +108,7 @@ public:
using Pair::toString;
};
-inline void Point::Move( sal_Int32 nHorzMove, sal_Int32 nVertMove )
+inline void Point::Move( long nHorzMove, long nVertMove )
{
nA += nHorzMove;
nB += nVertMove;
@@ -134,14 +128,14 @@ inline Point& Point::operator -= ( const Point& rPoint )
return *this;
}
-inline Point& Point::operator *= ( const sal_Int32 nVal )
+inline Point& Point::operator *= ( const long nVal )
{
nA *= nVal;
nB *= nVal;
return *this;
}
-inline Point& Point::operator /= ( const sal_Int32 nVal )
+inline Point& Point::operator /= ( const long nVal )
{
nA /= nVal;
nB /= nVal;
@@ -158,12 +152,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 sal_Int32 nVal2 )
+inline Point operator*( const Point &rVal1, const long nVal2 )
{
return Point( rVal1.nA*nVal2, rVal1.nB*nVal2 );
}
-inline Point operator/( const Point &rVal1, const sal_Int32 nVal2 )
+inline Point operator/( const Point &rVal1, const long nVal2 )
{
return Point( rVal1.nA/nVal2, rVal1.nB/nVal2 );
}
@@ -191,20 +185,18 @@ class SAL_WARN_UNUSED Size final : protected Pair
{
public:
Size() {}
- Size( sal_Int32 nWidth, sal_Int32 nHeight ) : Pair( nWidth, nHeight )
- {
- }
+ Size( long nWidth, long nHeight ) : Pair( nWidth, nHeight ) {}
- sal_Int32 Width() const { return nA; }
- sal_Int32 Height() const { return nB; }
+ long Width() const { return nA; }
+ long Height() const { return nB; }
- sal_Int32 AdjustWidth( sal_Int32 n ) { nA += n; return nA; }
- sal_Int32 AdjustHeight( sal_Int32 n ) { nB += n; return nB; }
+ long AdjustWidth( long n ) { nA += n; return nA; }
+ long AdjustHeight( long n ) { nB += n; return nB; }
- 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; }
+ long getWidth() const { return Width(); }
+ long getHeight() const { return Height(); }
+ void setWidth(long nWidth) { nA = nWidth; }
+ void setHeight(long nHeight) { nB = nHeight; }
Pair const & toPair() const { return *this; }
Pair & toPair() { return *this; }
@@ -237,22 +229,22 @@ inline void Point::Move( Size const & s )
// Range
-#define RANGE_MAX SAL_MAX_INT32
+#define RANGE_MAX LONG_MAX
class SAL_WARN_UNUSED Range final : protected Pair
{
public:
Range() {}
- Range( sal_Int32 nMin, sal_Int32 nMax ) : Pair( nMin, nMax ) {}
+ Range( long nMin, long nMax ) : Pair( nMin, nMax ) {}
- sal_Int32 Min() const { return nA; }
- sal_Int32 Max() const { return nB; }
- sal_Int32 Len() const { return nB - nA + 1; }
+ long Min() const { return nA; }
+ long Max() const { return nB; }
+ long Len() const { return nB - nA + 1; }
- sal_Int32& Min() { return nA; }
- sal_Int32& Max() { return nB; }
+ long& Min() { return nA; }
+ long& Max() { return nB; }
- bool IsInside( sal_Int32 nIs ) const;
+ bool IsInside( long nIs ) const;
void Justify();
@@ -262,7 +254,7 @@ public:
using Pair::toString;
};
-inline bool Range::IsInside( sal_Int32 nIs ) const
+inline bool Range::IsInside( long nIs ) const
{
return ((nA <= nIs) && (nIs <= nB ));
}
@@ -271,7 +263,7 @@ inline void Range::Justify()
{
if ( nA > nB )
{
- sal_Int32 nHelp = nA;
+ long nHelp = nA;
nA = nB;
nB = nHelp;
}
@@ -296,32 +288,32 @@ inline std::basic_ostream<charT, traits> & operator <<(
// Selection
-#define SELECTION_MIN SAL_MIN_INT32
-#define SELECTION_MAX SAL_MAX_INT32
+#define SELECTION_MIN LONG_MIN
+#define SELECTION_MAX LONG_MAX
class SAL_WARN_UNUSED Selection final : protected Pair
{
public:
Selection() {}
- Selection( sal_Int32 nPos ) : Pair( nPos, nPos ) {}
- Selection( sal_Int32 nMin, sal_Int32 nMax ) : Pair( nMin, nMax ) {}
+ Selection( long nPos ) : Pair( nPos, nPos ) {}
+ Selection( long nMin, long nMax ) : Pair( nMin, nMax ) {}
- sal_Int32 Min() const { return nA; }
- sal_Int32 Max() const { return nB; }
- sal_Int32 Len() const { return nB - nA; }
+ long Min() const { return nA; }
+ long Max() const { return nB; }
+ long Len() const { return nB - nA; }
- sal_Int32& Min() { return nA; }
- sal_Int32& Max() { return nB; }
+ long& Min() { return nA; }
+ long& Max() { return nB; }
- bool IsInside( sal_Int32 nIs ) const;
+ bool IsInside( long nIs ) const;
void Justify();
bool operator !() const { return !Len(); }
- sal_Int32 getMin() const { return Min(); }
- void setMin(sal_Int32 nMin) { Min() = nMin; }
- void setMax(sal_Int32 nMax) { Max() = nMax; }
+ long getMin() const { return Min(); }
+ void setMin(long nMin) { Min() = nMin; }
+ void setMax(long nMax) { Max() = nMax; }
Pair const & toPair() const { return *this; }
Pair & toPair() { return *this; }
@@ -329,7 +321,7 @@ public:
using Pair::toString;
};
-inline bool Selection::IsInside( sal_Int32 nIs ) const
+inline bool Selection::IsInside( long nIs ) const
{
return ((nA <= nIs) && (nIs < nB ));
}
@@ -338,7 +330,7 @@ inline void Selection::Justify()
{
if ( nA > nB )
{
- sal_Int32 nHelp = nA;
+ long nHelp = nA;
nA = nB;
nB = nHelp;
}
@@ -362,6 +354,9 @@ 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!
@@ -373,28 +368,27 @@ 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 sal_Int32 RECT_EMPTY = -32767;
+ static constexpr short RECT_EMPTY = -32767;
public:
Rectangle();
Rectangle( const Point& rLT, const Point& rRB );
- Rectangle( sal_Int32 nLeft, sal_Int32 nTop,
- sal_Int32 nRight, sal_Int32 nBottom );
+ Rectangle( long nLeft, long nTop,
+ long nRight, long nBottom );
/// Constructs an empty Rectangle, with top/left at the specified params
- Rectangle( sal_Int32 nLeft, sal_Int32 nTop );
+ Rectangle( long nLeft, long nTop );
Rectangle( const Point& rLT, const Size& rSize );
- sal_Int32 Left() const { return nLeft; }
- sal_Int32 Right() const { return nRight; }
- sal_Int32 Top() const { return nTop; }
- sal_Int32 Bottom() const { return nBottom; }
+ long Left() const { return nLeft; }
+ long Right() const { return nRight; }
+ long Top() const { return nTop; }
+ long Bottom() const { return nBottom; }
- 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; }
+ void SetLeft(long v) { nLeft = v; }
+ void SetRight(long v) { nRight = v; }
+ void SetTop(long v) { nTop = v; }
+ void SetBottom(long v) { nBottom = v; }
inline Point TopLeft() const;
inline Point TopRight() const;
@@ -407,21 +401,20 @@ public:
inline Point Center() const;
/// Move the top and left edges by a delta, preserving width and height
- inline void Move( sal_Int32 nHorzMoveDelta, sal_Int32 nVertMoveDelta );
+ inline void Move( long nHorzMoveDelta, long nVertMoveDelta );
void Move( Size const & s ) { Move(s.Width(), s.Height()); }
- 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; }
-
+ 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; }
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 sal_Int32 GetWidth() const;
+ inline long GetWidth() const;
/// Returns the difference between bottom and top, assuming the range is inclusive.
- inline sal_Int32 GetHeight() const;
+ inline long GetHeight() const;
tools::Rectangle& Union( const tools::Rectangle& rRect );
tools::Rectangle& Intersection( const tools::Rectangle& rRect );
@@ -454,39 +447,39 @@ public:
TOOLS_DLLPUBLIC friend SvStream& WriteRectangle( SvStream& rOStream, const tools::Rectangle& rRect );
// ONE
- sal_Int32 getX() const { return nLeft; }
- sal_Int32 getY() const { return nTop; }
+ long getX() const { return nLeft; }
+ long getY() const { return nTop; }
/// Returns the difference between right and left, assuming the range includes one end, but not the other.
- sal_Int32 getWidth() const { return nRight - nLeft; }
+ long getWidth() const { return nRight - nLeft; }
/// Returns the difference between bottom and top, assuming the range includes one end, but not the other.
- sal_Int32 getHeight() const { return nBottom - nTop; }
+ long getHeight() const { return nBottom - nTop; }
/// Set the left edge of the rectangle to x, preserving the width
- void setX( sal_Int32 x ) { nRight += x - nLeft; nLeft = x; }
+ void setX( long x ) { nRight += x - nLeft; nLeft = x; }
/// Set the top edge of the rectangle to y, preserving the height
- 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; }
+ void setY( long y ) { nBottom += y - nTop; nTop = y; }
+ void setWidth( long n ) { nRight = nLeft + n; }
+ void setHeight( long 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(sal_Int32 nExpandBy);
- inline void shrink(sal_Int32 nShrinkBy);
+ inline void expand(long nExpandBy);
+ inline void shrink(long nShrinkBy);
/**
* Sanitizing variants for handling data from the outside
*/
void SaturatingSetSize(const Size& rSize);
- void SaturatingSetX(sal_Int32 x);
- void SaturatingSetY(sal_Int32 y);
+ void SaturatingSetX(long x);
+ void SaturatingSetY(long y);
private:
- sal_Int32 nLeft;
- sal_Int32 nTop;
- sal_Int32 nRight;
- sal_Int32 nBottom;
+ long nLeft;
+ long nTop;
+ long nRight;
+ long nBottom;
};
}
@@ -504,8 +497,8 @@ inline tools::Rectangle::Rectangle( const Point& rLT, const Point& rRB )
nBottom = rRB.Y();
}
-inline tools::Rectangle::Rectangle( sal_Int32 _nLeft, sal_Int32 _nTop,
- sal_Int32 _nRight, sal_Int32 _nBottom )
+inline tools::Rectangle::Rectangle( long _nLeft, long _nTop,
+ long _nRight, long _nBottom )
{
nLeft = _nLeft;
nTop = _nTop;
@@ -513,7 +506,7 @@ inline tools::Rectangle::Rectangle( sal_Int32 _nLeft, sal_Int32 _nTop,
nBottom = _nBottom;
}
-inline tools::Rectangle::Rectangle( sal_Int32 _nLeft, sal_Int32 _nTop )
+inline tools::Rectangle::Rectangle( long _nLeft, long _nTop )
{
nLeft = _nLeft;
nTop = _nTop;
@@ -596,7 +589,7 @@ inline Point tools::Rectangle::Center() const
return Point( nLeft+(nRight-nLeft)/2 , nTop+(nBottom-nTop)/2 );
}
-inline void tools::Rectangle::Move( sal_Int32 nHorzMove, sal_Int32 nVertMove )
+inline void tools::Rectangle::Move( long nHorzMove, long nVertMove )
{
nLeft += nHorzMove;
nTop += nVertMove;
@@ -616,9 +609,9 @@ inline void tools::Rectangle::SetPos( const Point& rPoint )
nTop = rPoint.Y();
}
-inline sal_Int32 tools::Rectangle::GetWidth() const
+inline long tools::Rectangle::GetWidth() const
{
- sal_Int32 n;
+ long n;
if ( nRight == RECT_EMPTY )
n = 0;
else
@@ -633,9 +626,9 @@ inline sal_Int32 tools::Rectangle::GetWidth() const
return n;
}
-inline sal_Int32 tools::Rectangle::GetHeight() const
+inline long tools::Rectangle::GetHeight() const
{
- sal_Int32 n;
+ long n;
if ( nBottom == RECT_EMPTY )
n = 0;
else
@@ -724,7 +717,7 @@ inline Rectangle operator - ( const Rectangle& rRect, const Point& rPt )
}
}
-inline void tools::Rectangle::expand(sal_Int32 nExpandBy)
+inline void tools::Rectangle::expand(long nExpandBy)
{
nLeft -= nExpandBy;
nTop -= nExpandBy;
@@ -732,7 +725,7 @@ inline void tools::Rectangle::expand(sal_Int32 nExpandBy)
nBottom += nExpandBy;
}
-inline void tools::Rectangle::shrink(sal_Int32 nShrinkBy)
+inline void tools::Rectangle::shrink(long nShrinkBy)
{
nLeft += nShrinkBy;
nTop += nShrinkBy;