aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2018-03-03 13:42:08 +1100
committerNeil <nyamatongwe@gmail.com>2018-03-03 13:42:08 +1100
commitddbc7d46f93d87773a2713281591fc4e9c5baeca (patch)
treeddeb72687d7c6a5548253a21ad44863a14c1fef8 /src
parent37ae7ea7fcfca313265d85bb4bc9e56b0f29fd82 (diff)
downloadscintilla-mirror-ddbc7d46f93d87773a2713281591fc4e9c5baeca.tar.gz
Split LineVector into interface and implementation classes to allow future
choice between 32-bit and 64-bit position implementations.
Diffstat (limited to 'src')
-rw-r--r--src/CellBuffer.cxx142
-rw-r--r--src/CellBuffer.h32
2 files changed, 87 insertions, 87 deletions
diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx
index 744b62967..837fb0c23 100644
--- a/src/CellBuffer.cxx
+++ b/src/CellBuffer.cxx
@@ -25,54 +25,75 @@
#include "CellBuffer.h"
#include "UniConversion.h"
-using namespace Scintilla;
-
-LineVector::LineVector() : starts(256), perLine(0) {
- Init();
-}
+namespace Scintilla {
-LineVector::~LineVector() {
- starts.DeleteAll();
-}
-
-void LineVector::Init() {
- starts.DeleteAll();
- if (perLine) {
- perLine->Init();
- }
-}
+class ILineVector {
+public:
+ virtual void Init() = 0;
+ virtual void SetPerLine(PerLine *pl) = 0;
+ virtual void InsertText(Sci::Line line, Sci::Position delta) = 0;
+ virtual void InsertLine(Sci::Line line, Sci::Position position, bool lineStart) = 0;
+ virtual void SetLineStart(Sci::Line line, Sci::Position position) = 0;
+ virtual void RemoveLine(Sci::Line line) = 0;
+ virtual Sci::Line Lines() const = 0;
+ virtual Sci::Line LineFromPosition(Sci::Position pos) const = 0;
+ virtual Sci::Position LineStart(Sci::Line line) const = 0;
+ virtual ~ILineVector() {}
+};
-void LineVector::SetPerLine(PerLine *pl) {
- perLine = pl;
}
-void LineVector::InsertText(Sci::Line line, Sci::Position delta) {
- starts.InsertText(line, delta);
-}
+using namespace Scintilla;
-void LineVector::InsertLine(Sci::Line line, Sci::Position position, bool lineStart) {
- starts.InsertPartition(line, position);
- if (perLine) {
- if ((line > 0) && lineStart)
- line--;
- perLine->InsertLine(line);
+class LineVector : public ILineVector {
+ Partitioning<int> starts;
+ PerLine *perLine;
+public:
+ LineVector() : starts(256), perLine(0) {
+ Init();
+ }
+ ~LineVector() {
+ starts.DeleteAll();
+ }
+ void Init() override {
+ starts.DeleteAll();
+ if (perLine) {
+ perLine->Init();
+ }
+ }
+ void SetPerLine(PerLine *pl) override {
+ perLine = pl;
+ }
+ void InsertText(Sci::Line line, Sci::Position delta) override {
+ starts.InsertText(line, delta);
+ }
+ void InsertLine(Sci::Line line, Sci::Position position, bool lineStart) override {
+ starts.InsertPartition(line, position);
+ if (perLine) {
+ if ((line > 0) && lineStart)
+ line--;
+ perLine->InsertLine(line);
+ }
}
-}
-
-void LineVector::SetLineStart(Sci::Line line, Sci::Position position) {
- starts.SetPartitionStartPosition(line, position);
-}
-
-void LineVector::RemoveLine(Sci::Line line) {
- starts.RemovePartition(line);
- if (perLine) {
- perLine->RemoveLine(line);
+ void SetLineStart(Sci::Line line, Sci::Position position) override {
+ starts.SetPartitionStartPosition(line, position);
}
-}
-
-Sci::Line LineVector::LineFromPosition(Sci::Position pos) const {
- return starts.PartitionFromPosition(pos);
-}
+ void RemoveLine(Sci::Line line) override {
+ starts.RemovePartition(line);
+ if (perLine) {
+ perLine->RemoveLine(line);
+ }
+ }
+ Sci::Line Lines() const override {
+ return starts.Partitions();
+ }
+ Sci::Line LineFromPosition(Sci::Position pos) const override {
+ return starts.PartitionFromPosition(pos);
+ }
+ Sci::Position LineStart(Sci::Line line) const override {
+ return starts.PositionFromPartition(line);
+ }
+};
Action::Action() {
at = startAction;
@@ -347,6 +368,7 @@ CellBuffer::CellBuffer(bool hasStyles_) :
readOnly = false;
utf8LineEnds = 0;
collectingUndo = true;
+ plv = std::make_unique<LineVector>();
}
CellBuffer::~CellBuffer() {
@@ -505,11 +527,11 @@ bool CellBuffer::ContainsLineEnd(const char *s, Sci::Position length) const {
}
void CellBuffer::SetPerLine(PerLine *pl) {
- lv.SetPerLine(pl);
+ plv->SetPerLine(pl);
}
Sci::Line CellBuffer::Lines() const {
- return lv.Lines();
+ return plv->Lines();
}
Sci::Position CellBuffer::LineStart(Sci::Line line) const {
@@ -518,7 +540,11 @@ Sci::Position CellBuffer::LineStart(Sci::Line line) const {
else if (line >= Lines())
return Length();
else
- return lv.LineStart(line);
+ return plv->LineStart(line);
+}
+
+Sci::Line CellBuffer::LineFromPosition(Sci::Position pos) const {
+ return plv->LineFromPosition(pos);
}
bool CellBuffer::IsReadOnly() const {
@@ -556,11 +582,11 @@ bool CellBuffer::TentativeActive() const {
// Without undo
void CellBuffer::InsertLine(Sci::Line line, Sci::Position position, bool lineStart) {
- lv.InsertLine(line, position, lineStart);
+ plv->InsertLine(line, position, lineStart);
}
void CellBuffer::RemoveLine(Sci::Line line) {
- lv.RemoveLine(line);
+ plv->RemoveLine(line);
}
bool CellBuffer::UTF8LineEndOverlaps(Sci::Position position) const {
@@ -575,13 +601,13 @@ bool CellBuffer::UTF8LineEndOverlaps(Sci::Position position) const {
void CellBuffer::ResetLineEnds() {
// Reinitialize line data -- too much work to preserve
- lv.Init();
+ plv->Init();
const Sci::Position position = 0;
const Sci::Position length = Length();
Sci::Line lineInsert = 1;
const bool atLineStart = true;
- lv.InsertText(lineInsert-1, length);
+ plv->InsertText(lineInsert-1, length);
unsigned char chBeforePrev = 0;
unsigned char chPrev = 0;
for (Sci::Position i = 0; i < length; i++) {
@@ -592,7 +618,7 @@ void CellBuffer::ResetLineEnds() {
} else if (ch == '\n') {
if (chPrev == '\r') {
// Patch up what was end of line
- lv.SetLineStart(lineInsert - 1, (position + i) + 1);
+ plv->SetLineStart(lineInsert - 1, (position + i) + 1);
} else {
InsertLine(lineInsert, (position + i) + 1, atLineStart);
lineInsert++;
@@ -625,10 +651,10 @@ void CellBuffer::BasicInsertString(Sci::Position position, const char *s, Sci::P
style.InsertValue(position, insertLength, 0);
}
- Sci::Line lineInsert = lv.LineFromPosition(position) + 1;
- const bool atLineStart = lv.LineStart(lineInsert-1) == position;
+ Sci::Line lineInsert = plv->LineFromPosition(position) + 1;
+ const bool atLineStart = plv->LineStart(lineInsert-1) == position;
// Point all the lines after the insertion point further along in the buffer
- lv.InsertText(lineInsert-1, insertLength);
+ plv->InsertText(lineInsert-1, insertLength);
unsigned char chBeforePrev = substance.ValueAt(position - 2);
unsigned char chPrev = substance.ValueAt(position - 1);
if (chPrev == '\r' && chAfter == '\n') {
@@ -648,7 +674,7 @@ void CellBuffer::BasicInsertString(Sci::Position position, const char *s, Sci::P
} else if (ch == '\n') {
if (chPrev == '\r') {
// Patch up what was end of line
- lv.SetLineStart(lineInsert - 1, (position + i) + 1);
+ plv->SetLineStart(lineInsert - 1, (position + i) + 1);
} else {
InsertLine(lineInsert, (position + i) + 1, atLineStart);
lineInsert++;
@@ -695,20 +721,20 @@ void CellBuffer::BasicDeleteChars(Sci::Position position, Sci::Position deleteLe
if ((position == 0) && (deleteLength == substance.Length())) {
// If whole buffer is being deleted, faster to reinitialise lines data
// than to delete each line.
- lv.Init();
+ plv->Init();
} else {
// Have to fix up line positions before doing deletion as looking at text in buffer
// to work out which lines have been removed
- Sci::Line lineRemove = lv.LineFromPosition(position) + 1;
- lv.InsertText(lineRemove-1, - (deleteLength));
+ Sci::Line lineRemove = plv->LineFromPosition(position) + 1;
+ plv->InsertText(lineRemove-1, - (deleteLength));
const unsigned char chPrev = substance.ValueAt(position - 1);
const unsigned char chBefore = chPrev;
unsigned char chNext = substance.ValueAt(position);
bool ignoreNL = false;
if (chPrev == '\r' && chNext == '\n') {
// Move back one
- lv.SetLineStart(lineRemove, position);
+ plv->SetLineStart(lineRemove, position);
lineRemove++;
ignoreNL = true; // First \n is not real deletion
}
@@ -749,7 +775,7 @@ void CellBuffer::BasicDeleteChars(Sci::Position position, Sci::Position deleteLe
if (chBefore == '\r' && chAfter == '\n') {
// Using lineRemove-1 as cr ended line before start of deletion
RemoveLine(lineRemove - 1);
- lv.SetLineStart(lineRemove - 1, position + 1);
+ plv->SetLineStart(lineRemove - 1, position + 1);
}
}
substance.DeleteRange(position, deleteLength);
diff --git a/src/CellBuffer.h b/src/CellBuffer.h
index 7c999a36e..544a26711 100644
--- a/src/CellBuffer.h
+++ b/src/CellBuffer.h
@@ -22,33 +22,7 @@ public:
/**
* The line vector contains information about each of the lines in a cell buffer.
*/
-class LineVector {
-
- Partitioning<int> starts;
- PerLine *perLine;
-
-public:
-
- LineVector();
- // Deleted so LineVector objects can not be copied.
- LineVector(const LineVector &) = delete;
- void operator=(const LineVector &) = delete;
- ~LineVector();
- void Init();
- void SetPerLine(PerLine *pl);
-
- void InsertText(Sci::Line line, Sci::Position delta);
- void InsertLine(Sci::Line line, Sci::Position position, bool lineStart);
- void SetLineStart(Sci::Line line, Sci::Position position);
- void RemoveLine(Sci::Line line);
- Sci::Line Lines() const {
- return starts.Partitions();
- }
- Sci::Line LineFromPosition(Sci::Position pos) const;
- Sci::Position LineStart(Sci::Line line) const {
- return starts.PositionFromPartition(line);
- }
-};
+class ILineVector;
enum actionType { insertAction, removeAction, startAction, containerAction };
@@ -142,7 +116,7 @@ private:
bool collectingUndo;
UndoHistory uh;
- LineVector lv;
+ std::unique_ptr<ILineVector> plv;
bool UTF8LineEndOverlaps(Sci::Position position) const;
void ResetLineEnds();
@@ -175,7 +149,7 @@ public:
void SetPerLine(PerLine *pl);
Sci::Line Lines() const;
Sci::Position LineStart(Sci::Line line) const;
- Sci::Line LineFromPosition(Sci::Position pos) const { return lv.LineFromPosition(pos); }
+ Sci::Line LineFromPosition(Sci::Position pos) const;
void InsertLine(Sci::Line line, Sci::Position position, bool lineStart);
void RemoveLine(Sci::Line line);
const char *InsertString(Sci::Position position, const char *s, Sci::Position insertLength, bool &startSequence);