#include <Query.h>
#include <BindingTable.h>
-enum next_state {
+enum NextState {
/**
* This state tells the "next" function that it should capture the
* incoming BindingTable state and provide the initial Binding of
restore
};
-//enum compound_state { reset, started, ended };
-
/**
- * A struct query_callbacks record defines the callbacks for a
- * specific query type.
+ * A struct Query_callbacks record defines the callbacks for a
+ * specific Query type.
*/
-struct query_callbacks {
+struct QueryCallbacks {
/**
- * \brief Callback function to reclaim the query memory for a
- * given query.
+ * \brief Callback function to reclaim the Query memory for a
+ * given Query.
*
- * \param this is the specific \ref query concerned.
+ * \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.
*/
- void (*reclaim)(query *this);
- void (*start)(query *this,BindingTable *bt,enum next_state s);
+ void (*reclaim)(Query *this);
+ void (*start)(Query *this,BindingTable *bt,enum NextState s);
/**
* \brief Callback function to update the Binding table with a
* succession of alternative bindings.
*
- * \param this is the specific \ref query concerned.
+ * \param this is the specific \ref Query concerned.
*
* \param bt is the Binding table to set bindings in.
*
* \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"
+ * 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
* return 1 after any successful Binding setup, and return 0 when
* it cannot setup any (more) Binding.
*/
- int (*next)(query *this,BindingTable *bt,enum next_state state);
+ int (*next)(Query *this,BindingTable *bt,enum NextState state);
};
/* ==================== AssignmentQuery ==================== */
typedef struct {
- struct query_callbacks *def;
+ struct QueryCallbacks *def;
int arity;
tuple *names;
tuple *values;
} AssignmentQuery;
// Release any memory.
-static void AssignmentQuery_reclaim(query *this) {
+static void AssignmentQuery_reclaim(Query *this) {
AssignmentQuery *q = (AssignmentQuery*) this;
free( q->saved );
free( this );
// Make names have given values and return 1. If any name has a
// different value then return 0. Values are strings.
static int AssignmentQuery_next(
- query *this,BindingTable *bt,enum next_state state) {
+ Query *this,BindingTable *bt,enum NextState state) {
AssignmentQuery *q = (AssignmentQuery*) this;
switch ( state ) {
case initial:
return 0;
}
-static struct query_callbacks AssignmentQuery_def = {
+static struct QueryCallbacks AssignmentQuery_def = {
.reclaim = AssignmentQuery_reclaim,
.next = AssignmentQuery_next
};
/**
- * Return a query object representing an assignment of one or more
+ * Return a Query object representing an assignment of one or more
* variables.
*/
-query *query_assign(int arity,tuple *names,tuple *values) {
+Query *Query_assign(int arity,tuple *names,tuple *values) {
AssignmentQuery *q = (AssignmentQuery*)
malloc( sizeof( AssignmentQuery ) );
(*q) = (AssignmentQuery) {
.values = values,
.saved = 0
};
- return (query*) q;
+ return (Query*) q;
}
/* ==================== conjunction ==================== */
typedef struct {
- struct query_callbacks *def;
+ struct QueryCallbacks *def;
int active;
int size;
- query **conjuncts;
+ Query **conjuncts;
} ConjunctionQuery;
-static void ConjunctionQuery_reclaim(query *this) {
+static void ConjunctionQuery_reclaim(Query *this) {
ConjunctionQuery *q = (ConjunctionQuery*) this;
int i;
for ( i = 0; i < q->size; i++ ) {
}
static int ConjunctionQuery_next(
- query *this,BindingTable *bt,enum next_state state)
+ Query *this,BindingTable *bt,enum NextState state)
{
ConjunctionQuery *q = (ConjunctionQuery*) this;
int i = q->size - 1;
- enum next_state s = subsequent;
+ enum NextState s = subsequent;
switch ( state ) {
case initial:
q->active = 1;
return 0;
}
-static struct query_callbacks ConjunctionQuery_def = {
+static struct QueryCallbacks ConjunctionQuery_def = {
.reclaim = ConjunctionQuery_reclaim,
.next = ConjunctionQuery_next
};
-query *query_and(int n,...) {
+Query *Query_and(int n,...) {
va_list args;
ConjunctionQuery *q = (ConjunctionQuery *)
malloc( sizeof( ConjunctionQuery ) );
.def = &ConjunctionQuery_def,
.active = 0,
.size = n,
- .conjuncts = (query**) malloc( n * sizeof( query* ) )
+ .conjuncts = (Query**) malloc( n * sizeof( Query* ) )
};
int i;
va_start( args, n );
for ( i = 0; i < n; i++ ) {
- q->conjuncts[i] = va_arg( args, query* );
+ q->conjuncts[i] = va_arg( args, Query* );
}
va_end( args );
- return (query*) q;
+ return (Query*) q;
}
/* ==================== disjunction ==================== */
typedef struct {
- struct query_callbacks *def;
+ struct QueryCallbacks *def;
int index;
int size;
- query **disjuncts;
+ Query **disjuncts;
} DisjunctionQuery;
-static void DisjunctionQuery_reclaim(query *this) {
+static void DisjunctionQuery_reclaim(Query *this) {
DisjunctionQuery *q = (DisjunctionQuery*) this;
int i;
for ( i = 0; i < q->size; i++ ) {
}
static int DisjunctionQuery_next(
- query *this,BindingTable *bt,enum next_state state) {
+ Query *this,BindingTable *bt,enum NextState state) {
DisjunctionQuery *q = (DisjunctionQuery*) this;
int i = q->index;
- enum next_state s = subsequent;
+ enum NextState s = subsequent;
switch ( state ) {
case initial:
i = 0;
return 0;
}
-static struct query_callbacks DisjunctionQuery_def = {
+static struct QueryCallbacks DisjunctionQuery_def = {
.reclaim = DisjunctionQuery_reclaim,
.next = DisjunctionQuery_next,
};
-query *query_or(int n,...) {
+Query *Query_or(int n,...) {
va_list args;
DisjunctionQuery *q = (DisjunctionQuery *)
malloc( sizeof( DisjunctionQuery ) );
.def = &DisjunctionQuery_def,
.index = -1,
.size = n,
- .disjuncts = (query**) malloc( n * sizeof( query* ) ),
+ .disjuncts = (Query**) malloc( n * sizeof( Query* ) ),
};
int i;
va_start( args, n );
for ( i = 0; i < n; i++ ) {
- q->disjuncts[i] = va_arg( args, query* );
+ q->disjuncts[i] = va_arg( args, Query* );
}
va_end( args );
- return (query*) q;
+ return (Query*) q;
}
/* ==================== Relation access ==================== */
typedef struct {
- struct query_callbacks *def;
+ struct QueryCallbacks *def;
Relation *rel;
VectorIndex index;
tuple *names;
} RelationQuery;
// Release any memory.
-static void RelationQuery_reclaim(query *this) {
+static void RelationQuery_reclaim(Query *this) {
RelationQuery *q = (RelationQuery*) this;
free( q->saved );
free( this );
// Make names have given values and return 1. If any name has a
// different value then return 0. Values are strings.
static int RelationQuery_next(
- query *this,BindingTable *bt,enum next_state state) {
+ Query *this,BindingTable *bt,enum NextState state) {
RelationQuery *q = (RelationQuery*) this;
int arity = ((TupleSchema*) q->rel->content.type)->arity;
VectorIndex index = q->index + 1;
// Fall through
case subsequent:
for ( ; index < q->rel->content.table.size; index++ ) {
- tuple *values = relation_next( q->rel, &index, q->values );
+ tuple *values = Relation_next( q->rel, &index, q->values );
if ( values ) {
q->index = index;
AssignmentQuery_assign( bt, arity, q->names, values, 1 );
return 0;
}
-static struct query_callbacks RelationQuery_def = {
+static struct QueryCallbacks RelationQuery_def = {
.reclaim = RelationQuery_reclaim,
.next = RelationQuery_next
};
/**
- * Return a query object representing an Relation of one or more
+ * Return a Query object representing an Relation of one or more
* variables.
*/
-query *query_Relation(Relation *r,tuple *names,tuple *values) {
+Query *Query_Relation(Relation *r,tuple *names,tuple *values) {
RelationQuery *q = (RelationQuery*) malloc( sizeof( RelationQuery ) );
(*q) = (RelationQuery) {
.def = &RelationQuery_def,
.values = values,
.saved = 0
};
- return (query*) q;
+ return (Query*) q;
}