KVIrc
4.9.2
DeveloperAPIs
|
A fast KviPointerList iterator. More...
#include <KviPointerList.h>
Public Member Functions | |
T * | current () |
Returs the value pointed by the iterator. More... | |
bool | isValid () |
Returns true if this iterator points to a valid element. More... | |
KviPointerListIterator (const KviPointerListIterator< T > &src) | |
Creates an iterator copy. More... | |
KviPointerListIterator (KviPointerList< T > &l) | |
Creates an iterator for the list l. More... | |
KviPointerListIterator (KviPointerList< T > &l, KviPointerListNode *pNode) | |
Creates an iterator for the list l. More... | |
bool | moveFirst () |
Moves the iterator to the first element of the list. More... | |
bool | moveLast () |
Moves the iterator to the last element of the list. More... | |
bool | moveNext () |
Moves the iterator to the next element of the list. More... | |
bool | movePrev () |
Moves the iterator to the previous element of the list. More... | |
T * | operator* () |
Returs the value pointed by the iterator. More... | |
bool | operator++ () |
Moves the iterator to the next element of the list. More... | |
bool | operator-- () |
Moves the iterator to the previous element of the list. More... | |
void | operator= (const KviPointerListIterator< T > &src) |
Creates an iterator copy. More... | |
Protected Attributes | |
KviPointerList< T > * | m_pList |
KviPointerListNode * | m_pNode |
A fast KviPointerList iterator.
This class allows traversing the list sequentially. Multilpe iterators can traverse the list at the same time.
Iteration example 1:
* KviPointerListIterator<T> it(list); * for(bool b = it.moveFirst(); b; b = it.moveNext()) * { * T * pData = it.data(); * doSomethingWithData(pData); * } *
Iteration example 2:
* KviPointerListIterator<T> it(list); * if(it.moveFirst()) * { * do { * T * pData = it.data(); * doSomethingWithData(pData); * } while(it.moveNext()); * } *
Iteration example 3:
* KviPointerListIterator<T> it(list.iteratorAt(10)); * if(it.isValid()) * { * do { * T * pData = it.data(); * doSomethingWithData(pData); * while(it.movePrev()); * } *
Please note that you must NOT remove any item from the list when using the iterators. An iterator pointing to a removed item will crash your application if you use it. The following code will NOT work (and crash):
* KviPointerList<T> l; * l.append(new KviCString("x")); * l.append(new KviCString("y")); * KviPointerListIterator<T> it(l); * it.moveFirst(); * l.removeFirst(); * KviCString * tmp = it.data(); <-- this will crash *
In the rare cases in that you need to remove items while traversing the list you should put them in a temporary list and remove them after the iteration.
I've chosen this way because usually you don't modify the list while traversing it and a fix for this would add a constant overhead to several list operation. You just must take care of it yourself.
|
inline |
Creates an iterator copy.
The new iterator points exactly to the item pointed by src.
src | The source item to point to |
|
inline |
Creates an iterator for the list l.
The iterator points to the first list item, if any.
l | The source list to point to |
|
inline |
Creates an iterator for the list l.
The iterator points to the specified list node.
l | The source list |
pNode | The list node to point to |
|
inline |
Returs the value pointed by the iterator.
If the iterator is not valid, returns NULL.
Referenced by KviPointerHashTableIterator< Key, T >::current(), KviPointerHashTableIterator< Key, T >::currentKey(), KviKvsObject::disconnectSignal(), KviKvsObject::emitSignal(), KviKvsTreeNodeDataList::evaluate(), KviKvsTreeNodeCompositeData::evaluateReadOnly(), KviKvsTreeNodeInstructionBlock::execute(), KviPointerHashTableIterator< Key, T >::operator*(), KviMainWindow::setButtonStyle(), KviMainWindow::setIconSize(), spaste_kvs_cmd_list(), and spaste_kvs_cmd_stop().
|
inline |
Returns true if this iterator points to a valid element.
Returns false otherwise.
|
inline |
Moves the iterator to the first element of the list.
Returns true in case of success or false if the list is empty.
Referenced by KviPointerHashTableIterator< Key, T >::moveFirst(), KviPointerHashTableIterator< Key, T >::moveNext(), spellchecker_kvs_check(), and spellchecker_kvs_suggestions().
|
inline |
Moves the iterator to the last element of the list.
Returns true in case of success or false if the list is empty.
Referenced by KviPointerHashTableIterator< Key, T >::moveLast(), and KviPointerHashTableIterator< Key, T >::movePrev().
|
inline |
Moves the iterator to the next element of the list.
The iterator must be actually valid for this function to work. Returns true in case of success or false if there is no next item.
Referenced by KviPointerHashTableIterator< Key, T >::moveNext(), spellchecker_kvs_check(), and spellchecker_kvs_suggestions().
|
inline |
Moves the iterator to the previous element of the list.
The iterator must be actually valid for this function to work. Returns true in case of success or false if there is no previous item.
Referenced by KviPointerHashTableIterator< Key, T >::movePrev().
|
inline |
Returs the value pointed by the iterator.
If the iterator is not valid, returns NULL. This is just an alias to current().
|
inline |
Moves the iterator to the next element of the list.
The iterator must be actually valid for this operator to work. Returns true in case of success or false if there is no next item. This is just a convenient alias to moveNext().
|
inline |
Moves the iterator to the previous element of the list.
The iterator must be actually valid for this operator to work. Returns true in case of success or false if there is no previous item. This is just a convenient alias to movePrev().
|
inline |
Creates an iterator copy.
The new iterator points exactly to the item pointed by src.
src | The source item to copy |
|
protected |
Referenced by KviPointerListIterator< KviPointerHashTableEntry< Key, T > >::KviPointerListIterator(), KviPointerListIterator< KviPointerHashTableEntry< Key, T > >::moveFirst(), KviPointerListIterator< KviPointerHashTableEntry< Key, T > >::moveLast(), and KviPointerListIterator< KviPointerHashTableEntry< Key, T > >::operator=().
|
protected |
Referenced by KviPointerListIterator< KviPointerHashTableEntry< Key, T > >::current(), KviPointerListIterator< KviPointerHashTableEntry< Key, T > >::isValid(), KviPointerListIterator< KviPointerHashTableEntry< Key, T > >::KviPointerListIterator(), KviPointerListIterator< KviPointerHashTableEntry< Key, T > >::moveFirst(), KviPointerListIterator< KviPointerHashTableEntry< Key, T > >::moveLast(), KviPointerListIterator< KviPointerHashTableEntry< Key, T > >::moveNext(), KviPointerListIterator< KviPointerHashTableEntry< Key, T > >::movePrev(), KviPointerListIterator< KviPointerHashTableEntry< Key, T > >::operator*(), KviPointerListIterator< KviPointerHashTableEntry< Key, T > >::operator++(), KviPointerListIterator< KviPointerHashTableEntry< Key, T > >::operator--(), and KviPointerListIterator< KviPointerHashTableEntry< Key, T > >::operator=().