Commit 91ec31df authored by Michael Reeves's avatar Michael Reeves

Refactor

Add invalidate, isValid to LineRef.
use pointer syntax when dealing with iterators
parent 925449e8
......@@ -23,14 +23,12 @@
#include <stdlib.h>
#include <type_traits>
#include <QtGlobal>
class LineRef
{
public:
typedef int LineType;
static_assert(sizeof(LineType) <= sizeof(size_t), "Unsupport configuration.");
typedef qint32 LineType;
LineRef() = default;
LineRef(const LineType i) { mLineNumber = i; }
operator LineType() const { return mLineNumber; }
......@@ -41,6 +39,9 @@ class LineRef
return *this;
};
void invalidate() { mLineNumber = -1; }
bool isValid() const { return mLineNumber != -1; }
private:
LineType mLineNumber = -1;
};
......
......@@ -219,13 +219,13 @@ void Overview::drawColumn(QPainter& p, e_OverviewMode eOverviewMode, int x, int
if(!m_bTripleDiff)
{
if(d3l.getLineA() == -1 && d3l.getLineB() >= 0)
if(!d3l.getLineA().isValid() && d3l.getLineB().isValid())
{
c = m_pOptions->m_colorA;
x2 = w / 2;
w2 = x2;
}
if(d3l.getLineA() >= 0 && d3l.getLineB() == -1)
if(d3l.getLineA().isValid() && !d3l.getLineB().isValid())
{
c = m_pOptions->m_colorB;
w2 = w / 2;
......
......@@ -164,7 +164,7 @@ bool CvsIgnoreList::matches(const QString& text, bool bCaseSensitive) const
for(it = m_endPatterns.begin(), itEnd = m_endPatterns.end(); it != itEnd; ++it)
{
if(text.mid(text.length() - (*it).length()) == *it) //(text.endsWith(*it))
if(text.mid(text.length() - it->length()) == *it) //(text.endsWith(*it))
{
return true;
}
......
This diff is collapsed.
......@@ -121,9 +121,9 @@ class DiffBufferInfo
class Diff3Line
{
private:
LineRef lineA = -1;
LineRef lineB = -1;
LineRef lineC = -1;
LineRef lineA;
LineRef lineB;
LineRef lineC;
public:
bool bAEqC = false; // These are true if equal or only white-space changes exist.
......@@ -309,12 +309,13 @@ class ManualDiffHelpList; // A list of corresponding ranges
class ManualDiffHelpEntry
{
private:
LineRef lineA1 = -1;
LineRef lineA2 = -1;
LineRef lineB1 = -1;
LineRef lineB2 = -1;
LineRef lineC1 = -1;
LineRef lineC2 = -1;
LineRef lineA1;
LineRef lineA2;
LineRef lineB1;
LineRef lineB2;
LineRef lineC1;
LineRef lineC2;
public:
LineRef& firstLine(e_SrcSelector winIdx)
{
......
......@@ -42,10 +42,7 @@
#include "LineRef.h"
/* The integer type of a line number. */
//typedef qint32 LineRef;
//typedef qint32 LineCount;
typedef qint64 GNULineRef;
typedef qint32 LineIndex;
#define LINEREF_MAX std::numeric_limits<LineRef>::max()
#define GNULINEREF_MAX std::numeric_limits<GNULineRef>::max()
......
......@@ -902,8 +902,8 @@ void KDiff3App::slotFilePrint()
bool bPrintSelection = false;
int totalNofPages = (totalNofLines + linesPerPage - 1) / linesPerPage;
LineRef line = -1;
LineRef selectionEndLine = -1;
LineRef line;
LineRef selectionEndLine;
if(printer.printRange() == QPrinter::AllPages) {
pageList.clear();
......
......@@ -225,7 +225,7 @@ void Diff3Line::mergeOneLine(
if(bTwoInputs) // Only two input files
{
if(getLineA() != -1 && getLineB() != -1)
if(getLineA() != -1 && getLineB().isValid())
{
if(pFineAB == nullptr)
{
......@@ -240,12 +240,12 @@ void Diff3Line::mergeOneLine(
}
else
{
if(getLineA() != -1 && getLineB() == -1)
if(getLineA().isValid() && !getLineB().isValid())
{
mergeDetails = eBDeleted;
bConflict = true;
}
else if(getLineA() == -1 && getLineB() != -1)
else if(!getLineA().isValid() && getLineB().isValid())
{
mergeDetails = eBDeleted;
bConflict = true;
......@@ -255,7 +255,7 @@ void Diff3Line::mergeOneLine(
}
// A is base.
if(getLineA() != -1 && getLineB() != -1 && getLineC() != -1)
if(getLineA().isValid() && getLineB().isValid() && getLineC() != -1)
{
if(pFineAB == nullptr && pFineBC == nullptr && pFineCA == nullptr)
{
......@@ -285,7 +285,7 @@ void Diff3Line::mergeOneLine(
else
Q_ASSERT(true);
}
else if(getLineA() != -1 && getLineB() != -1 && getLineC() == -1)
else if(getLineA().isValid() && getLineB().isValid() && !getLineC().isValid())
{
if(pFineAB != nullptr)
{
......@@ -299,7 +299,7 @@ void Diff3Line::mergeOneLine(
src = C;
}
}
else if(getLineA() != -1 && getLineB() == -1 && getLineC() != -1)
else if(getLineA().isValid() && !getLineB().isValid() && getLineC() != -1)
{
if(pFineCA != nullptr)
{
......@@ -313,7 +313,7 @@ void Diff3Line::mergeOneLine(
src = B;
}
}
else if(getLineA() == -1 && getLineB() != -1 && getLineC() != -1)
else if(!getLineA().isValid() && getLineB().isValid() && getLineC() != -1)
{
if(pFineBC != nullptr)
{
......@@ -326,17 +326,17 @@ void Diff3Line::mergeOneLine(
src = C;
}
}
else if(getLineA() == -1 && getLineB() == -1 && getLineC() != -1)
else if(!getLineA().isValid() && !getLineB().isValid() && getLineC() != -1)
{
mergeDetails = eCAdded;
src = C;
}
else if(getLineA() == -1 && getLineB() != -1 && getLineC() == -1)
else if(!getLineA().isValid() && getLineB().isValid() && !getLineC().isValid())
{
mergeDetails = eBAdded;
src = B;
}
else if(getLineA() != -1 && getLineB() == -1 && getLineC() == -1)
else if(getLineA().isValid() && !getLineB().isValid() && !getLineC().isValid())
{
mergeDetails = eBCDeleted;
bLineRemoved = true;
......@@ -508,7 +508,7 @@ void MergeResultWindow::merge(bool bAutoSolve, e_SrcSelector defaultSelector, bo
MergeLine& ml = *mlIt;
// Remove all lines that are empty, because no src lines are there.
LineRef oldSrcLine = -1;
LineRef oldSrcLine;
int oldSrc = -1;
MergeEditLineList::iterator melIt;
for(melIt = ml.mergeEditLineList.begin(); melIt != ml.mergeEditLineList.end();)
......@@ -520,7 +520,7 @@ void MergeResultWindow::merge(bool bAutoSolve, e_SrcSelector defaultSelector, bo
// At least one line remains because oldSrc != melsrc for first line in list
// Other empty lines will be removed
if(srcLine == -1 && oldSrcLine == -1 && oldSrc == melsrc)
if(!srcLine.isValid() && !oldSrcLine.isValid() && oldSrc == melsrc)
melIt = ml.mergeEditLineList.erase(melIt);
else
++melIt;
......@@ -1052,7 +1052,7 @@ void MergeResultWindow::choose(e_SrcSelector selector)
LineRef srcLine = mel.src() == 1 ? mel.id3l()->getLineA() : mel.src() == 2 ? mel.id3l()->getLineB() : mel.src() == 3 ? mel.id3l()->getLineC() : LineRef();
if(srcLine == -1)
if(!srcLine.isValid())
melIt = ml.mergeEditLineList.erase(melIt);
else
++melIt;
......@@ -1674,11 +1674,11 @@ QString MergeResultWindow::MergeEditLine::getString(const MergeResultWindow* mrw
const Diff3Line& d3l = *m_id3l;
const LineData* pld = nullptr;
Q_ASSERT(src == A || src == B || src == C);
if(src == A && d3l.getLineA() != -1)
if(src == A && d3l.getLineA().isValid())
pld = &mrw->m_pldA[d3l.getLineA()];
else if(src == B && d3l.getLineB() != -1)
else if(src == B && d3l.getLineB().isValid())
pld = &mrw->m_pldB[d3l.getLineB()];
else if(src == C && d3l.getLineC() != -1)
else if(src == C && d3l.getLineC().isValid())
pld = &mrw->m_pldC[d3l.getLineC()];
//Not an error.
......
......@@ -64,11 +64,11 @@ static void debugLineCheck(Diff3LineList& d3ll, LineRef size, e_SrcSelector idx)
Q_ASSERT(idx >= A && idx <= C);
if(idx == A)
l = (*it).getLineA();
l = it->getLineA();
else if(idx == B)
l = (*it).getLineB();
l = it->getLineB();
else if(idx == C)
l = (*it).getLineC();
l = it->getLineC();
if(l != -1)
{
......@@ -1416,8 +1416,8 @@ void KDiff3App::slotRegExpAutoMerge()
void KDiff3App::slotSplitDiff()
{
LineRef firstLine = -1;
LineRef lastLine = -1;
LineRef firstLine;
LineRef lastLine;
DiffTextWindow* pDTW = nullptr;
if(m_pDiffTextWindow1)
{
......@@ -1444,8 +1444,8 @@ void KDiff3App::slotSplitDiff()
void KDiff3App::slotJoinDiffs()
{
LineRef firstLine = -1;
LineRef lastLine = -1;
LineRef firstLine;
LineRef lastLine;
DiffTextWindow* pDTW = nullptr;
if(m_pDiffTextWindow1)
{
......@@ -2310,8 +2310,8 @@ void ManualDiffHelpList::insertEntry(e_SrcSelector winIdx, LineRef firstLine, Li
if((firstLine <= l1 && lastLine >= l1) || (firstLine <= l2 && lastLine >= l2))
{
// overlap
l1 = -1;
l2 = -1;
l1.invalidate();
l2.invalidate();
}
if(firstLine < l1 && lastLine < l1)
{
......@@ -2341,8 +2341,8 @@ void ManualDiffHelpList::insertEntry(e_SrcSelector winIdx, LineRef firstLine, Li
{
iEmpty->firstLine((e_SrcSelector)wIdx) = i->firstLine((e_SrcSelector)wIdx);
iEmpty->lastLine((e_SrcSelector)wIdx) = i->lastLine((e_SrcSelector)wIdx);
i->firstLine((e_SrcSelector)wIdx) = -1;
i->lastLine((e_SrcSelector)wIdx) = -1;
i->firstLine((e_SrcSelector)wIdx).invalidate();
i->lastLine((e_SrcSelector)wIdx).invalidate();
++iEmpty;
}
}
......@@ -2352,8 +2352,8 @@ void ManualDiffHelpList::insertEntry(e_SrcSelector winIdx, LineRef firstLine, Li
void KDiff3App::slotAddManualDiffHelp()
{
LineRef firstLine = -1;
LineRef lastLine = -1;
LineRef firstLine;
LineRef lastLine;
e_SrcSelector winIdx = Invalid;
if(m_pDiffTextWindow1)
{
......
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