ad4461b426ce36f407fd3e1a8dfd46c3d6994632
[rrq/rrqmisc.git] / vector / QueryCallbacks.h
1 #ifndef QueryCallbacks_H
2 #define QueryCallbacks_H
3
4 typedef struct HashVector HashVector;
5 typedef struct Query Query;
6 typedef struct BindingTable BindingTable;;
7
8 enum NextState {
9     /**
10      * This state tells the "next" function that it should capture the
11      * incoming BindingTable state and provide the initial Binding of
12      * a new sucession of bindings.
13      */
14     initial, 
15     /**
16      * This state tells the "next" function that it should update the
17      * bidning table with a subsequent Binding in the current
18      * succession of bindings.
19      */
20     subsequent,
21     /**
22      * This state tells the "next" function that it should just
23      * restore the Binding table to its incoming state.
24      */
25     restore
26 };
27
28 /**
29  * A struct Query_callbacks record defines the callbacks for a
30  * specific Query type.
31  */
32 typedef struct QueryCallbacks {
33     /**
34      * \brief Callback function to reclaim the Query memory for a
35      * given Query.
36      *
37      * \param this is the specific \ref Query concerned.
38      *
39      * Ground queries recalim their own state memory. Composite
40      * queries first propagate the reclaim call to its components, and
41      * thereafter reclaim their local state memory.
42      */
43     void (*reclaim)(Query *this);
44     /**
45      * \brief Callback function to update the Binding table with a
46      * succession of alternative bindings.
47      *
48      * \param this is the specific \ref Query concerned.
49      *
50      * \param bt is the Binding table to set bindings in.
51      *
52      * \param s is the call "sub-command" for the function.
53      *
54      * \returns 1 if a new Binding is provided and 0 otherwise.
55      *
56      * This function is called repeatedly for successively obtaining
57      * the alternative bindings that satisfy the Query. The "initial"
58      * state sub-command tells the function to capture the incoming
59      * BindingTable state so that the function can later restore it
60      * upon the "restore" sub-command. Upon the "initial" command, the
61      * function also sets up the Binding table with its first Binding
62      * alternative. This is followed by a series of "subsequent"
63      * sub-command calls for the function to change the BindingTable
64      * for its succession of Binding alternatives. The function should
65      * return 1 after any successful Binding setup, and return 0 when
66      * it cannot setup any (more) Binding.
67      */
68     int (*next)(Query *this,BindingTable *bt,enum NextState state);
69     /**
70      * \brief This callback function adds its binding names to the
71      * hashvector.
72      */
73     void (*variables)(Query *this,HashVector *hv);
74 } QueryCallbacks;
75
76 #endif