#include <Soprano/Iterator>
Public Member Functions | |
Iterator () | |
Iterator (IteratorBackend< T > *sti) | |
Iterator (const Iterator &sti) | |
virtual | ~Iterator () |
Iterator & | operator= (const Iterator &) |
void | close () |
bool | next () |
T | current () const |
T | operator* () const |
bool | isValid () const |
QList< T > | allElements () |
Protected Member Functions | |
void | setBackend (IteratorBackend< T > *b) |
IteratorBackend< T > * | backend () const |
Iterators in Soprano are very easy to use through two methods next() and current(). Instead of the latter operator*() can also be used. Both can be called subsequetially to retrieve the current element until next() has been called again.
Soprano::Iterator<X> it; while( it.next() ) { doSomething( *it ); doSomethingElse( it.current() ); }
Many backends do lock the underlying Model during iteration. Thus, it is always a good idea to cache the results if they are to be used to modify the model to prevent a deadlock:
Soprano::StatementIterator it = model->listStatements(); QList<Statement> allStatements = it.allElements(); Q_FOREACH( Soprano::Statement s, allStatements ) { modifyTheModel( model, s ); }
Iterators have to be closed. This can either be achieved by deleting the iterator, finishing it (next() does return false
), or calling close(). Before that other operations on the Model may block.
Iterators are not thread-safe. Two threads using the same iterator at the same time may result in undefined behaviour and even crashes.
Definition at line 76 of file iterator.h.
Soprano::Iterator< T >::Iterator | ( | ) |
Creates and empty, invalid iterator.
Soprano::Iterator< T >::Iterator | ( | IteratorBackend< T > * | sti | ) |
Soprano::Iterator< T >::Iterator | ( | const Iterator< T > & | sti | ) |
virtual Soprano::Iterator< T >::~Iterator | ( | ) | [virtual] |
Iterator& Soprano::Iterator< T >::operator= | ( | const Iterator< T > & | ) |
void Soprano::Iterator< T >::close | ( | ) |
Close the iterator and release any locks on the underlying Model.
bool Soprano::Iterator< T >::next | ( | ) |
Advances to the next element in the iterator.
T Soprano::Iterator< T >::current | ( | ) | const |
Get the element the iterator currently points to. Be aware that a valid current element is only available if next() returned true
.
T Soprano::Iterator< T >::operator* | ( | ) | const |
Retrieve the current element in the iterator.
This is equivalent to current().
bool Soprano::Iterator< T >::isValid | ( | ) | const |
true
if the Iterator is valid, false
otherwise. (An invalid iterator has no backend.) QList<T> Soprano::Iterator< T >::allElements | ( | ) |
Convenience method which extracts all elements (this does not include the elements that have already been read from the iterator) from the iterator and returns them in a list.
Be aware that after calling this method the iterator will be invalid.
void Soprano::Iterator< T >::setBackend | ( | IteratorBackend< T > * | b | ) | [protected] |
Set the backend to read the actual data from. A previous backend will be deleted if there are no other Iterator instances using it.
IteratorBackend<T>* Soprano::Iterator< T >::backend | ( | ) | const [protected] |