#include <qptrvector.h>
A QPtrVector should be used when random access to elements needs to be quick. Insertions to and removals from the start of the list in particular are slow. Iterators are also invalidated whenever an insertion or removal is made. If you want something different, look into FX::QPtrList. This list is effectively a FX::QMemArray but with pointers and auto-deletion.
I've gone a bit further than Qt's QPtrVector as I've implemented all the QPtrList methods too - this was because the QPtrList code was used to make QPtrVector so it was trivial. Thus you can drop in a QPtrVector where a QPtrList used to be. I did however remove prepend() & removeFirst() as that's a major performance hurt with this container - use insert(0, x) or remove(0) instead. Qt doesn't seem to provide a QPtrVectorIterator, but we have.
Note that all sorts of unpleasantness has been used to get this work, including const_cast<>
. Also, because of the nature of templates not being compiled until they are used, I may not have caught all the compile errors yet :(
Public Member Functions | |
QPtrVector (bool wantAutoDel=false) | |
QPtrVector (std::vector< type * > &l) | |
bool | autoDelete () const |
void | setAutoDelete (bool a) |
type ** | data () const |
uint | count () const |
bool | isEmpty () const |
bool | insert (uint i, const type *d) |
bool | insertAtIter (QPtrVectorIterator< type > &it, const type *d) |
void | inSort (const type *d) |
void | append (const type *d) |
bool | extend (uint no) |
bool | remove (uint i) |
bool | remove (const type *d) |
bool | removeRef (const type *d) |
bool | removeByIter (QPtrVectorIterator< type > &it) |
bool | removeLast () |
type * | take (uint i) |
bool | take (const type *d) |
bool | takeRef (const type *d) |
bool | takeByIter (QPtrVectorIterator< type > &it) |
bool | takeLast () |
void | clear () |
template<class SortFunc> | |
void | sort (SortFunc sortfunc) |
void | sort () |
int | find (const type *d) |
int | findRef (const type *d) |
uint | contains (const type *d) const |
uint | containsRef (const type *d) const |
bool | replace (uint i, const type *d, bool callDeleteItem=true) |
bool | replaceAtIter (QPtrVectorIterator< type > &it, const type *d, bool callDeleteItem=true) |
type * | at (uint i) const |
type * | operator[] (uint i) const |
type * | operator[] (int i) const |
type * | getFirst () const |
type * | getLast () const |
type * | first () |
type * | last () |
virtual int | compareItems (type *a, type *b) const |
std::vector< type * > & | int_vector () |
std::vector< type * >::iterator | int_begin () |
std::vector< type * >::iterator | int_end () |
template<> | |
void | deleteItem (void *) |
Protected Member Functions | |
virtual void | deleteItem (type *d) |
bool FX::QPtrVector< type >::autoDelete | ( | ) | const [inline] |
Returns if auto-deletion is enabled.
void FX::QPtrVector< type >::setAutoDelete | ( | bool | a | ) | [inline] |
Sets if auto-deletion is enabled.
type** FX::QPtrVector< type >::data | ( | ) | const [inline] |
Returns the raw array of pointers.
uint FX::QPtrVector< type >::count | ( | ) | const [inline] |
Returns the number of items in the list.
Referenced by FX::QPtrVector< TnFXGraphItem >::contains(), and FX::QPtrVector< TnFXGraphItem >::containsRef().
bool FX::QPtrVector< type >::isEmpty | ( | ) | const [inline] |
Returns true if the list is empty.
Referenced by FX::QPtrVector< TnFXGraphItem >::remove(), FX::QPtrVector< TnFXGraphItem >::removeLast(), FX::QPtrVector< TnFXGraphItem >::replace(), FX::QPtrVector< TnFXGraphItem >::take(), and FX::QPtrVector< TnFXGraphItem >::takeLast().
bool FX::QPtrVector< type >::insert | ( | uint | i, | |
const type * | d | |||
) | [inline] |
Inserts item d into the list at index i.
bool FX::QPtrVector< type >::insertAtIter | ( | QPtrVectorIterator< type > & | it, | |
const type * | d | |||
) | [inline] |
Inserts item d into the list at where iterator it points.
References FXEXCEPTION_STL1, FXEXCEPTION_STL2, and FX::QPtrVectorIterator< type >::int_getIterator().
void FX::QPtrVector< type >::inSort | ( | const type * | d | ) | [inline] |
Inserts item d into the list in its correct sorted order.
void FX::QPtrVector< type >::append | ( | const type * | d | ) | [inline] |
Appends the item d onto the list.
bool FX::QPtrVector< type >::extend | ( | uint | no | ) | [inline] |
Extends the list to no items if not that already.
bool FX::QPtrVector< type >::remove | ( | uint | i | ) | [inline] |
Removes the item at index i.
bool FX::QPtrVector< type >::remove | ( | const type * | d | ) | [inline] |
Removes the specified item d via compareItems().
bool FX::QPtrVector< type >::removeRef | ( | const type * | d | ) | [inline] |
Removes the specified item d via pointer compare (quicker).
bool FX::QPtrVector< type >::removeByIter | ( | QPtrVectorIterator< type > & | it | ) | [inline] |
Removes the item pointed to by it (quickest).
References FX::QPtrVectorIterator< type >::int_getIterator().
bool FX::QPtrVector< type >::removeLast | ( | ) | [inline] |
Removes the last item.
type* FX::QPtrVector< type >::take | ( | uint | i | ) | [inline] |
Removes the item at index i without auto-deletion.
bool FX::QPtrVector< type >::take | ( | const type * | d | ) | [inline] |
Removes the specified item d via compareItems() without auto-deletion.
bool FX::QPtrVector< type >::takeRef | ( | const type * | d | ) | [inline] |
Removes the specified item d via pointer compare (quicker) without auto-deletion.
bool FX::QPtrVector< type >::takeByIter | ( | QPtrVectorIterator< type > & | it | ) | [inline] |
Removes the item pointed to by it without auto-deletion (quickest).
References FX::QPtrVectorIterator< type >::int_getIterator().
bool FX::QPtrVector< type >::takeLast | ( | ) | [inline] |
Removes the last item without auto-deletion.
void FX::QPtrVector< type >::clear | ( | ) | [inline] |
Clears the list.
void FX::QPtrVector< type >::sort | ( | SortFunc | sortfunc | ) | [inline] |
Sorts the list using a user supplied callable entity taking two pointers of type type.
void FX::QPtrVector< type >::sort | ( | ) | [inline] |
Sorts the list.
int FX::QPtrVector< type >::find | ( | const type * | d | ) | [inline] |
Returns the index of the position of item d via compareItems(), or -1 if not found.
int FX::QPtrVector< type >::findRef | ( | const type * | d | ) | [inline] |
Returns the index of the position of item d via pointer compare, or -1 if not found.
uint FX::QPtrVector< type >::contains | ( | const type * | d | ) | const [inline] |
Returns the number of item d in the list via compareItems().
uint FX::QPtrVector< type >::containsRef | ( | const type * | d | ) | const [inline] |
Returns the number of item d in the list via pointer compare.
bool FX::QPtrVector< type >::replace | ( | uint | i, | |
const type * | d, | |||
bool | callDeleteItem = true | |||
) | [inline] |
Replaces item at index i with d.
bool FX::QPtrVector< type >::replaceAtIter | ( | QPtrVectorIterator< type > & | it, | |
const type * | d, | |||
bool | callDeleteItem = true | |||
) | [inline] |
type* FX::QPtrVector< type >::at | ( | uint | i | ) | const [inline] |
Returns the item at index i.
type* FX::QPtrVector< type >::getFirst | ( | ) | const [inline] |
Returns the first item in the list.
type* FX::QPtrVector< type >::getLast | ( | ) | const [inline] |
Returns the last item in the list.
type* FX::QPtrVector< type >::first | ( | ) | [inline] |
Returns the first item in the list.
type* FX::QPtrVector< type >::last | ( | ) | [inline] |
Returns the last item in the list.
virtual int FX::QPtrVector< type >::compareItems | ( | type * | a, | |
type * | b | |||
) | const [inline, virtual] |
Compares two items (used by many methods above). Default returns -1 if a < b, +1 if a > b and 0 if a==b.
Referenced by FX::QPtrVector< TnFXGraphItem >::contains(), FX::QPtrVector< TnFXGraphItem >::find(), FX::QPtrVector< TnFXGraphItem >::inSort(), FX::QPtrVector< TnFXGraphItem >::remove(), and FX::QPtrVector< TnFXGraphItem >::take().