Commit 291436ec authored by Michael Reeves's avatar Michael Reeves

Make LineRefs private in Diff3line

parent 0cfd107b
This diff is collapsed.
......@@ -82,10 +82,11 @@ class DiffBufferInfo
class Diff3Line
{
public:
private:
LineRef lineA = -1;
LineRef lineB = -1;
LineRef lineC = -1;
public:
bool bAEqC : 1; // These are true if equal or only white-space changes exist.
bool bBEqC : 1;
......@@ -133,6 +134,14 @@ class Diff3Line
pFineCA = nullptr;
}
LineRef getLineA() const { return lineA; }
LineRef getLineB() const { return lineB; }
LineRef getLineC() const { return lineC; }
void setLineA(const LineRef& line) { lineA = line; }
void setLineB(const LineRef& line) { lineB = line; }
void setLineC(const LineRef& line) { lineC = line; }
bool operator==(const Diff3Line& d3l) const
{
return lineA == d3l.lineA && lineB == d3l.lineB && lineC == d3l.lineC && bAEqB == d3l.bAEqB && bAEqC == d3l.bAEqC && bBEqC == d3l.bBEqC;
......@@ -161,10 +170,37 @@ class Diff3Line
if(src == 3) return lineC;
return -1;
}
bool fineDiff(const int selector, const LineData* v1, const LineData* v2);
private:
void setFineDiff(const int selector, DiffList* pDiffList)
{
Q_ASSERT(selector == 1 || selector == 2 || selector == 3);
if(selector == 1)
{
if(pFineAB != nullptr)
delete pFineAB;
pFineAB = pDiffList;
}
else if(selector == 2)
{
if(pFineBC != nullptr)
delete pFineBC;
pFineBC = pDiffList;
}
else if(selector == 3)
{
if(pFineCA)
delete pFineCA;
pFineCA = pDiffList;
}
}
};
class Diff3LineList : public QList<Diff3Line>
{
public:
bool fineDiff(const int selector, const LineData* v1, const LineData* v2);
};
class Diff3LineVector : public QVector<Diff3Line*>
......
......@@ -1180,29 +1180,29 @@ void DiffTextWindowData::getLineInfo(
Q_ASSERT(m_winIdx >= 1 && m_winIdx <= 3);
if(m_winIdx == 1) {
lineIdx = d3l.lineA;
lineIdx = d3l.getLineA();
pFineDiff1 = d3l.pFineAB;
pFineDiff2 = d3l.pFineCA;
changed |= ((d3l.lineB == -1) != (lineIdx == -1) ? 1 : 0) +
((d3l.lineC == -1) != (lineIdx == -1) && m_bTriple ? 2 : 0);
changed |= ((d3l.getLineB() == -1) != (lineIdx == -1) ? 1 : 0) +
((d3l.getLineC() == -1) != (lineIdx == -1) && m_bTriple ? 2 : 0);
changed2 |= (bAEqB ? 0 : 1) + (bAEqC || !m_bTriple ? 0 : 2);
}
else if(m_winIdx == 2)
{
lineIdx = d3l.lineB;
lineIdx = d3l.getLineB();
pFineDiff1 = d3l.pFineBC;
pFineDiff2 = d3l.pFineAB;
changed |= ((d3l.lineC == -1) != (lineIdx == -1) && m_bTriple ? 1 : 0) +
((d3l.lineA == -1) != (lineIdx == -1) ? 2 : 0);
changed |= ((d3l.getLineC() == -1) != (lineIdx == -1) && m_bTriple ? 1 : 0) +
((d3l.getLineA() == -1) != (lineIdx == -1) ? 2 : 0);
changed2 |= (bBEqC || !m_bTriple ? 0 : 1) + (bAEqB ? 0 : 2);
}
else if(m_winIdx == 3)
{
lineIdx = d3l.lineC;
lineIdx = d3l.getLineC();
pFineDiff1 = d3l.pFineCA;
pFineDiff2 = d3l.pFineBC;
changed |= ((d3l.lineA == -1) != (lineIdx == -1) ? 1 : 0) +
((d3l.lineB == -1) != (lineIdx == -1) ? 2 : 0);
changed |= ((d3l.getLineA() == -1) != (lineIdx == -1) ? 1 : 0) +
((d3l.getLineB() == -1) != (lineIdx == -1) ? 2 : 0);
changed2 |= (bAEqC ? 0 : 1) + (bBEqC ? 0 : 2);
}
......@@ -1254,15 +1254,15 @@ QString DiffTextWindow::getSelection()
Q_ASSERT(d->m_winIdx >= 1 && d->m_winIdx <= 3);
if(d->m_winIdx == 1) {
lineIdx = d3l->lineA;
lineIdx = d3l->getLineA();
}
else if(d->m_winIdx == 2)
{
lineIdx = d3l->lineB;
lineIdx = d3l->getLineB();
}
else if(d->m_winIdx == 3)
{
lineIdx = d3l->lineC;
lineIdx = d3l->getLineC();
}
if(lineIdx != -1)
......@@ -1377,9 +1377,9 @@ void DiffTextWindow::setSelection(int firstLine, int startPos, int lastLine, int
const Diff3Line* d3l = (*d->m_pDiff3LineVector)[convertLineToDiff3LineIdx(lastLine)];
int line = -1;
if(d->m_winIdx == 1) line = d3l->lineA;
if(d->m_winIdx == 2) line = d3l->lineB;
if(d->m_winIdx == 3) line = d3l->lineC;
if(d->m_winIdx == 1) line = d3l->getLineA();
if(d->m_winIdx == 2) line = d3l->getLineB();
if(d->m_winIdx == 3) line = d3l->getLineC();
if(line >= 0)
endPos = d->m_pLineData[line].width(d->m_pOptions->m_tabSize);
}
......@@ -1436,9 +1436,9 @@ int DiffTextWindowData::convertLineOnScreenToLineInSource(int lineOnScreen, e_Co
while(line < 0 && d3lIdx < (int)m_pDiff3LineVector->size() && d3lIdx >= 0)
{
const Diff3Line* d3l = (*m_pDiff3LineVector)[d3lIdx];
if(m_winIdx == 1) line = d3l->lineA;
if(m_winIdx == 2) line = d3l->lineB;
if(m_winIdx == 3) line = d3l->lineC;
if(m_winIdx == 1) line = d3l->getLineA();
if(m_winIdx == 2) line = d3l->getLineB();
if(m_winIdx == 3) line = d3l->getLineC();
if(bFirstLine)
++d3lIdx;
else
......
......@@ -195,7 +195,7 @@ void mergeOneLine(
if(bTwoInputs) // Only two input files
{
if(d.lineA != -1 && d.lineB != -1)
if(d.getLineA() != -1 && d.getLineB() != -1)
{
if(d.pFineAB == nullptr)
{
......@@ -210,12 +210,12 @@ void mergeOneLine(
}
else
{
if(d.lineA != -1 && d.lineB == -1)
if(d.getLineA() != -1 && d.getLineB() == -1)
{
mergeDetails = eBDeleted;
bConflict = true;
}
else if(d.lineA == -1 && d.lineB != -1)
else if(d.getLineA() == -1 && d.getLineB() != -1)
{
mergeDetails = eBDeleted;
bConflict = true;
......@@ -225,7 +225,7 @@ void mergeOneLine(
}
// A is base.
if(d.lineA != -1 && d.lineB != -1 && d.lineC != -1)
if(d.getLineA() != -1 && d.getLineB() != -1 && d.getLineC() != -1)
{
if(d.pFineAB == nullptr && d.pFineBC == nullptr && d.pFineCA == nullptr)
{
......@@ -255,7 +255,7 @@ void mergeOneLine(
else
Q_ASSERT(true);
}
else if(d.lineA != -1 && d.lineB != -1 && d.lineC == -1)
else if(d.getLineA() != -1 && d.getLineB() != -1 && d.getLineC() == -1)
{
if(d.pFineAB != nullptr)
{
......@@ -269,7 +269,7 @@ void mergeOneLine(
src = C;
}
}
else if(d.lineA != -1 && d.lineB == -1 && d.lineC != -1)
else if(d.getLineA() != -1 && d.getLineB() == -1 && d.getLineC() != -1)
{
if(d.pFineCA != nullptr)
{
......@@ -283,7 +283,7 @@ void mergeOneLine(
src = B;
}
}
else if(d.lineA == -1 && d.lineB != -1 && d.lineC != -1)
else if(d.getLineA() == -1 && d.getLineB() != -1 && d.getLineC() != -1)
{
if(d.pFineBC != nullptr)
{
......@@ -296,17 +296,17 @@ void mergeOneLine(
src = C;
}
}
else if(d.lineA == -1 && d.lineB == -1 && d.lineC != -1)
else if(d.getLineA() == -1 && d.getLineB() == -1 && d.getLineC() != -1)
{
mergeDetails = eCAdded;
src = C;
}
else if(d.lineA == -1 && d.lineB != -1 && d.lineC == -1)
else if(d.getLineA() == -1 && d.getLineB() != -1 && d.getLineC() == -1)
{
mergeDetails = eBAdded;
src = B;
}
else if(d.lineA != -1 && d.lineB == -1 && d.lineC == -1)
else if(d.getLineA() != -1 && d.getLineB() == -1 && d.getLineC() == -1)
{
mergeDetails = eBCDeleted;
bLineRemoved = true;
......@@ -449,7 +449,7 @@ void MergeResultWindow::merge(bool bAutoSolve, int defaultSelector, bool bConfli
MergeEditLine mel(d3llit);
mel.setSource(defaultSelector, false);
LineRef srcLine = defaultSelector == 1 ? d3llit->lineA : defaultSelector == 2 ? d3llit->lineB : defaultSelector == 3 ? d3llit->lineC : -1;
LineRef srcLine = defaultSelector == 1 ? d3llit->getLineA() : defaultSelector == 2 ? d3llit->getLineB() : defaultSelector == 3 ? d3llit->getLineC() : -1;
if(srcLine != -1)
{
......@@ -484,7 +484,7 @@ void MergeResultWindow::merge(bool bAutoSolve, int defaultSelector, bool bConfli
MergeEditLine& mel = *melIt;
int melsrc = mel.src();
LineRef srcLine = mel.isRemoved() ? -1 : melsrc == 1 ? mel.id3l()->lineA : melsrc == 2 ? mel.id3l()->lineB : melsrc == 3 ? mel.id3l()->lineC : -1;
LineRef srcLine = mel.isRemoved() ? -1 : melsrc == 1 ? mel.id3l()->getLineA() : melsrc == 2 ? mel.id3l()->getLineB() : melsrc == 3 ? mel.id3l()->getLineC() : -1;
// At least one line remains because oldSrc != melsrc for first line in list
// Other empty lines will be removed
......@@ -1018,7 +1018,7 @@ void MergeResultWindow::choose(int selector)
{
MergeEditLine& mel = *melIt;
LineRef srcLine = mel.src() == 1 ? mel.id3l()->lineA : mel.src() == 2 ? mel.id3l()->lineB : mel.src() == 3 ? mel.id3l()->lineC : -1;
LineRef srcLine = mel.src() == 1 ? mel.id3l()->getLineA() : mel.src() == 2 ? mel.id3l()->getLineB() : mel.src() == 3 ? mel.id3l()->getLineC() : -1;
if(srcLine == -1)
melIt = ml.mergeEditLineList.erase(melIt);
......@@ -1642,12 +1642,12 @@ 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.lineA != -1)
pld = &mrw->m_pldA[d3l.lineA];
else if(src == B && d3l.lineB != -1)
pld = &mrw->m_pldB[d3l.lineB];
else if(src == C && d3l.lineC != -1)
pld = &mrw->m_pldC[d3l.lineC];
if(src == A && d3l.getLineA() != -1)
pld = &mrw->m_pldA[d3l.getLineA()];
else if(src == B && d3l.getLineB() != -1)
pld = &mrw->m_pldB[d3l.getLineB()];
else if(src == C && d3l.getLineC() != -1)
pld = &mrw->m_pldC[d3l.getLineC()];
//Not an error.
if(pld == nullptr)
......@@ -3260,13 +3260,13 @@ void Overview::drawColumn(QPainter& p, e_OverviewMode eOverviewMode, int x, int
if(!m_bTripleDiff)
{
if(d3l.lineA == -1 && d3l.lineB >= 0)
if(d3l.getLineA() == -1 && d3l.getLineB() >= 0)
{
c = m_pOptions->m_colorA;
x2 = w / 2;
w2 = x2;
}
if(d3l.lineA >= 0 && d3l.lineB == -1)
if(d3l.getLineA() >= 0 && d3l.getLineB() == -1)
{
c = m_pOptions->m_colorB;
w2 = w / 2;
......
......@@ -63,11 +63,11 @@ static void debugLineCheck(Diff3LineList& d3ll, LineRef size, LineRef idx)
Q_ASSERT(idx >= 1 && idx <= 3);
if(idx == 1)
l = (*it).lineA;
l = (*it).getLineA();
else if(idx == 2)
l = (*it).lineB;
l = (*it).getLineB();
else if(idx == 3)
l = (*it).lineC;
l = (*it).getLineC();
if(l != -1)
{
......@@ -204,7 +204,7 @@ void KDiff3App::mainInit(TotalDiffStatus* pTotalDiffStatus, bool bLoadFiles, boo
pp.setInformation(i18n("Linediff: A <-> B"));
calcDiff3LineListUsingAB(&m_diffList12, m_diff3LineList);
pTotalDiffStatus->bTextAEqB = fineDiff(m_diff3LineList, 1, m_sd1.getLineDataForDisplay(), m_sd2.getLineDataForDisplay());
pTotalDiffStatus->bTextAEqB = m_diff3LineList.fineDiff(1, m_sd1.getLineDataForDisplay(), m_sd2.getLineDataForDisplay());
if(m_sd1.getSizeBytes() == 0) pTotalDiffStatus->bTextAEqB = false;
pp.step();
......@@ -276,29 +276,29 @@ void KDiff3App::mainInit(TotalDiffStatus* pTotalDiffStatus, bool bLoadFiles, boo
pp.setInformation(i18n("Linediff: A <-> B"));
if(m_sd1.hasData() && m_sd2.hasData() && m_sd1.isText() && m_sd2.isText())
pTotalDiffStatus->bTextAEqB = fineDiff(m_diff3LineList, 1, m_sd1.getLineDataForDisplay(), m_sd2.getLineDataForDisplay());
pTotalDiffStatus->bTextAEqB = m_diff3LineList.fineDiff(1, m_sd1.getLineDataForDisplay(), m_sd2.getLineDataForDisplay());
pp.step();
pp.setInformation(i18n("Linediff: B <-> C"));
if(m_sd2.hasData() && m_sd3.hasData() && m_sd2.isText() && m_sd3.isText())
pTotalDiffStatus->bTextBEqC = fineDiff(m_diff3LineList, 2, m_sd2.getLineDataForDisplay(), m_sd3.getLineDataForDisplay());
pTotalDiffStatus->bTextBEqC = m_diff3LineList.fineDiff(2, m_sd2.getLineDataForDisplay(), m_sd3.getLineDataForDisplay());
pp.step();
pp.setInformation(i18n("Linediff: A <-> C"));
if(m_sd1.hasData() && m_sd3.hasData() && m_sd1.isText() && m_sd3.isText())
pTotalDiffStatus->bTextAEqC = fineDiff(m_diff3LineList, 3, m_sd3.getLineDataForDisplay(), m_sd1.getLineDataForDisplay());
pTotalDiffStatus->bTextAEqC = m_diff3LineList.fineDiff(3, m_sd3.getLineDataForDisplay(), m_sd1.getLineDataForDisplay());
debugLineCheck(m_diff3LineList, m_sd2.getSizeLines(), 2);
debugLineCheck(m_diff3LineList, m_sd3.getSizeLines(), 3);
pp.setInformation(i18n("Linediff: A <-> B"));
if(m_sd1.hasData() && m_sd2.hasData() && m_sd1.isText() && m_sd2.isText())
pTotalDiffStatus->bTextAEqB = fineDiff(m_diff3LineList, 1, m_sd1.getLineDataForDisplay(), m_sd2.getLineDataForDisplay());
pTotalDiffStatus->bTextAEqB = m_diff3LineList.fineDiff(1, m_sd1.getLineDataForDisplay(), m_sd2.getLineDataForDisplay());
pp.step();
pp.setInformation(i18n("Linediff: B <-> C"));
if(m_sd3.hasData() && m_sd2.hasData() && m_sd3.isText() && m_sd2.isText())
pTotalDiffStatus->bTextBEqC = fineDiff(m_diff3LineList, 2, m_sd2.getLineDataForDisplay(), m_sd3.getLineDataForDisplay());
pTotalDiffStatus->bTextBEqC = m_diff3LineList.fineDiff(2, m_sd2.getLineDataForDisplay(), m_sd3.getLineDataForDisplay());
pp.step();
pp.setInformation(i18n("Linediff: A <-> C"));
if(m_sd1.hasData() && m_sd3.hasData() && m_sd1.isText() && m_sd3.isText())
pTotalDiffStatus->bTextAEqC = fineDiff(m_diff3LineList, 3, m_sd3.getLineDataForDisplay(), m_sd1.getLineDataForDisplay());
pTotalDiffStatus->bTextAEqC = m_diff3LineList.fineDiff(3, m_sd3.getLineDataForDisplay(), m_sd1.getLineDataForDisplay());
pp.step();
if(m_sd1.getSizeBytes() == 0) {
pTotalDiffStatus->bTextAEqB = false;
......@@ -754,9 +754,9 @@ int ManualDiffHelpEntry::calcManualDiffFirstDiff3LineIdx(const Diff3LineVector&
for(i = 0; i < d3lv.size(); ++i)
{
const Diff3Line& d3l = *d3lv[i];
if((lineA1 >= 0 && lineA1 == d3l.lineA) ||
(lineB1 >= 0 && lineB1 == d3l.lineB) ||
(lineC1 >= 0 && lineC1 == d3l.lineC))
if((lineA1 >= 0 && lineA1 == d3l.getLineA()) ||
(lineB1 >= 0 && lineB1 == d3l.getLineB()) ||
(lineC1 >= 0 && lineC1 == d3l.getLineC()))
return i;
}
return -1;
......
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