edbee - Qt Editor Library
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
edbee::GapVector< T > Class Template Reference

This class is used to define a gap vector. A Gapvector is split in 2 parts. where the gap is moved to the insertation/changing point. So reducing the movement of fields. More...

#include <gapvector.h>

+ Collaboration diagram for edbee::GapVector< T >:

Public Member Functions

 GapVector (int capacity=16)
 
 ~GapVector ()
 
int length () const
 returns the used length of the data More...
 
int gapSize () const
 
int gapBegin () const
 
int gapEnd () const
 
int capacity () const
 
void clear ()
 clears the data More...
 
void replace (int offset, int length, const T *data, int newLength)
 this method replaces the given items More...
 
void fill (int offset, int length, const T &data, int newLength)
 this method replaces the given items with a single data item More...
 
void append (T t)
 convenient append method More...
 
void append (const T *t, int length)
 another append method More...
 
at (int offset) const
 This method returns the item at the given index. More...
 
void set (int offset, const T &value)
 This method sets an item at the given index. More...
 
T & operator[] (int offset)
 This method return an index. More...
 
T & rawAt (int index)
 This method returns the 'raw' element at the given location This method does NOT take in account the gap. More...
 
void copyRange (QChar *data, int offset, int length) const
 This method copies the given range to the data pointer. More...
 
T * data ()
 This method returns a direct pointer to the 0-terminated buffer This pointer is only valid as long as the buffer doesn't change WARNING, this method MOVES the gap! Which means this method should NOT be used for a lot of operations. More...
 
void moveGapTo (int offset)
 
void ensureGapSize (int requiredSize)
 this method makes sure there's enough room for the insertation More...
 
void resize (int newSize)
 resizes the array of data More...
 
void setGrowSize (int size)
 sets the growsize. The growsize if the amount to reserve extra More...
 
int growSize ()
 returns the growsize More...
 
QString getUnitTestString (QChar gapChar='_') const
 Converts the 'gap-buffer' to a unit-test debugging string. More...
 
QString getUnitTestString2 () const
 Converts the 'gap-buffer' to a unit-test debugging string. More...
 

Protected Member Functions

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 is the same in this method no gap-moving is required More...
 
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 is the same in this method no gap-moving is required More...
 

Protected Attributes

T * items_
 The item data. More...
 
int capacity_
 The number of reserved bytes. More...
 
int gapBegin_
 The start of the gap. More...
 
int gapEnd_
 The end of the gap. More...
 
int growSize_
 The size to grow extra. More...
 

Detailed Description

template<typename T>
class edbee::GapVector< T >

This class is used to define a gap vector. A Gapvector is split in 2 parts. where the gap is moved to the insertation/changing point. So reducing the movement of fields.

Constructor & Destructor Documentation

◆ GapVector()

template<typename T>
edbee::GapVector< T >::GapVector ( int  capacity = 16)
inline

◆ ~GapVector()

template<typename T>
edbee::GapVector< T >::~GapVector ( )
inline

Member Function Documentation

◆ append() [1/2]

template<typename T>
void edbee::GapVector< T >::append ( t)
inline

convenient append method

◆ append() [2/2]

template<typename T>
void edbee::GapVector< T >::append ( const T *  t,
int  length 
)
inline

another append method

◆ at()

template<typename T>
T edbee::GapVector< T >::at ( int  offset) const
inline

This method returns the item at the given index.

◆ capacity()

template<typename T>
int edbee::GapVector< T >::capacity ( ) const
inline

◆ clear()

template<typename T>
void edbee::GapVector< T >::clear ( )
inline

clears the data

◆ copyRange()

template<typename T>
void edbee::GapVector< T >::copyRange ( QChar *  data,
int  offset,
int  length 
) const
inline

This method copies the given range to the data pointer.

◆ data()

template<typename T>
T* edbee::GapVector< T >::data ( )
inline

This method returns a direct pointer to the 0-terminated buffer This pointer is only valid as long as the buffer doesn't change WARNING, this method MOVES the gap! Which means this method should NOT be used for a lot of operations.

◆ ensureGapSize()

template<typename T>
void edbee::GapVector< T >::ensureGapSize ( int  requiredSize)
inline

this method makes sure there's enough room for the insertation

◆ fill() [1/2]

template<typename T>
void edbee::GapVector< T >::fill ( int  offset,
int  length,
const T &  data 
)
inlineprotected

this method replaces the given text with the given data. because the length of the source and target is the same in this method no gap-moving is required

Parameters
offsetthe target to move the data to
lengththe number of items to replace
datathe data pointer with the source data

◆ fill() [2/2]

template<typename T>
void edbee::GapVector< T >::fill ( int  offset,
int  length,
const T &  data,
int  newLength 
)
inline

this method replaces the given items with a single data item

Parameters
offsetthe offset of the items to replace
lenththe number of items to replace
newLengththe number of times to repeat data

◆ gapBegin()

template<typename T>
int edbee::GapVector< T >::gapBegin ( ) const
inline

◆ gapEnd()

template<typename T>
int edbee::GapVector< T >::gapEnd ( ) const
inline

◆ gapSize()

template<typename T>
int edbee::GapVector< T >::gapSize ( ) const
inline

◆ getUnitTestString()

template<typename T>
QString edbee::GapVector< T >::getUnitTestString ( QChar  gapChar = '_') const
inline

Converts the 'gap-buffer' to a unit-test debugging string.

◆ getUnitTestString2()

template<typename T>
QString edbee::GapVector< T >::getUnitTestString2 ( ) const
inline

Converts the 'gap-buffer' to a unit-test debugging string.

◆ growSize()

template<typename T>
int edbee::GapVector< T >::growSize ( )
inline

returns the growsize

◆ length()

template<typename T>
int edbee::GapVector< T >::length ( ) const
inline

returns the used length of the data

◆ moveGapTo()

template<typename T>
void edbee::GapVector< T >::moveGapTo ( int  offset)
inline

◆ operator[]()

template<typename T>
T& edbee::GapVector< T >::operator[] ( int  offset)
inline

This method return an index.

◆ rawAt()

template<typename T>
T& edbee::GapVector< T >::rawAt ( int  index)
inline

This method returns the 'raw' element at the given location This method does NOT take in account the gap.

◆ replace() [1/2]

template<typename T>
void edbee::GapVector< T >::replace ( int  offset,
int  length,
const T *  data 
)
inlineprotected

this method replaces the given text with the given data. because the length of the source and target is the same in this method no gap-moving is required

Parameters
offsetthe target to move the data to
lengththe number of items to replace
datathe data pointer with the source data

◆ replace() [2/2]

template<typename T>
void edbee::GapVector< T >::replace ( int  offset,
int  length,
const T *  data,
int  newLength 
)
inline

this method replaces the given items

Parameters
offsetthe offset of the items to replace
lenththe number of items to replace
dataan array with new items
newLengththe number of items in the new array

◆ resize()

template<typename T>
void edbee::GapVector< T >::resize ( int  newSize)
inline

resizes the array of data

Todo:
: optimize, so data is moved only once in other words, gap movement is not required over here!! this can be done with 2 memcopies

◆ set()

template<typename T>
void edbee::GapVector< T >::set ( int  offset,
const T &  value 
)
inline

This method sets an item at the given index.

◆ setGrowSize()

template<typename T>
void edbee::GapVector< T >::setGrowSize ( int  size)
inline

sets the growsize. The growsize if the amount to reserve extra

Member Data Documentation

◆ capacity_

template<typename T>
int edbee::GapVector< T >::capacity_
protected

The number of reserved bytes.

◆ gapBegin_

template<typename T>
int edbee::GapVector< T >::gapBegin_
protected

The start of the gap.

◆ gapEnd_

template<typename T>
int edbee::GapVector< T >::gapEnd_
protected

The end of the gap.

◆ growSize_

template<typename T>
int edbee::GapVector< T >::growSize_
protected

The size to grow extra.

◆ items_

template<typename T>
T* edbee::GapVector< T >::items_
protected

The item data.


The documentation for this class was generated from the following file: