Commit e26e5cdd authored by Michael Reeves's avatar Michael Reeves

add increment/decrement operators to LineRef

parent 80c9636a
......@@ -23,36 +23,62 @@
#include <stdlib.h>
#include <type_traits>
#include <QtGlobal>
#define TYPE_MAX(x) std::numeric_limits<x>::max()
#define TYPE_MIN(x) std::numeric_limits<x>::min()
class LineRef
{
public:
typedef qint32 LineType;
inline LineRef() = default;
inline LineRef(const LineType i) { mLineNumber = i; }
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 LineRef& operator+=(const LineType& inLine)
{
mLineNumber += inLine;
return *this;
};
public:
typedef qint32 LineType;
inline LineRef() = default;
inline LineRef(const LineType i) { mLineNumber = i; }
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 LineRef& operator+=(const LineType& inLine)
{
mLineNumber += inLine;
return *this;
};
LineRef& operator++()
{
++mLineNumber;
return *this;
};
LineRef operator++(int)
{
LineRef line(*this);
++mLineNumber;
return line;
};
inline void invalidate() { mLineNumber = -1; }
inline bool isValid() const { return mLineNumber != -1; }
LineRef& operator--()
{
--mLineNumber;
return *this;
};
private:
LineType mLineNumber = -1;
LineRef operator--(int)
{
LineRef line(*this);
--mLineNumber;
return line;
};
inline void invalidate() { mLineNumber = -1; }
inline bool isValid() const { return mLineNumber != -1; }
private:
LineType mLineNumber = -1;
};
static_assert(std::is_copy_constructible<LineRef>::value, "LineRef must be copt constuctible.");
......@@ -67,4 +93,3 @@ typedef size_t PtrDiffRef;
typedef LineRef::LineType LineIndex;
#endif
......@@ -1133,6 +1133,7 @@ QString DiffTextWindowData::getString(int d3lIdx)
{
if(d3lIdx < 0 || d3lIdx >= (int)m_pDiff3LineVector->size())
return QString();
const Diff3Line* d3l = (*m_pDiff3LineVector)[d3lIdx];
DiffList* pFineDiff1;
DiffList* pFineDiff2;
......
......@@ -2798,13 +2798,13 @@ void MergeResultWindow::deleteSelection()
setModified();
int line = 0;
LineRef line = 0;
MergeLineList::iterator mlItFirst;
MergeEditLineList::iterator melItFirst;
QString firstLineString;
int firstLine = -1;
int lastLine = -1;
LineRef firstLine;
LineRef lastLine;
MergeLineList::iterator mlIt;
for(mlIt = m_mergeLineList.begin(); mlIt != m_mergeLineList.end(); ++mlIt)
......@@ -2817,7 +2817,7 @@ void MergeResultWindow::deleteSelection()
if(mel.isEditableText() && m_selection.lineWithin(line))
{
if(firstLine == -1)
if(!firstLine.isValid())
firstLine = line;
lastLine = line;
}
......@@ -2826,7 +2826,7 @@ void MergeResultWindow::deleteSelection()
}
}
if(firstLine == -1)
if(!firstLine.isValid())
{
return; // Nothing to delete.
}
......
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