Commit 4cabfd89 authored by Michael Reeves's avatar Michael Reeves

Don't ship our own versions of standard types/functions

Use std::min, std::max instead of custome function.
Use stardard QT types for 8, 16, 32 bit inits. Don't try to define our
own.
parent 5ce6d147
......@@ -22,21 +22,6 @@
#include <QString>
#include <map>
template< class T >
T min2( T x, T y )
{
return x<y ? x : y;
}
template< class T >
T max2( T x, T y )
{
return x>y ? x : y;
}
typedef unsigned char UINT8;
typedef unsigned short UINT16;
typedef unsigned int UINT32;
template <class T>
T min3( T d1, T d2, T d3 )
{
......@@ -54,7 +39,6 @@ T max3( T d1, T d2, T d3 )
if ( d2 > d3 ) return d2;
return d3;
}
template <class T>
......
......@@ -811,7 +811,7 @@ QStringList SourceData::readAndPreprocess(QTextCodec* pEncoding, bool bAutoDetec
if(m_pOptions->m_bIgnoreComments)
{
m_lmppData.removeComments();
LineRef vSize = (LineRef)min2(m_normalData.m_vSize, m_lmppData.m_vSize);
LineRef vSize = (LineRef)std::min(m_normalData.m_vSize, m_lmppData.m_vSize);
for(int i = 0; i < (int)vSize; ++i)
{
m_normalData.m_v[i].bContainsPureComment = m_lmppData.m_v[i].bContainsPureComment;
......@@ -921,7 +921,7 @@ bool SourceData::FileData::preprocess(bool bPreserveCR, QTextCodec* pEncoding)
{
--lineLength;
}
m_v[lineIdx].pFirstNonWhiteChar = m_v[lineIdx].pLine + min2(whiteLength, lineLength);
m_v[lineIdx].pFirstNonWhiteChar = m_v[lineIdx].pLine + std::min(whiteLength, lineLength);
m_v[lineIdx].size = lineLength;
if(lineIdx < vOrigDataLineEndStyle.count() && bPreserveCR && i < ucSize)
{
......@@ -1595,7 +1595,7 @@ static bool runDiff(const LineData* p1, LineRef size1, const LineData* p2, LineR
if(diffList.empty())
{
Diff d(0, 0, 0);
d.nofEquals = min2(size1, size2);
d.nofEquals = std::min(size1, size2);
d.diff1 = size1 - d.nofEquals;
d.diff2 = size2 - d.nofEquals;
diffList.push_back(d);
......@@ -1620,7 +1620,7 @@ static bool runDiff(const LineData* p1, LineRef size1, const LineData* p2, LineR
currentLine1 += equalLinesAtStart;
currentLine2 += equalLinesAtStart;
LineRef nofEquals = min2(size1 - currentLine1, size2 - currentLine2);
LineRef nofEquals = std::min(size1 - currentLine1, size2 - currentLine2);
if(nofEquals == 0)
{
diffList.back().diff1 += size1 - currentLine1;
......
......@@ -263,7 +263,7 @@ void DiffTextWindow::setFirstLine(int firstLine)
{
int fontHeight = fontMetrics().lineSpacing();
int newFirstLine = max2(0, firstLine);
int newFirstLine = std::max(0, firstLine);
int deltaY = fontHeight * (d->m_firstLine - newFirstLine);
......@@ -348,7 +348,7 @@ int DiffTextWindow::getNofLines()
int DiffTextWindow::convertLineToDiff3LineIdx(int line)
{
if(line >= 0 && d->m_bWordWrap && d->m_diff3WrapLineVector.size() > 0)
return d->m_diff3WrapLineVector[min2(line, (int)d->m_diff3WrapLineVector.size() - 1)].diff3LineIndex;
return d->m_diff3WrapLineVector[std::min(line, (int)d->m_diff3WrapLineVector.size() - 1)].diff3LineIndex;
else
return line;
}
......@@ -356,7 +356,7 @@ int DiffTextWindow::convertLineToDiff3LineIdx(int line)
int DiffTextWindow::convertDiff3LineIdxToLine(int d3lIdx)
{
if(d->m_bWordWrap && d->m_pDiff3LineVector != nullptr && d->m_pDiff3LineVector->size() > 0)
return (*d->m_pDiff3LineVector)[min2(d3lIdx, (int)d->m_pDiff3LineVector->size() - 1)]->sumLinesNeededForDisplay;
return (*d->m_pDiff3LineVector)[std::min(d3lIdx, (int)d->m_pDiff3LineVector->size() - 1)]->sumLinesNeededForDisplay;
else
return d3lIdx;
}
......@@ -467,7 +467,7 @@ bool isCTokenChar(QChar c)
void calcTokenPos(const QString& s, int posOnScreen, int& pos1, int& pos2, int tabSize)
{
// Cursor conversions that consider g_tabSize
int pos = convertToPosInText(s, max2(0, posOnScreen), tabSize);
int pos = convertToPosInText(s, std::max(0, posOnScreen), tabSize);
if(pos >= (int)s.length())
{
pos1 = s.length();
......@@ -626,11 +626,11 @@ void DiffTextWindow::timerEvent(QTimerEvent*)
}
else
{
firstLine = min2(d->m_selection.getLastLine(), d->m_selection.getOldLastLine());
lastLine = max2(d->m_selection.getLastLine(), d->m_selection.getOldLastLine());
firstLine = std::min(d->m_selection.getLastLine(), d->m_selection.getOldLastLine());
lastLine = std::max(d->m_selection.getLastLine(), d->m_selection.getOldLastLine());
}
int y1 = (firstLine - d->m_firstLine) * fontHeight;
int y2 = min2(height(), (lastLine - d->m_firstLine + 1) * fontHeight);
int y2 = std::min(height(), (lastLine - d->m_firstLine + 1) * fontHeight);
if(y1 < height() && y2 > 0)
{
......@@ -878,7 +878,7 @@ void DiffTextWindowData::writeLine(
//case '\0b' : lineString[lineString.length()-1] = 0x2756; break; // some other nice looking character
}
}
QVector<UINT8> charChanged(pld->size);
QVector<quint8> charChanged(pld->size);
Merger merger(pLineDiff1, pLineDiff2);
while(!merger.isEndReached() && i < pld->size)
{
......@@ -1037,7 +1037,7 @@ void DiffTextWindow::paintEvent(QPaintEvent* e)
bool bOldSelectionContainsData = d->m_selection.bSelectionContainsData;
d->m_selection.bSelectionContainsData = false;
int endLine = min2(d->m_firstLine + getNofVisibleLines() + 2, getNofLines());
int endLine = std::min(d->m_firstLine + getNofVisibleLines() + 2, getNofLines());
MyPainter p(this, d->m_pOptions->m_bRightToLeftLanguage, width(), fontMetrics().width('0'));
......@@ -1065,7 +1065,7 @@ void DiffTextWindow::print(MyPainter& p, const QRect&, int firstLine, int nofLin
QRect invalidRect = QRect(0, 0, 1000000000, 1000000000);
QColor bgColor = d->m_pOptions->m_bgColor;
d->m_pOptions->m_bgColor = Qt::white;
d->draw(p, invalidRect, p.window().width(), firstLine, min2(firstLine + nofLinesPerPage, getNofLines()));
d->draw(p, invalidRect, p.window().width(), firstLine, std::min(firstLine + nofLinesPerPage, getNofLines()));
d->m_pOptions->m_bgColor = bgColor;
d->m_firstLine = oldFirstLine;
}
......@@ -1715,7 +1715,7 @@ void DiffTextWindow::recalcWordWrapHelper(int wrapLineVectorSize, int visibleTex
if(wrapLineVectorSize > 0)
{
d->m_firstLine = min2(d->m_firstLine, wrapLineVectorSize - 1);
d->m_firstLine = std::min(d->m_firstLine, wrapLineVectorSize - 1);
d->m_horizScrollOffset = 0;
d->m_pDiffTextWindowFrame->setFirstLine(d->m_firstLine);
}
......
......@@ -884,7 +884,7 @@ bool DirectoryMergeWindow::Data::fastFileComparison(
while(sizeLeft > 0 && !pp.wasCancelled())
{
qint64 len = min2(sizeLeft, (t_FileSize)buf1.size());
qint64 len = std::min(sizeLeft, (t_FileSize)buf1.size());
if(len != file1.read(&buf1[0], len))
{
status = i18n("Error reading from %1", fileName1);
......
......@@ -672,7 +672,7 @@ static bool interruptableReadFile(QFile& f, void* pDestBuffer, qint64 maxLength)
pp.setMaxNofSteps(maxLength / maxChunkSize + 1);
while(i < maxLength)
{
qint64 nextLength = min2(maxLength - i, maxChunkSize);
qint64 nextLength = std::min(maxLength - i, maxChunkSize);
qint64 reallyRead = f.read((char*)pDestBuffer + i, nextLength);
if(reallyRead != nextLength)
{
......@@ -723,7 +723,7 @@ bool FileAccess::writeFile(const void* pSrcBuffer, qint64 length)
qint64 i = 0;
while(i < length)
{
qint64 nextLength = min2(length - i, maxChunkSize);
qint64 nextLength = std::min(length - i, maxChunkSize);
qint64 reallyWritten = f.write((char*)pSrcBuffer + i, nextLength);
if(reallyWritten != nextLength)
{
......@@ -1002,7 +1002,7 @@ void FileAccessJobHandler::slotGetData(KJob* pJob, const QByteArray& newData)
}
else
{
qint64 length = min2(qint64(newData.size()), m_maxLength - m_transferredBytes);
qint64 length = std::min(qint64(newData.size()), m_maxLength - m_transferredBytes);
::memcpy(m_pTransferBuffer + m_transferredBytes, newData.data(), newData.size());
m_transferredBytes += length;
}
......@@ -1046,7 +1046,7 @@ void FileAccessJobHandler::slotPutData(KIO::Job* pJob, QByteArray& data)
*/
qint64 maxChunkSize = 100000;
qint64 length = min2(maxChunkSize, m_maxLength - m_transferredBytes);
qint64 length = std::min(maxChunkSize, m_maxLength - m_transferredBytes);
data.resize((int)length);
if(data.size() == (int)length)
{
......@@ -1233,7 +1233,7 @@ bool FileAccessJobHandler::copyFile(const QString& dest)
qint64 srcSize = srcFile.size();
while(srcSize > 0 && !pp.wasCancelled())
{
qint64 readSize = srcFile.read(&buffer[0], min2(srcSize, bufSize));
qint64 readSize = srcFile.read(&buffer[0], std::min(srcSize, bufSize));
if(readSize == -1 || readSize == 0)
{
m_pFileAccess->setStatusText(i18n("Error during file copy operation: Reading failed. Filename: %1", srcName));
......
......@@ -889,9 +889,9 @@ void KDiff3App::slotFilePrint()
m_pEventLoopForPrinting->exec();
}
LineRef totalNofLines = max2(m_pDiffTextWindow1->getNofLines(), m_pDiffTextWindow2->getNofLines());
LineRef totalNofLines = std::max(m_pDiffTextWindow1->getNofLines(), m_pDiffTextWindow2->getNofLines());
if(m_bTripleDiff && m_pDiffTextWindow3)
totalNofLines = max2(totalNofLines, m_pDiffTextWindow3->getNofLines());
totalNofLines = std::max(totalNofLines, m_pDiffTextWindow3->getNofLines());
QList<int> pageList; // = printer.pageList();
......
......@@ -546,13 +546,13 @@ void MergeResultWindow::merge(bool bAutoSolve, int defaultSelector, bool bConfli
void MergeResultWindow::setFirstLine(int firstLine)
{
m_firstLine = max2(0, firstLine);
m_firstLine = std::max(0, firstLine);
update();
}
void MergeResultWindow::setHorizScrollOffset(int horizScrollOffset)
{
m_horizScrollOffset = max2(0, horizScrollOffset);
m_horizScrollOffset = std::max(0, horizScrollOffset);
update();
}
......@@ -1735,7 +1735,7 @@ QVector<QTextLayout::FormatRange> MergeResultWindow::getTextLayoutForLine(int li
{
int firstPosInText = convertToPosInText(str, m_selection.firstPosInLine(line), m_pOptions->m_tabSize);
int lastPosInText = convertToPosInText(str, m_selection.lastPosInLine(line), m_pOptions->m_tabSize);
int lengthInText = max2(0, lastPosInText - firstPosInText);
int lengthInText = std::max(0, lastPosInText - firstPosInText);
if(lengthInText > 0)
m_selection.bSelectionContainsData = true;
......@@ -2043,7 +2043,7 @@ int MergeResultWindow::convertToLine(int y)
int yOffset = topLineYOffset - m_firstLine * fontHeight;
int line = min2((y - yOffset) / fontHeight, m_totalSize - 1);
int line = std::min((y - yOffset) / fontHeight, m_totalSize - 1);
return line;
}
......@@ -2067,7 +2067,7 @@ void MergeResultWindow::mousePressEvent(QMouseEvent* e)
{
m_cursorXPos = 0;
m_cursorOldXPixelPos = 0;
m_cursorYPos = max2(line, 0);
m_cursorYPos = std::max(line, 0);
int l = 0;
MergeLineList::iterator i = m_mergeLineList.begin();
for(i = m_mergeLineList.begin(); i != m_mergeLineList.end(); ++i)
......@@ -2091,8 +2091,8 @@ void MergeResultWindow::mousePressEvent(QMouseEvent* e)
}
else if(bLMB) // Normal cursor placement
{
pos = max2(pos, 0);
line = max2(line, 0);
pos = std::max(pos, 0);
line = std::max(line, 0);
if(e->QInputEvent::modifiers() & Qt::ShiftModifier)
{
if(!m_selection.isValidFirstLine())
......@@ -2118,8 +2118,8 @@ void MergeResultWindow::mousePressEvent(QMouseEvent* e)
}
else if(bMMB) // Paste clipboard
{
pos = max2(pos, 0);
line = max2(line, 0);
pos = std::max(pos, 0);
line = std::max(line, 0);
m_selection.reset();
m_cursorXPos = pos;
......@@ -2245,7 +2245,7 @@ void MergeResultWindow::wheelEvent(QWheelEvent* e)
{
int d = -e->delta() * QApplication::wheelScrollLines() / 120;
e->accept();
scroll(0, min2(d, getNofVisibleLines()));
scroll(0, std::min(d, getNofVisibleLines()));
}
bool MergeResultWindow::event(QEvent* e)
......@@ -3121,7 +3121,7 @@ Overview::e_OverviewMode Overview::getOverviewMode()
void Overview::mousePressEvent(QMouseEvent* e)
{
int h = height() - 1;
int h1 = h * m_pageHeight / max2(1, m_nofLines) + 3;
int h1 = h * m_pageHeight / std::max(1, m_nofLines) + 3;
if(h > 0)
emit setLine((e->y() - h1 / 2) * m_nofLines / h);
}
......@@ -3278,12 +3278,12 @@ void Overview::drawColumn(QPainter& p, e_OverviewMode eOverviewMode, int x, int
// Make sure that lines with conflict are not overwritten.
if(c == m_pOptions->m_colorForConflict)
{
p.fillRect(x2 + 1, oldY, w2, max2(1, y - oldY), bWhiteSpaceChange ? QBrush(c, Qt::Dense4Pattern) : QBrush(c));
p.fillRect(x2 + 1, oldY, w2, std::max(1, y - oldY), bWhiteSpaceChange ? QBrush(c, Qt::Dense4Pattern) : QBrush(c));
oldConflictY = oldY;
}
else if(c != m_pOptions->m_bgColor && oldY > oldConflictY)
{
p.fillRect(x2 + 1, oldY, w2, max2(1, y - oldY), bWhiteSpaceChange ? QBrush(c, Qt::Dense4Pattern) : QBrush(c));
p.fillRect(x2 + 1, oldY, w2, std::max(1, y - oldY), bWhiteSpaceChange ? QBrush(c, Qt::Dense4Pattern) : QBrush(c));
}
}
......
......@@ -471,7 +471,7 @@ void KDiff3App::resizeDiffTextWindowHeight(int newHeight)
{
m_DTWHeight = newHeight;
m_pDiffVScrollBar->setRange(0, max2(0, m_neededLines + 1 - newHeight));
m_pDiffVScrollBar->setRange(0, std::max(0, m_neededLines + 1 - newHeight));
m_pDiffVScrollBar->setPageStep(newHeight);
m_pOverview->setRange(m_pDiffVScrollBar->value(), m_pDiffVScrollBar->pageStep());
......@@ -481,7 +481,7 @@ void KDiff3App::resizeDiffTextWindowHeight(int newHeight)
void KDiff3App::resizeMergeResultWindow()
{
MergeResultWindow* p = m_pMergeResultWindow;
m_pMergeVScrollBar->setRange(0, max2(0, p->getNofLines() - p->getNofVisibleLines()));
m_pMergeVScrollBar->setRange(0, std::max(0, p->getNofLines() - p->getNofVisibleLines()));
m_pMergeVScrollBar->setPageStep(p->getNofVisibleLines());
setHScrollBarRange();
......@@ -533,7 +533,7 @@ template <class W, class L>
void addWidget(L* layout, W* widget)
{
QSize s = widget->sizeHint();
widget->setMinimumSize(QSize(max2(s.width(), 0), max2(s.height(), 0)));
widget->setMinimumSize(QSize(std::max(s.width(), 0), std::max(s.height(), 0)));
layout->addWidget(widget);
}
......@@ -728,7 +728,7 @@ void KDiff3App::slotFinishMainInit()
/*int newWidth = m_pDiffTextWindow1->getNofVisibleColumns();*/
m_DTWHeight = newHeight;
m_pDiffVScrollBar->setRange(0, max2(0, m_neededLines + 1 - newHeight));
m_pDiffVScrollBar->setRange(0, std::max(0, m_neededLines + 1 - newHeight));
m_pDiffVScrollBar->setPageStep(newHeight);
m_pOverview->setRange(m_pDiffVScrollBar->value(), m_pDiffVScrollBar->pageStep());
......@@ -738,7 +738,7 @@ void KDiff3App::slotFinishMainInit()
if(d3l >= 0 && m_pDiffTextWindow1)
{
int line = m_pDiffTextWindow1->convertDiff3LineIdxToLine(d3l);
m_pDiffVScrollBar->setValue(max2(0, line - 1));
m_pDiffVScrollBar->setValue(std::max(0, line - 1));
}
else
{
......@@ -1786,7 +1786,7 @@ void KDiff3App::slotFinishRecalcWordWrap()
if(m_pOverview)
m_pOverview->slotRedraw();
if(m_pDiffVScrollBar)
m_pDiffVScrollBar->setRange(0, max2(0, m_neededLines + 1 - m_DTWHeight));
m_pDiffVScrollBar->setRange(0, std::max(0, m_neededLines + 1 - m_DTWHeight));
if(m_pDiffTextWindow1)
{
if(m_pDiffVScrollBar)
......@@ -2070,7 +2070,7 @@ void KDiff3App::slotEditFindNext()
{
m_pDiffTextWindow1->setSelection(d3vLine, posInLine, d3vLine, posInLine + s.length(), l, p);
m_pDiffVScrollBar->setValue(l - m_pDiffVScrollBar->pageStep() / 2);
m_pHScrollBar->setValue(max2(0, p + (int)s.length() - m_pHScrollBar->pageStep()));
m_pHScrollBar->setValue(std::max(0, p + (int)s.length() - m_pHScrollBar->pageStep()));
m_pFindDialog->currentLine = d3vLine;
m_pFindDialog->currentPos = posInLine + 1;
return;
......@@ -2089,7 +2089,7 @@ void KDiff3App::slotEditFindNext()
{
m_pDiffTextWindow2->setSelection(d3vLine, posInLine, d3vLine, posInLine + s.length(), l, p);
m_pDiffVScrollBar->setValue(l - m_pDiffVScrollBar->pageStep() / 2);
m_pHScrollBar->setValue(max2(0, p + (int)s.length() - m_pHScrollBar->pageStep()));
m_pHScrollBar->setValue(std::max(0, p + (int)s.length() - m_pHScrollBar->pageStep()));
m_pFindDialog->currentLine = d3vLine;
m_pFindDialog->currentPos = posInLine + 1;
return;
......@@ -2108,7 +2108,7 @@ void KDiff3App::slotEditFindNext()
{
m_pDiffTextWindow3->setSelection(d3vLine, posInLine, d3vLine, posInLine + s.length(), l, p);
m_pDiffVScrollBar->setValue(l - m_pDiffVScrollBar->pageStep() / 2);
m_pHScrollBar->setValue(max2(0, p + (int)s.length() - m_pHScrollBar->pageStep()));
m_pHScrollBar->setValue(std::max(0, p + (int)s.length() - m_pHScrollBar->pageStep()));
m_pFindDialog->currentLine = d3vLine;
m_pFindDialog->currentPos = posInLine + 1;
return;
......@@ -2127,7 +2127,7 @@ void KDiff3App::slotEditFindNext()
{
m_pMergeResultWindow->setSelection(d3vLine, posInLine, d3vLine, posInLine + s.length());
m_pMergeVScrollBar->setValue(d3vLine - m_pMergeVScrollBar->pageStep() / 2);
m_pHScrollBar->setValue(max2(0, posInLine + (int)s.length() - m_pHScrollBar->pageStep()));
m_pHScrollBar->setValue(std::max(0, posInLine + (int)s.length() - m_pHScrollBar->pageStep()));
m_pFindDialog->currentLine = d3vLine;
m_pFindDialog->currentPos = posInLine + 1;
return;
......
......@@ -65,14 +65,14 @@ public:
int lastPosInLine(LineRef l);
LineRef beginLine(){
if (firstLine<0 && lastLine<0) return invalidRef;
return max2((LineRef)0,min2(firstLine,lastLine));
return std::max((LineRef)0,std::min(firstLine,lastLine));
}
LineRef endLine(){
if (firstLine<0 && lastLine<0) return invalidRef;
return max2(firstLine,lastLine);
return std::max(firstLine,lastLine);
}
int beginPos() { return firstLine==lastLine ? min2(firstPos,lastPos) :
int beginPos() { return firstLine==lastLine ? std::min(firstPos,lastPos) :
firstLine<lastLine ? (firstLine<0?0:firstPos) : (lastLine<0?0:lastPos); }
int endPos() { return firstLine==lastLine ? max2(firstPos,lastPos) :
int endPos() { return firstLine==lastLine ? std::max(firstPos,lastPos) :
firstLine<lastLine ? lastPos : firstPos; }
};
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