major reorganisation
[rrq/rrqmisc.git] / logic / NotQuery.c
1 #include <stdlib.h>
2 #include <NotQuery.h>
3
4 static void NotQuery_reclaim(Query *this) {
5     NotQuery *q = (NotQuery*) this;
6     Query_reclaim( q->query );
7     free( this );
8 }
9
10 static int NotQuery_next(
11     Query *this,BindingTable *bt,enum NextState state)
12 {
13     NotQuery *q = (NotQuery*) this;
14     if ( state == initial ) {
15         if ( Query_next( q->query, bt, initial ) ) {
16             Query_next( q->query, bt, restore );
17             return 0;
18         }
19         return 1;
20     }
21     return 0;
22 }
23
24 static void NotQuery_variables(Query *this,HashVector *hv) {
25     Query_variables( ((NotQuery*) this)->query, hv );
26 }
27
28 static struct QueryCallbacks NotQuery_def = {
29     .reclaim = NotQuery_reclaim,
30     .next = NotQuery_next,
31     .variables = NotQuery_variables
32 };
33
34 Query *Query_not(Query *q) {
35     NotQuery *nq = (NotQuery*) malloc( sizeof( NotQuery ) );
36     (*nq) = (NotQuery) {
37         .def = &NotQuery_def,
38         .query = q
39     };
40     return (Query*) nq;
41 }