File: rdf_query_internal.h

package info (click to toggle)
redland 1.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 27,592 kB
  • ctags: 12,328
  • sloc: ansic: 79,017; xml: 25,115; sh: 10,162; yacc: 5,985; lex: 3,682; makefile: 3,260; perl: 2,814; cpp: 59
file content (180 lines) | stat: -rw-r--r-- 6,179 bytes parent folder | download
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
/* -*- Mode: c; c-basic-offset: 2 -*-
 *
 * rdf_query_internal.h - Internal RDF Query definitions
 *
 * $Id: rdf_query_internal.h 13284 2007-12-18 09:03:42Z laalto $
 *
 * Copyright (C) 2002-2006, David Beckett http://purl.org/net/dajobe/
 * Copyright (C) 2002-2005, University of Bristol, UK http://www.bristol.ac.uk/
 * 
 * This package is Free Software and part of Redland http://librdf.org/
 * 
 * It is licensed under the following three licenses as alternatives:
 *   1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
 *   2. GNU General Public License (GPL) V2 or any newer version
 *   3. Apache License, V2.0 or any newer version
 * 
 * You may not use this file except in compliance with at least one of
 * the above three licenses.
 * 
 * See LICENSE.html or LICENSE.txt at the top of this package for the
 * complete terms and further detail along with the license texts for
 * the licenses in COPYING.LIB, COPYING and LICENSE-2.0.txt respectively.
 * 
 * 
 */


#ifndef LIBRDF_QUERY_INTERNAL_H
#define LIBRDF_QUERY_INTERNAL_H

#ifdef __cplusplus
extern "C" {
#endif

/** A query object */
struct librdf_query_s
{
  librdf_world *world;
  int usage;
  void *context;
  struct librdf_query_factory_s* factory;

  /* list of all the results for this query */
  librdf_query_results* results;
};


struct librdf_query_results_s
{
  /* query that this was executed over */
  librdf_query* query;

  /* next query result */
  librdf_query_results* next;
};


#ifdef RASQAL_H
/* rasqal.h will have defined this */
#else
/* provide a forward reference */
#ifndef RASQAL_QUERY_RESULTS_FORMATTER_DECLARED
#define RASQAL_QUERY_RESULTS_FORMATTER_DECLARED 1
typedef struct rasqal_query_results_formatter_s rasqal_query_results_formatter;
#endif
#endif

struct librdf_query_results_formatter_s
{
  /* query result that this is formatting */
  librdf_query_results* query_results;

  rasqal_query_results_formatter *formatter;
};
  

/** A Query Factory */
struct librdf_query_factory_s {
  librdf_world *world;
  struct librdf_query_factory_s* next;
  char* name;       /* name of query language - required */
  librdf_uri *uri;  /* URI of query language - may be NULL */
  
  /* the rest of this structure is populated by the
   * query-specific register function */
  size_t context_length;
  
  /* create a new query */
  int (*init)(librdf_query* query, const char *name, librdf_uri *uri, const unsigned char *query_string, librdf_uri *base_uri);
  
  /* copy a query */
  /* clone is assumed to do leave the new query in the same state
   * after an init() method on an existing query - i.e ready to
   * use but closed.
   */
  int (*clone)(librdf_query* new_query, librdf_query* old_query);

  /* destroy a query */
  void (*terminate)(librdf_query* query);
  
  /* perform the query on a model */
  librdf_query_results* (*execute)(librdf_query* query, librdf_model* model);

  /* get/set query results limit (max results to return) */
  int (*get_limit)(librdf_query *query);
  int (*set_limit)(librdf_query *query, int limit);
  /* get/set query results offset (results to skip) */
  int (*get_offset)(librdf_query *query);
  int (*set_offset)(librdf_query *query, int offset);

  /* get the query results as a stream - OPTIONAL */
  librdf_stream* (*results_as_stream)(librdf_query_results* query_results);

  /* get number of results (so far) - OPTIONAL */
  int (*results_get_count)(librdf_query_results* query_results);

  /* get next result - OPTIONAL */
  int (*results_next)(librdf_query_results* query_results);

  /* find out if binding results are exhausted - OPTIONAL */
  int (*results_finished)(librdf_query_results* query_results);

  /* get all binding names, values for current result - OPTIONAL */
  int (*results_get_bindings)(librdf_query_results* query_results, const char ***names, librdf_node **values);

  /* get one value for current result - OPTIONAL */
  librdf_node* (*results_get_binding_value)(librdf_query_results* query_results, int offset);

  /* get one name for current result - OPTIONAL */
  const char* (*results_get_binding_name)(librdf_query_results* query_results, int offset);

  /* get one value by name for current result - OPTIONAL */
  librdf_node* (*results_get_binding_value_by_name)(librdf_query_results* query_results, const char *name);

  /* get number of bound variables in the result - OPTIONAL */
  int (*results_get_bindings_count)(librdf_query_results* query_results);

  /* tidy up query results - OPTIONAL */
  void (*free_results)(librdf_query_results* query_results);

  /* Return true/false if result is format given - OPTIONAL */
  int (*results_is_bindings)(librdf_query_results *query_results);
  int (*results_is_boolean)(librdf_query_results *query_results);
  int (*results_is_graph)(librdf_query_results *query_results);
  int (*results_is_syntax)(librdf_query_results *query_results);
  
  /* get a boolean result - OPTIONAL */
  int (*results_get_boolean)(librdf_query_results *query_results);

  /* query results formatter */
  librdf_query_results_formatter* (*new_results_formatter)(librdf_query_results* query_results, const char *name, librdf_uri* uri);
  librdf_query_results_formatter* (*new_results_formatter_by_mime_type)(librdf_query_results* query_results, const char *mime_type);
  void (*free_results_formatter)(librdf_query_results_formatter* formatter);
  int (*results_formatter_write)(raptor_iostream *iostr, librdf_query_results_formatter* formatter, librdf_query_results* results, librdf_uri *base_uri);
};


/* module init */
void librdf_init_query(librdf_world *world);

/* module terminate */
void librdf_finish_query(librdf_world *world);

/* class methods */
librdf_query_factory* librdf_get_query_factory(librdf_world *world, const char *name, librdf_uri* uri);

void librdf_query_triples_constructor(librdf_world *world);
void librdf_query_rasqal_constructor(librdf_world *world);

void librdf_query_rasqal_destructor(void);

void librdf_query_add_query_result(librdf_query *query, librdf_query_results* query_results);
void librdf_query_remove_query_result(librdf_query *query, librdf_query_results* query_results);


#ifdef __cplusplus
}
#endif

#endif