Soprano  2.9.4
Public Member Functions | Protected Member Functions | List of all members
Soprano::Iterator< T > Class Template Reference

The basic Soprano iterator class. More...

#include <Soprano/Iterator>

+ Inheritance diagram for Soprano::Iterator< T >:

Public Member Functions

 Iterator ()
 
 Iterator (IteratorBackend< T > *sti)
 
 Iterator (const Iterator &sti)
 
virtual ~Iterator ()
 
Iteratoroperator= (const Iterator &)
 
void close ()
 
bool next ()
 
current () const
 
operator* () const
 
bool isValid () const
 
QList< T > allElements ()
 
- Public Member Functions inherited from Soprano::Error::ErrorCache
virtual ~ErrorCache ()
 
virtual Error lastError () const
 

Protected Member Functions

void setBackend (IteratorBackend< T > *b)
 
IteratorBackend< T > * backend () const
 
- Protected Member Functions inherited from Soprano::Error::ErrorCache
 ErrorCache ()
 
void clearError () const
 
void setError (const Error &) const
 
void setError (const QString &errorMessage, int code=ErrorUnknown) const
 

Detailed Description

template<typename T>
class Soprano::Iterator< T >

The basic Soprano iterator class.

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.

while( it.next() ) {
doSomething( *it );
doSomethingElse( it.current() );
}
The basic Soprano iterator class.
Definition: iterator.h:79

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 );
}
QList< T > allElements()
An iterator that provides a stream of Statements.
A Statement instance represents one RDF quadruple.
Definition: statement.h:48

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.
Author
Daniele Galdi danie.nosp@m.le.g.nosp@m.aldi@.nosp@m.gmai.nosp@m.l.com
Sebastian Trueg trueg.nosp@m.@kde.nosp@m..org

Definition at line 78 of file iterator.h.

Constructor & Destructor Documentation

◆ Iterator() [1/3]

template<typename T >
Soprano::Iterator< T >::Iterator ( )

Creates and empty, invalid iterator.

◆ Iterator() [2/3]

template<typename T >
Soprano::Iterator< T >::Iterator ( IteratorBackend< T > *  sti)

Create a new Iterator instance that uses sti as backend. Iterator will take ownership of the backend.

◆ Iterator() [3/3]

template<typename T >
Soprano::Iterator< T >::Iterator ( const Iterator< T > &  sti)

◆ ~Iterator()

template<typename T >
virtual Soprano::Iterator< T >::~Iterator ( )
virtual

Member Function Documentation

◆ operator=()

template<typename T >
Iterator& Soprano::Iterator< T >::operator= ( const Iterator< T > &  )

◆ close()

template<typename T >
void Soprano::Iterator< T >::close ( )

Close the iterator and release any locks on the underlying Model.

◆ next()

template<typename T >
bool Soprano::Iterator< T >::next ( )

Advances to the next element in the iterator.

Returns
true if another element can be read from the iterator, false if the end has been reached.

◆ current()

template<typename T >
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.

Returns
the current element.

◆ operator*()

template<typename T >
T Soprano::Iterator< T >::operator* ( ) const

Retrieve the current element in the iterator.

This is equivalent to current().

Returns
The element the iterator currently points to or an invalid one if next has never been called.

◆ isValid()

template<typename T >
bool Soprano::Iterator< T >::isValid ( ) const
Returns
true if the Iterator is valid, false otherwise. (An invalid iterator has no backend.)

◆ allElements()

template<typename T >
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.

Returns
A list of all elements that rest in the iterator.

◆ setBackend()

template<typename T >
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.

◆ backend()

template<typename T >
IteratorBackend<T>* Soprano::Iterator< T >::backend ( ) const
protected

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