/usr/include/soprano/queryresultiterator.h is in libsoprano-dev 2.9.4+dfsg-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | /*
* This file is part of Soprano Project.
*
* Copyright (C) 2006 Daniele Galdi <daniele.galdi@gmail.com>
* Copyright (C) 2007-2009 Sebastian Trueg <trueg@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef SOPRANO_RESULT_SET_H
#define SOPRANO_RESULT_SET_H
#include "iterator.h"
#include "bindingset.h"
#include "statement.h"
#include "soprano_export.h"
#include <QtCore/QString>
#include <QtCore/QStringList>
namespace Soprano {
class Node;
class NodeIterator;
class QueryResultIteratorBackend;
class StatementIterator;
class BindingSet;
/**
* \class QueryResultIterator queryresultiterator.h Soprano/QueryResultIterator
*
* \brief An iterator for query results.
*
* %Query results in %Soprano are wrapped in a QueryResultIterator.
*
* %Query iterators are returned by Model::executeQuery(). In contrast to
* NodeIterator or StatementIterator %QueryResultIterator has a set of different
* access methods for the current dataset which can be one of three things:
*
* \li A Statement: Graph query results are represented as a stream of statements.
* See also currentStatement() and iterateStatements().
* \li A BindingSet: Tuple query results are represented by a set of variable bindings
* according to the variables used in the query. The bindings can be accessed as a set
* through the normal Iterator method current() or separately through #binding(int) const or
* #binding(const QString&) const.
* \li A boolean value: This is a special case in which the query was a boolean query
* (a SPARQL ASK query). In this case there is nothing to iterate but only a single
* boolean value which can be accessed through boolValue().
*
* <b>Example:</b>
*
* \code
* QueryResultIterator it = model->executeQuery( someGraphQuery );
* while( it.next() ) {
* doSomething( it.currentStatement() );
* }
*
* QueryResultIterator it2 = model->executeQuery( someTupleQuery );
* while( it.next() ) {
* doSomethingElse( it.currentBindings() );
* doSomethingCompletelyDifferent( it.binding( "x" ) );
* doSomethingEntirelyDifferent( it.binding( 0 ) );
* }
* \endcode
*
* 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:
*
* \code
* Soprano::QueryResultIterator it = model->executeQuery( someTupleQuery );
* QList<BindingSet> allBindings = it.allBindings();
* Q_FOREACH( Soprano::BindingSet bs, allBindings ) {
* modifyTheModel( model, bs );
* }
* \endcode
*
* Iterators have to be closed.
* This can either be achieved by deleting the iterator, finishing it (next() does return \p 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.
*
* \author Daniele Galdi <daniele.galdi@gmail.com><br>Sebastian Trueg <trueg@kde.org>
*/
class SOPRANO_EXPORT QueryResultIterator : public Iterator<BindingSet>
{
public:
//@{
/**
* Creates and empty, invalid iterator.
*/
QueryResultIterator();
/**
* Copy constructor. Copies of iterators share their data.
*/
QueryResultIterator( const QueryResultIterator& );
/**
* Create a new QueryResultIterator which uses qr as backend.
* QueryResultIterator will take ownership of the QueryResultIteratorBackend.
*/
QueryResultIterator( QueryResultIteratorBackend *qr );
/**
* Destructor.
*/
virtual ~QueryResultIterator();
/**
* Copies of iterators share their data.
*/
QueryResultIterator& operator=( const QueryResultIterator& );
//@}
//@{
/**
* Retrieve the current Statement after a call to next.
* This method does only make sense for graph queries.
*/
Statement currentStatement() const;
/**
* Convenience method that puts all current bindings into one map.
* This method does only make sense for tuple queries.
*/
BindingSet currentBindings() const;
/**
* This method does only make sense for boolean queries.
*
* \return The result of a boolean query (SPARQL ASK).
*
* \sa isBool()
*/
bool boolValue() const;
//@}
//@{
/**
* Get the current binding for a variable by index.
*
* \param offset The index of the requested variable.
*
* This is equivalent to binding(int) const.
*
* \return The binding for the requested variable or and invalid
* node if offset is out of bounds, i.e. bigger or equal to bindingCount().
*
* \since 2.2
*/
Node operator[]( int offset ) const;
/**
* Get the current binding for a variable.
*
* \param name The name of the requested variable.
*
* This is equivalent to binding(const QString&) const.
*
* \return The binding for the requested variable or and invalid
* node if the bindings do not contain the variable.
*
* \since 2.2
*/
Node operator[]( const QString name ) const;
/**
* Get the current binding for a variable.
*
* \param name The name of the requested variable.
*
* This method does only make sense for tuple queries.
*
* \return The binding for the requested variable or and invalid
* node if the bindings do not contain the variable.
*/
Node binding( const QString &name ) const;
/**
* Get the current binding for a variable by index.
*
* \param offset The index of the requested variable.
*
* This method does only make sense for tuple queries.
*
* \return The binding for the requested variable or and invalid
* node if offset is out of bounds, i.e. bigger or equal to bindingCount().
*/
Node binding( int offset ) const;
/**
* The number of bindings in this query result.
*
* This method does only make sense for tuple queries.
*
* \return The number of bindings.
*/
int bindingCount() const;
/**
* This method does only make sense for tuple queries.
*
* \return The names of the bound variables in this query result.
*/
QStringList bindingNames() const;
//@}
//@{
/**
* Check if this is a graph result.
*
* \return \p true if this result refers to a graph query, i.e. currentStatement()
* and iterateStatements() return valid values.
*/
bool isGraph() const;
/**
* Check if this is a tuple result.
*
* \return \p true if this result refers to a tuple query, i.e. currentBindings(),
* binding(), bindingCount(), bindingNames(), and allBindings() return valid values.
*/
bool isBinding() const;
/**
* Check if this is a boolean result.
*
* There is no need to call next() for boolean results.
*
* \return \p true if this result refers to a boolean query (SPARQL ASK), i.e.
* boolValue() returns a valid value.
*/
bool isBool() const;
//@}
//@{
/**
* Convenience method that collects all binding sets that are left
* in the iterator.
*/
QList<BindingSet> allBindings();
/**
* Convenience method that creates an iterator over the statements in this query result.
* This method does only make sense for graph queries.
*
* \warning The new iterator is just a wrapper around this one. Thus, changing it will also
* change this one.
*
* \return A wrapper iterator over the statements in a graph query.
*/
StatementIterator iterateStatements() const;
/**
* Convenience method that creates an iterator over one column of bindings in this query result.
* This method does only make sense for tuple queries.
*
* \param variableName The name of the requested variable.
*
* \warning The new iterator is just a wrapper around this one. Thus, changing it will also
* change this one.
*
* \return A wrapper iterator over one column in a tuple query or an invalid iterator if the
* result does not contain bindings for variableName.
*/
NodeIterator iterateBindings( const QString& variableName ) const;
/**
* Convenience method that creates an iterator over one column of bindings in this query result.
* This method does only make sense for tuple queries.
*
* \param offset The index of the requested variable.
*
* \warning The new iterator is just a wrapper around this one. Thus, changing it will also
* change this one.
*
* \return A wrapper iterator over one column in a tuple query or an invalid iterator
* if offset is out of bounds, i.e. bigger or equal to bindingCount().
*/
NodeIterator iterateBindings( int offset ) const;
/**
* Convenience method that creates an iterator over statements constructed from the values of the
* provided bindings.
*
* The typical usage would be with a query as follows:
*
* \code
* Soprano::StatementIterator it =
* model->executeQuery( "select * where { graph ?c { ?s ?p ?o . } }" )
* .iterateStatementsFromBindings( "s", "p", "o", "c" );
* \endcode
*
* \param subjectBindingName The name of the binding that will be used to set the subject of the
* constructed statements.
* \param predicateBindingName The name of the binding that will be used to set the predicate of the
* constructed statements.
* \param objectBindingName The name of the binding that will be used to set the object of the
* constructed statements.
* \param contextBindingName The name of the binding that will be used to set the context of the
* constructed statements.
* \param templateStatement If any of the provided binding names is empty the corresponding nodes
* in the resulting statements will be filled by templateStatement.
*
* \warning The new iterator is just a wrapper around this one. Thus, changing it will also
* change this one.
*
* \return A wrapper iterator over statements constructed from the specified bindings.
*
* \since 2.2
*/
StatementIterator iterateStatementsFromBindings( const QString& subjectBindingName,
const QString& predicateBindingName,
const QString& objectBindingName,
const QString& contextBindingName = QString(),
const Statement& templateStatement = Statement() ) const;
//@}
};
}
#endif // SOPRANO_RESULT_SET_H
|