1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
/****************************************************************************
**
** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
**
** This file is part of the Edyuk project <http://edyuk.org>
**
** This file may be used under the terms of the GNU General Public License
** version 3 as published by the Free Software Foundation and appearing in the
** file GPL.txt included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#ifndef _QDOCUMENT_BUFFER_H_
#define _QDOCUMENT_BUFFER_H_
#include "qce-config.h"
#include <QVector>
#include "qdocumentline_p.h"
class QDocumentLineHandle;
class QCE_EXPORT QDocumentBuffer
{
friend class QDocumentLineHandle;
public:
class iterator
{
public:
iterator(const iterator& i);
bool atEnd() const;
int lineNumber() const;
QDocumentLineHandle* lineHandle() const;
void move(int numLines);
protected:
iterator(QDocumentBuffer *buffer, int block, int line);
private:
int m_block;
int m_line;
QDocumentBuffer *m_buffer;
};
QDocumentBuffer();
~QDocumentBuffer();
QDocumentLineHandle* at(int index) const;
void appendLine(QDocumentLineHandle *l);
void insertLine(int index, QDocumentLineHandle *l);
void removeLine(int index);
void insertLines(int after, const QVector<QDocumentLineHandle*>& l);
void removeLines(int after, int n);
private:
static void cleanHelper(QVector<QDocumentLineHandle*>& l)
{
foreach ( QDocumentLineHandle *h, l )
h->deref();
}
struct Block
{
inline Block() : start(-1), end(-1) {}
inline Block(int line) : start(line), end(line) {}
~Block() { cleanHelper(lines); }
inline void move(int numLines) { start += numLines; end += numLines; }
inline int size() const { return lines.count(); }
inline QDocumentLineHandle* at(int index) const { return lines.at(index - start); }
inline void append(QDocumentLineHandle *h) { lines.append(h); }
inline void prepend(QDocumentLineHandle *h) { lines.prepend(h); }
inline void insert(int index, QDocumentLineHandle *h) { lines.insert(index - start, h); }
inline void insert(int index, const QDocumentLineHandle* const* l, int n)
{
QDocumentLineHandle **d = const_cast<QDocumentLineHandle**>(l);
int i = index - start;
lines.insert(i, n, 0);
while ( n )
{
lines[i++] = *d;
++d;
--n;
}
}
inline void append(const QDocumentLineHandle* const* l, int n)
{
QDocumentLineHandle **d = const_cast<QDocumentLineHandle**>(l);
int i = lines.count();
lines.insert(i, n, 0);
while ( n )
{
lines[i++] = *d;
++d;
--n;
}
}
inline void prepend(const QDocumentLineHandle* const* l, int n)
{
QDocumentLineHandle **d = const_cast<QDocumentLineHandle**>(l);
int i = 0;
lines.insert(i, n, 0);
while ( n )
{
lines[i++] = *d;
++d;
--n;
}
}
inline void remove(int index) { lines.remove(index - start); }
inline void remove(int index, int count) { lines.remove(index - start, qMin(count, end - index)); }
int start, end;
QVector<QDocumentLineHandle*> lines;
};
int blockForLine(int index) const;
int m_safetyRoom;
int m_optimalSize;
int m_forkThresold;
int m_mergeThresold;
QVector<Block*> m_blocks;
};
#endif // !_QDOCUMENT_BUFFER_H_
|