X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;ds=sidebyside;f=vector%2FQuery.h;h=4b2fa6a08c335711a7daae02e2840d18b07a6484;hb=48cdb87442b7b3f1cdde9c1710ed90ec773dce97;hp=188a1eaae1d0383373cd1b32c8209af689b2a470;hpb=813cf9d12ff1b1c58e508485c977d33caaf89a86;p=rrq%2Frrqmisc.git diff --git a/vector/Query.h b/vector/Query.h index 188a1ea..4b2fa6a 100644 --- a/vector/Query.h +++ b/vector/Query.h @@ -1,11 +1,9 @@ #ifndef Query_H #define Query_H -#include -#include +#include #include - -struct QueryCallbacks; +#include /** * A Query is an implementation of a generic ABI over relations. It's @@ -18,6 +16,57 @@ typedef struct Query { struct QueryCallbacks *def; } Query; +/** + * \brief Trampoline for the callback function to reclaim the Query + * memory for a given Query. + * + * \param this is the specific \ref Query concerned. + * + * Ground queries recalim their own state memory. Composite + * queries first propagate the reclaim call to its components, and + * thereafter reclaim their local state memory. + */ +extern void Query_reclaim(Query *this); + +/** + * \brief Trampoline for the callback function to update the Binding + * table with a succession of alternative bindings. + * + * \param this is the specific \ref Query concerned. + * + * \param bt is the Binding table to set bindings in. + * + * \param s is the call "sub-command" for the function. + * + * \returns 1 if a new Binding is provided and 0 otherwise. + * + * This function is called repeatedly for successively obtaining + * the alternative bindings that satisfy the Query. The "initial" + * state sub-command tells the function to capture the incoming + * BindingTable state so that the function can later restore it + * upon the "restore" sub-command. Upon the "initial" command, the + * function also sets up the Binding table with its first Binding + * alternative. This is followed by a series of "subsequent" + * sub-command calls for the function to change the BindingTable + * for its succession of Binding alternatives. The function should + * return 1 after any successful Binding setup, and return 0 when + * it cannot setup any (more) Binding. + */ +extern int Query_next(Query *this,BindingTable *bt,enum NextState state); + +/** + * \brief Trampoline for the callback function that adds its binding + * names to the hashvector. + * + * \param this is the query concerned. + * + * \param hv is the HashVector for collating names. + */ +extern void Query_variables(Query *this,HashVector *hv); + + + + /** * \brief Creates an assignment Query. * @@ -104,9 +153,38 @@ extern Query *Query_or(int n,...); * * \related Query */ -extern void Query_rule( +extern void Query_eval( Query *q,BindingTable *bt, int (*consequent)(BindingTable *bt,void *data), void *data ); +/** + * \brief Collect all bindings of query. + * + * \param q is the query to enumerate. + * + * \param names is the binding names to track. + * + * \param results is the result store of bindings for the names. + * + * \returns the number of results. + * + * This function evaluates the query for one round of bindings, and + * stores their value \ref Tuple Tuples in the given vector. The given + * vector is first cleared, and any item is reclaimed with \b free. + * Correspondingly the binding \ref Tuple Tuples are allocated with \b + * malloc for the caller to reclaim (possibly via a successive call to + * this function). + */ +//extern int Query_snapshot(Query *q,Tuple *names,Vector *v); + +/** + * \brief Creates an NotQuery. + * + * \param query is the query to negate. + * + * \related Query + */ +extern Query *Query_not(Query *values); + #endif