65 int len = qMin(
gapBegin_-offset, length );
67 memcpy(
items_ + offset, data,
sizeof(T)*len );
75 memcpy(
items_ + offset +
gapSize(), data,
sizeof(T)*length );
89 int len = qMin(
gapBegin_-offset, length );
90 for(
int i=0; i<len; ++i ) {
items_ [offset + i] =
data; }
110 int currentLength=this->
length();
111 Q_ASSERT( 0 <= offset && ((offset+length) <= currentLength) );
112 Q_UNUSED(currentLength);
123 if( length == newLength ) {
124 replace( offset, length, data );
127 }
else if( length < newLength ) {
128 int gapSizeRequired = newLength -
length;
131 memcpy(
items_ + offset, data,
sizeof(T) * newLength );
137 memcpy(
items_ + offset, data,
sizeof(T) * newLength );
153 int currentLength=this->
length();
154 Q_ASSERT( 0 <= offset && ((offset+length) <= currentLength) );
155 Q_UNUSED(currentLength);
162 if( length == newLength ) {
163 fill( offset, length, data );
166 }
else if( length < newLength ) {
167 int gapSizeRequired = newLength -
length;
170 for(
int i=0; i<newLength; ++i ) {
items_[offset+i] =
data; }
176 for(
int i=0; i<newLength; ++i ) {
items_[offset+i] =
data; }
199 T
at(
int offset )
const {
200 Q_ASSERT( 0 <= offset && offset <
length() );
209 void set(
int offset,
const T& value ) {
210 Q_ASSERT( 0 <= offset && offset <
length() );
221 Q_ASSERT( 0 <= offset && offset <
length() );
242 if( !length ) {
return; }
243 Q_ASSERT( 0 <= offset && offset < this->
length() );
244 Q_ASSERT( (offset+length) <= this->
length() );
248 int len = qMin(
gapBegin_-offset, length );
250 memcpy( data,
items_ + offset,
sizeof(T)*len );
258 memcpy( data,
items_ + offset +
gapSize(),
sizeof(T)*length );
279 Q_ASSERT( offset <=
length() );
299 #ifdef GAP_VECTOR_CLEAR_GAP 307 if(
gapSize() < requiredSize ) {
327 T *newChars =
new T[ newSize ];
330 memmove( newChars,
items_,
sizeof(T)*lengte );
338 #ifdef GAP_VECTOR_CLEAR_GAP 361 if(
items_[i].isNull() ) {
368 for(
int i=gapBegin; i<
gapEnd; ++i ) {
372 for(
int i=gapEnd; i<
capacity; ++i ) {
373 if(
items_[i].isNull() ) {
391 if( i ) { s.append(
","); }
392 if( gapEnd == i) s.append(
">");
393 s.append( QString(
"%1").arg(
"X" ));
394 if( gapBegin==i ) s.append(
"[");
420 memcpy(
items_, data.constData(),
sizeof(QChar)*data.length() );
432 memcpy(
items_, data.constData(),
sizeof(QChar)*data.length() );
443 replace( offset, length, data.constData(), data.length() );
451 Q_ASSERT( length >= 0 );
458 QString str( data, length );
473 template <
typename T>
509 items_.remove(offset,length);
510 for(
int i=0; i < newLength; i++ ) {
511 items_.insert(offset+i,data[i]);
520 items_.remove(offset,length);
521 for(
int i=0; i < newLength; i++ ) {
522 items_.insert(offset+i,data);
534 for(
int i=0; i <
length; i++ ) {
541 T
at(
int offset )
const {
546 void set(
int offset,
const T& value ) {
547 items_.replace(offset,value);
QCharGapVector(const QString &data, int gapSize)
initializes the vector with a given string
Definition: gapvector.h:418
QCharGapVector(int size=16)
Definition: gapvector.h:415
This class is used to define a gap vector. A Gapvector is split in 2 parts. where the gap is moved to...
Definition: gapvector.h:19
int gapBegin() const
Definition: gapvector.h:37
void fill(int offset, int length, const T &data, int newLength)
this method replaces the given items with a single data item
Definition: gapvector.h:152
int gapEnd_
The end of the gap.
Definition: gapvector.h:405
void resize(int newSize)
resizes the array of data
Definition: gapvector.h:315
void fill(int offset, int length, const T &data)
this method replaces the given text with the given data. because the length of the source and target ...
Definition: gapvector.h:85
void clear()
clears the data
Definition: gapvector.h:493
T & operator[](int offset)
This method return an index.
Definition: gapvector.h:220
int gapSize() const
Definition: gapvector.h:36
QVector< T > items_
This method returns a direct pointer to the 0-terminated buffer This pointer is only valid as long as...
Definition: gapvector.h:699
void replace(int offset, int length, const T *data, int newLength)
this method replaces the given items
Definition: gapvector.h:109
void init(const QString &data, int gapSize)
Initializes the gapvector.
Definition: gapvector.h:427
void setGrowSize(int size)
sets the growsize. The growsize if the amount to reserve extra
Definition: gapvector.h:347
void ensureGapSize(int requiredSize)
this method makes sure there's enough room for the insertation
Definition: gapvector.h:306
int capacity() const
Definition: gapvector.h:39
T & operator[](int offset)
This method return an index.
Definition: gapvector.h:552
void copyRange(QChar *data, int offset, int length) const
This method copies the given range to the data pointer.
Definition: gapvector.h:238
int capacity() const
Definition: gapvector.h:489
QString getUnitTestString(QChar gapChar='_') const
Converts the 'gap-buffer' to a unit-test debugging string.
Definition: gapvector.h:354
T & rawAt(int index)
This method returns the 'raw' element at the given location This method does NOT take in account the ...
Definition: gapvector.h:231
QString getUnitTestString2() const
Converts the 'gap-buffer' to a unit-test debugging string.
Definition: gapvector.h:384
Copyright 2011-2013 - Reliable Bits Software by Blommers IT.
Definition: commentcommand.cpp:22
QString mid(int offset, int length) const
a convenient method to retrieve a QString part
Definition: gapvector.h:449
T * data()
This method returns a direct pointer to the 0-terminated buffer This pointer is only valid as long as...
Definition: gapvector.h:266
void clear()
clears the data
Definition: gapvector.h:43
void moveGapTo(int offset)
Definition: gapvector.h:277
GapVector(int capacity=16)
Definition: gapvector.h:22
void append(T t)
convenient append method
Definition: gapvector.h:528
void fill(int offset, int length, const T &data, int newLength)
this method replaces the given items with a single data item
Definition: gapvector.h:519
void append(T t)
convenient append method
Definition: gapvector.h:188
~NoGapVector()
Definition: gapvector.h:481
int length() const
returns the used length of the data
Definition: gapvector.h:35
int growSize()
returns the growsize
Definition: gapvector.h:350
void replaceString(int offset, int length, const QString &data)
a convenient string replace function
Definition: gapvector.h:439
NoGapVector(int capacity=16)
Definition: gapvector.h:477
int growSize_
The size to grow extra.
Definition: gapvector.h:406
~GapVector()
Definition: gapvector.h:30
The character vecor to use.
Definition: gapvector.h:411
void replace(int offset, int length, const T *data)
this method replaces the given text with the given data. because the length of the source and target ...
Definition: gapvector.h:61
T at(int offset) const
This method returns the item at the given index.
Definition: gapvector.h:199
void append(const T *t, int length)
another append method
Definition: gapvector.h:533
int gapSize() const
Definition: gapvector.h:486
A special GapVector class that isn't a gapvector. It forwards it's request to a normal vector class (...
Definition: gapvector.h:474
int length() const
returns the used length of the data
Definition: gapvector.h:485
void append(const T *t, int length)
another append method
Definition: gapvector.h:193
int gapBegin() const
Definition: gapvector.h:487
int capacity_
The number of reserved bytes.
Definition: gapvector.h:403
T at(int offset) const
This method returns the item at the given index.
Definition: gapvector.h:541
int gapEnd() const
Definition: gapvector.h:488
void replace(int offset, int length, const T *data, int newLength)
this method replaces the given items
Definition: gapvector.h:508
T * items_
The item data.
Definition: gapvector.h:402
int gapEnd() const
Definition: gapvector.h:38
int gapBegin_
The start of the gap.
Definition: gapvector.h:404