StatementIterator Class Reference
from PyKDE4.soprano import *
Namespace: Soprano
Detailed Description
\class StatementIterator statementiterator.h Soprano/StatementIterator
An iterator that provides a stream of Statements.
The most common use of StatementIterator is through Model.listStatements().
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 may result in undefined behaviour and even crashes. An iterator needs to be closed by the same thread that opened it (except if the iterator contains special code to handle such a situation.)
- Warning:
- Be aware that iterators in Soprano are shared objects which means that copies of one iterator object work on the same data.
For further details on %Soprano iterators see Iterator.
Methods | |
__init__ (self) | |
__init__ (self, Soprano.StatementIterator sti) | |
[Soprano.Statement] | allElements (self) |
[Soprano.Statement] | allStatements (self) |
close (self) | |
Soprano.Statement | current (self) |
bool | isValid (self) |
Soprano.NodeIterator | iterateContexts (self) |
Soprano.NodeIterator | iterateObjects (self) |
Soprano.NodeIterator | iteratePredicates (self) |
Soprano.NodeIterator | iterateSubjects (self) |
bool | next (self) |
Method Documentation
__init__ | ( | self ) |
Creates and empty, invalid iterator.
__init__ | ( | self, | ||
Soprano.StatementIterator | sti | |||
) |
Create a new StatementIterator instance that uses sti as backend. StatementIterator will take ownership of the backend.
[Soprano.Statement] allElements | ( | self ) |
[Soprano.Statement] allStatements | ( | self ) |
Convenience method which extracts all statements (this does not include the statements 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.
- Returns:
- A list of all statements that rest in the iterator.
close | ( | self ) |
Soprano.Statement current | ( | self ) |
bool isValid | ( | self ) |
Soprano.NodeIterator iterateContexts | ( | self ) |
Convenience method that creates an iterator over the context nodes of the statements in this iterator.
- Warning:
- The new iterator is just a wrapper around this one. Thus, changing it will also change this one.
- Returns:
- A wrapper iterator over the context nodes.
Soprano.NodeIterator iterateObjects | ( | self ) |
Convenience method that creates an iterator over the object nodes of the statements in this iterator.
- Warning:
- The new iterator is just a wrapper around this one. Thus, changing it will also change this one.
- Returns:
- A wrapper iterator over the object nodes.
Soprano.NodeIterator iteratePredicates | ( | self ) |
Convenience method that creates an iterator over the predicate nodes of the statements in this iterator.
- Warning:
- The new iterator is just a wrapper around this one. Thus, changing it will also change this one.
- Returns:
- A wrapper iterator over the predicate nodes.
Soprano.NodeIterator iterateSubjects | ( | self ) |
Convenience method that creates an iterator over the subject nodes of the statements in this iterator.
- Warning:
- The new iterator is just a wrapper around this one. Thus, changing it will also change this one.
- Returns:
- A wrapper iterator over the subject nodes.
bool next | ( | self ) |