Chris@439: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@439: Chris@439: /* Chris@439: Sonic Visualiser Chris@439: An audio file viewer and annotation editor. Chris@439: Centre for Digital Music, Queen Mary, University of London. Chris@439: This file copyright 2008 QMUL. Chris@439: Chris@439: This program is free software; you can redistribute it and/or Chris@439: modify it under the terms of the GNU General Public License as Chris@439: published by the Free Software Foundation; either version 2 of the Chris@439: License, or (at your option) any later version. See the file Chris@439: COPYING included with this distribution for more information. Chris@439: */ Chris@439: Chris@439: #ifndef _SIMPLE_SPARQL_QUERY_H_ Chris@439: #define _SIMPLE_SPARQL_QUERY_H_ Chris@439: Chris@724: #ifdef NOT_DEFINED Chris@724: Chris@439: #include Chris@439: #include Chris@439: #include Chris@439: Chris@686: #include "base/Debug.h" Chris@686: Chris@439: class ProgressReporter; Chris@439: Chris@439: class SimpleSPARQLQuery Chris@439: { Chris@439: public: Chris@439: enum ValueType { NoValue, URIValue, LiteralValue, BlankValue }; Chris@439: Chris@439: struct Value { Chris@439: Value() : type(NoValue), value() { } Chris@439: Value(ValueType t, QString v) : type(t), value(v) { } Chris@439: ValueType type; Chris@439: QString value; Chris@439: }; Chris@439: Chris@439: typedef std::map KeyValueMap; Chris@439: typedef std::vector ResultList; Chris@439: Chris@492: /** Chris@492: * QueryType specifies the context in which the query will be Chris@492: * evaluated. SimpleSPARQLQuery maintains a general global data Chris@492: * model, into which data can be loaded using addSourceToModel(), Chris@492: * as well as permitting one-time queries directly on data sources Chris@492: * identified by URL. Chris@492: * Chris@492: * The query type QueryFromModel indicates a query to be evaluated Chris@492: * over the general global model; the query type Chris@492: * QueryFromSingleSource indicates that the query should be Chris@492: * evaluated in the context of a model generated solely by parsing Chris@492: * the FROM url found in the query. Chris@492: * Chris@492: * Even in QueryFromSingleSource mode, the parsed data remains in Chris@492: * memory and will be reused in subsequent queries with the same Chris@492: * mode and FROM url. To release data loaded in this way once all Chris@492: * queries across it are complete, pass the said FROM url to Chris@492: * closeSingleSource(). Chris@492: */ Chris@489: enum QueryType { Chris@489: QueryFromModel, Chris@489: QueryFromSingleSource Chris@489: }; Chris@489: Chris@492: /** Chris@492: * Construct a query of the given type (indicating the data model Chris@492: * context for the query) using the given SPARQL query content. Chris@492: */ Chris@489: SimpleSPARQLQuery(QueryType type, QString query); Chris@439: ~SimpleSPARQLQuery(); Chris@439: Chris@492: /** Chris@492: * Add the given URI to the general global model used for Chris@492: * QueryFromModel queries. Chris@492: */ Chris@489: static bool addSourceToModel(QString sourceUri); Chris@489: Chris@492: /** Chris@492: * Release any data that has been loaded from the given source as Chris@492: * part of a QueryFromSingleSource query with this source in the Chris@492: * FROM clause. Note this will not prevent any subsequent queries Chris@492: * on the source from working -- it will just make them slower as Chris@492: * the data will need to be re-parsed. Chris@492: */ Chris@492: static void closeSingleSource(QString sourceUri); Chris@492: Chris@439: void setProgressReporter(ProgressReporter *reporter); Chris@439: bool wasCancelled() const; Chris@439: Chris@439: ResultList execute(); Chris@439: Chris@439: bool isOK() const; Chris@439: QString getErrorString() const; Chris@439: Chris@492: /** Chris@492: * Construct and execute a query, and return the first result Chris@492: * value for the given binding. Chris@492: */ Chris@489: static Value singleResultQuery(QueryType type, Chris@480: QString query, Chris@480: QString binding); Chris@480: Chris@439: protected: Chris@439: class Impl; Chris@439: Impl *m_impl; Chris@589: Chris@589: private: Chris@589: SimpleSPARQLQuery(const SimpleSPARQLQuery &); // not provided Chris@589: SimpleSPARQLQuery &operator=(const SimpleSPARQLQuery &); // not provided Chris@439: }; Chris@439: Chris@439: #endif Chris@724: Chris@724: #endif