summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slv2/query.h89
-rw-r--r--slv2/slv2.h1
-rw-r--r--slv2/types.h5
3 files changed, 94 insertions, 1 deletions
diff --git a/slv2/query.h b/slv2/query.h
new file mode 100644
index 0000000..aa25436
--- /dev/null
+++ b/slv2/query.h
@@ -0,0 +1,89 @@
+/* SLV2
+ * Copyright (C) 2008 Dave Robillard <http://drobilla.net>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU 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 General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __SLV2_QUERY_H__
+#define __SLV2_QUERY_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/** Query a plugin with an arbitrary SPARQL string.
+ */
+SLV2Results
+slv2_plugin_query_sparql(SLV2Plugin plugin,
+ const char* sparql_str);
+
+
+/** Free query results.
+ */
+void
+slv2_results_free(SLV2Results results);
+
+
+/** Return the number of matches in \a results.
+ * Note this should not be used to iterate over a result set (since it will
+ * iterate to the end of \a results and rewinding is impossible).
+ * Instead, use slv2_results_next and slv2_results_finished repeatedly.
+ */
+unsigned
+slv2_results_size(SLV2Results results);
+
+
+/** Return true iff the end of \a results has been reached.
+ */
+bool
+slv2_results_finished(SLV2Results results);
+
+
+/** Return a binding in \a results by index.
+ * Indices correspond to selected variables in the query in order of appearance.
+ * \return NULL if binding value can not be expressed as an SLV2Value.
+ */
+SLV2Value
+slv2_results_get_binding_value(SLV2Results results, unsigned index);
+
+
+/** Return a binding in \a results by name.
+ * \a name corresponds to the name of the SPARQL variable (without the '?').
+ * \return NULL if binding value can not be expressed as an SLV2Value.
+ */
+SLV2Value
+slv2_results_get_binding_value_by_name(SLV2Results results, const char* name);
+
+
+/** Return the name of a binding in \a results.
+ * Indices correspond to selected variables in the query in order of appearance.
+ */
+const char*
+slv2_results_get_binding_name(SLV2Results results, unsigned index);
+
+
+/** Increment \a results to the next match.
+ */
+void
+slv2_results_next(SLV2Results results);
+
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+
+#endif /* __SLV2_QUERY_H__ */
diff --git a/slv2/slv2.h b/slv2/slv2.h
index 4381259..0960282 100644
--- a/slv2/slv2.h
+++ b/slv2/slv2.h
@@ -30,6 +30,7 @@ extern "C" {
#include "slv2/pluginui.h"
#include "slv2/pluginuiinstance.h"
#include "slv2/port.h"
+#include "slv2/query.h"
#include "slv2/scalepoint.h"
#include "slv2/types.h"
#include "slv2/util.h"
diff --git a/slv2/types.h b/slv2/types.h
index d17568f..0e18d6d 100644
--- a/slv2/types.h
+++ b/slv2/types.h
@@ -84,10 +84,13 @@ typedef struct _SLV2UI* SLV2UI;
typedef void* SLV2UIs;
+/** A set of query results (conceptually a table) */
+typedef struct _SLV2Results* SLV2Results;
+
+
#ifdef __cplusplus
} /* extern "C" */
#endif
-
#endif /* __SLV2_TYPES_H__ */