Commit 5ac57037 authored by Michael Reeves's avatar Michael Reeves

Finish LineRef

parent b9e3890a
...@@ -25,13 +25,21 @@ ...@@ -25,13 +25,21 @@
#include <type_traits> #include <type_traits>
#include <QtGlobal> #include <QtGlobal>
#define TYPE_MAX(x) std::numeric_limits<x>::max()
class LineRef class LineRef
{ {
public: public:
typedef qint32 LineType; typedef qint32 LineType;
LineRef() = default; inline LineRef() = default;
LineRef(const LineType i) { mLineNumber = i; } inline LineRef(const LineType i) { mLineNumber = i; }
operator LineType() const { return mLineNumber; } inline LineRef(const qint64 i)
{
if(i <= TYPE_MAX(LineType))
mLineNumber = (LineType)i;
else
mLineNumber = -1;
}
inline operator LineType() const { return mLineNumber; }
inline void operator= (const LineType lineIn) { mLineNumber = lineIn; } inline void operator= (const LineType lineIn) { mLineNumber = lineIn; }
inline LineRef& operator+=(const LineType& inLine) inline LineRef& operator+=(const LineType& inLine)
{ {
...@@ -39,22 +47,23 @@ class LineRef ...@@ -39,22 +47,23 @@ class LineRef
return *this; return *this;
}; };
void invalidate() { mLineNumber = -1; } inline void invalidate() { mLineNumber = -1; }
bool isValid() const { return mLineNumber != -1; } inline bool isValid() const { return mLineNumber != -1; }
private: private:
LineType mLineNumber = -1; LineType mLineNumber = -1;
}; };
static_assert(std::is_copy_constructible<LineRef>::value, ""); static_assert(std::is_copy_constructible<LineRef>::value, "LineRef must be copt constuctible.");
static_assert(std::is_copy_assignable<LineRef>::value, ""); static_assert(std::is_copy_assignable<LineRef>::value, "LineRef must copy assignable.");
static_assert(std::is_move_constructible<LineRef>::value, ""); static_assert(std::is_move_constructible<LineRef>::value, "LineRef must be move constructible.");
static_assert(std::is_move_assignable<LineRef>::value, ""); static_assert(std::is_move_assignable<LineRef>::value, "LineRef not must be move assignable.");
static_assert(std::is_convertible<LineRef, int>::value, ""); static_assert(std::is_convertible<LineRef, int>::value, "Can not convert LineRef to int.");
static_assert(std::is_convertible<int, LineRef>::value, ""); static_assert(std::is_convertible<int, LineRef>::value, "Can not convert int to LineRef.");
typedef LineRef::LineType LineCount; typedef LineRef::LineType LineCount;
typedef size_t PtrDiffRef; typedef size_t PtrDiffRef;
typedef LineRef::LineType LineIndex; typedef LineRef::LineType LineIndex;
#endif #endif
...@@ -173,7 +173,7 @@ const LineData* SourceData::getLineDataForDisplay() const ...@@ -173,7 +173,7 @@ const LineData* SourceData::getLineDataForDisplay() const
LineRef SourceData::getSizeLines() const LineRef SourceData::getSizeLines() const
{ {
return (LineRef::LineType)(m_normalData.m_vSize); return (LineRef)(m_normalData.m_vSize);
} }
qint64 SourceData::getSizeBytes() const qint64 SourceData::getSizeBytes() const
......
...@@ -105,8 +105,8 @@ void calcDiff3LineListUsingAB( ...@@ -105,8 +105,8 @@ void calcDiff3LineListUsingAB(
// First make d3ll for AB (from pDiffListAB) // First make d3ll for AB (from pDiffListAB)
DiffList::const_iterator i = pDiffListAB->begin(); DiffList::const_iterator i = pDiffListAB->begin();
int lineA = 0; LineRef::LineType lineA = 0;
int lineB = 0; LineRef::LineType lineB = 0;
Diff d(0, 0, 0); Diff d(0, 0, 0);
for(;;) for(;;)
...@@ -170,8 +170,8 @@ void calcDiff3LineListUsingAC( ...@@ -170,8 +170,8 @@ void calcDiff3LineListUsingAC(
DiffList::const_iterator i = pDiffListAC->begin(); DiffList::const_iterator i = pDiffListAC->begin();
Diff3LineList::iterator i3 = d3ll.begin(); Diff3LineList::iterator i3 = d3ll.begin();
int lineA = 0; LineRef::LineType lineA = 0;
int lineC = 0; LineRef::LineType lineC = 0;
Diff d(0, 0, 0); Diff d(0, 0, 0);
for(;;) for(;;)
...@@ -242,8 +242,8 @@ void calcDiff3LineListUsingBC( ...@@ -242,8 +242,8 @@ void calcDiff3LineListUsingBC(
DiffList::const_iterator i = pDiffListBC->begin(); DiffList::const_iterator i = pDiffListBC->begin();
Diff3LineList::iterator i3b = d3ll.begin(); Diff3LineList::iterator i3b = d3ll.begin();
Diff3LineList::iterator i3c = d3ll.begin(); Diff3LineList::iterator i3c = d3ll.begin();
int lineB = 0; LineRef::LineType lineB = 0;
int lineC = 0; LineRef::LineType lineC = 0;
Diff d(0, 0, 0); Diff d(0, 0, 0);
for(;;) for(;;)
...@@ -572,19 +572,19 @@ static bool runDiff(const LineData* p1, LineRef size1, const LineData* p2, LineR ...@@ -572,19 +572,19 @@ static bool runDiff(const LineData* p1, LineRef size1, const LineData* p2, LineR
gnuDiff.ignore_case = false; gnuDiff.ignore_case = false;
GnuDiff::change* script = gnuDiff.diff_2_files(&comparisonInput); GnuDiff::change* script = gnuDiff.diff_2_files(&comparisonInput);
LineRef equalLinesAtStart = (LineRef::LineType)comparisonInput.file[0].prefix_lines; LineRef equalLinesAtStart = (LineRef)comparisonInput.file[0].prefix_lines;
LineRef currentLine1 = 0; LineRef currentLine1 = 0;
LineRef currentLine2 = 0; LineRef currentLine2 = 0;
GnuDiff::change* p = nullptr; GnuDiff::change* p = nullptr;
for(GnuDiff::change* e = script; e; e = p) for(GnuDiff::change* e = script; e; e = p)
{ {
Diff d(0, 0, 0); Diff d(0, 0, 0);
d.nofEquals = (LineRef::LineType)(e->line0 - currentLine1); d.nofEquals = (LineRef)(e->line0 - currentLine1);
Q_ASSERT(d.nofEquals == e->line1 - currentLine2); Q_ASSERT(d.nofEquals == e->line1 - currentLine2);
d.diff1 = e->deleted; d.diff1 = e->deleted;
d.diff2 = e->inserted; d.diff2 = e->inserted;
currentLine1 += (LineRef::LineType)(d.nofEquals + d.diff1); currentLine1 += (LineRef)(d.nofEquals + d.diff1);
currentLine2 += (LineRef::LineType)(d.nofEquals + d.diff2); currentLine2 += (LineRef)(d.nofEquals + d.diff2);
diffList.push_back(d); diffList.push_back(d);
p = e->link; p = e->link;
...@@ -1303,8 +1303,8 @@ void calcDiff(const QChar* p1, LineRef size1, const QChar* p2, LineRef size2, Di ...@@ -1303,8 +1303,8 @@ void calcDiff(const QChar* p1, LineRef size1, const QChar* p2, LineRef size2, Di
DiffList::iterator i; DiffList::iterator i;
for(i = diffList.begin(); i != diffList.end(); ++i) for(i = diffList.begin(); i != diffList.end(); ++i)
{ {
l1 += (LineRef::LineType)(i->nofEquals + i->diff1); l1 += (LineRef)(i->nofEquals + i->diff1);
l2 += (LineRef::LineType)(i->nofEquals + i->diff2); l2 += (LineRef)(i->nofEquals + i->diff2);
} }
Q_ASSERT(l1 == size1 && l2 == size2); Q_ASSERT(l1 == size1 && l2 == size2);
......
...@@ -43,12 +43,10 @@ ...@@ -43,12 +43,10 @@
#include "LineRef.h" #include "LineRef.h"
/* The integer type of a line number. */ /* The integer type of a line number. */
typedef qint64 GNULineRef; typedef qint64 GNULineRef;
#define LINEREF_MAX std::numeric_limits<LineRef>::max()
#define GNULINEREF_MAX std::numeric_limits<GNULineRef>::max() #define GNULINEREF_MAX std::numeric_limits<GNULineRef>::max()
static_assert(sizeof(int) >= sizeof(qint32), "Legacy LP32 systems/compilers not supported");// e.g. Windows 16-bit static_assert(sizeof(int) >= sizeof(qint32), "Legacy LP32 systems/compilers not supported");// e.g. Windows 16-bit
static_assert(std::is_signed<GNULineRef>::value, "GNULineRef must be signed."); static_assert(std::is_signed<GNULineRef>::value, "GNULineRef must be signed.");
static_assert(sizeof(GNULineRef) >= sizeof(size_t),"GNULineRef must be able to recieve size_t values."); static_assert(sizeof(GNULineRef) >= sizeof(size_t),"GNULineRef must be able to receive size_t values.");
inline bool isEndOfLine( QChar c ) inline bool isEndOfLine( QChar c )
{ {
......
...@@ -820,8 +820,8 @@ void KDiff3App::slotFilePrint() ...@@ -820,8 +820,8 @@ void KDiff3App::slotFilePrint()
QPrinter printer; QPrinter printer;
QPointer<QPrintDialog> printDialog=QPointer<QPrintDialog>(new QPrintDialog(&printer, this)); QPointer<QPrintDialog> printDialog=QPointer<QPrintDialog>(new QPrintDialog(&printer, this));
LineRef firstSelectionD3LIdx = -1; LineRef firstSelectionD3LIdx;
LineRef lastSelectionD3LIdx = -1; LineRef lastSelectionD3LIdx;
m_pDiffTextWindow1->getSelectionRange(&firstSelectionD3LIdx, &lastSelectionD3LIdx, eD3LLineCoords); m_pDiffTextWindow1->getSelectionRange(&firstSelectionD3LIdx, &lastSelectionD3LIdx, eD3LLineCoords);
......
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