Cleanup Tuple to allow self-typing.
[rrq/rrqmisc.git] / vector / Query.h
1 #ifndef Query_H
2 #define Query_H
3
4 #include <TupleSchema.h>
5 #include <Relation.h>
6 #include <BindingTable.h>
7
8 struct QueryCallbacks;
9
10 /**
11  * A Query is an implementation of a generic ABI over relations. It's
12  * more or less a "virtual Relation" representing a logical composite
13  * access of actual relations, and as such its active part is held in
14  * a separate \ref Querytype record similar to how \ref ItemKeyFun
15  * records define valye types.
16  */
17 typedef struct {
18     struct QueryCallbacks *def;
19 } Query;
20
21 /**
22  * \brief Creates an assignment Query.
23  *
24  * \param arity is the assignment tuple arity.
25  *
26  * \param names is the (char*) names to assign.
27  *
28  * \param values is the (void*) values to asign.
29  *
30  * The two tuples must have the same arity for assigning names[i] to
31  * values[i]. This Query makes the given names have the given values,
32  * once for each (*next) call following a (*reset) call.
33  *
34  * \related Query
35  */
36 extern Query *Query_assign(int arity,Tuple *names,Tuple *values);
37
38 /**
39  * \brief Create a Query record for lookup data in a Relation.
40  *
41  * \param r is the relation being queried.
42  *
43  * \param names is a same-arity tuple of binding names for the
44  * columns, using \b 0 for unnamed columns.
45  *
46  * \param values is a same--arity tuple of query values, using \b 0 for
47  * columns to enumerate.
48  *
49  * The names and values tuples identify bindings and values to use for
50  * the search query, and which bindings to set up from the successive
51  * results. Names that are bound beforhand identify constraining
52  * values, and the names that are unbound gain successive values from
53  * the matching tuples.
54  *
55  * \related Query
56  */
57 extern Query *Query_Relation(Relation *r,Tuple *names,Tuple *values);
58
59 /**
60  * \brief Create a Query record for a conjunction of queries.
61  *
62  * \param n is the number of sub queries.
63  *
64  * \param ... are the sub queries.
65  *
66  * The conjunction query processes the sub queries in order resulting
67  * in the sequence of their combined bindings.
68  *
69  * \related Query
70  */
71 extern Query *Query_and(int n,...);
72
73 /**
74  * \brief Create a Query record for a disjunction of queries.
75  *
76  * \param n is the number of sub queries.
77  *
78  * \param ... are the sub queries.
79  *
80  * The disjunction query processed the sub queries in order to find
81  * all their individual "true" binding combinations. It processes one
82  * sub query at a time to exhaustion and provide their individudal
83  * binding sequences separately.
84  *
85  * \related Query
86  */
87 extern Query *Query_or(int n,...);
88
89 /**
90  * \brief Invoke a consequent callback function for each successful
91  * binding of a query.
92  *
93  * \param q is the antecedent query to process.
94  *
95  * \param bt is the binding table to use.
96  *
97  * \param consequent is the callback function to invoke for each
98  * binding.
99  * \param data is the caller's context data.
100  *
101  * This function prrocesses the Query for establishing its binding
102  * sequence and inokes the consequent callback function for each
103  * binding as it is provided.
104  * 
105  * \related Query
106  */
107 extern void Query_rule(
108     Query *q,BindingTable *bt,
109     int (*consequent)(BindingTable *bt,void *data),
110     void *data );
111
112 #endif