major reorganisation
[rrq/rrqmisc.git] / logic / TupleSchema.h
1 #ifndef tupleitem_H
2 #define tupleitem_H
3
4 #include <Tuple.h>
5
6 /**
7  * A TupleSchema record declares the ItemKeyFun functions for tuple
8  * items together with applicable arity and domain combinations.
9  * Records are created dynamically via the \ref TupleSchema_create
10  * function or the \ref TUPLESCHEMA convenience macro.
11  *
12  * \extends ItemKeyFun
13  */
14 typedef struct TupleSchema {
15     /**
16      * These are the ItemKeyFun callback functions to support
17      * HashVector use for tuple items. The functions expects their
18      * ItemKeyFun pointer to be within a TupleSchema record so as to
19      * provide the handling of the tuple columns.
20      */
21     ItemKeyFun base;
22
23     /**
24      * This points to tuple whose elements is array of pointers to the
25      * tuple item domains as represented by their associated
26      * ItemKeyFun records.
27      */
28     Tuple *columns;
29 } TupleSchema;
30
31 /**
32  * Create a tuples with given values.
33  *
34  * \related TupleSchema
35  */
36 extern TupleSchema *TupleSchema_create(Tuple *columns);
37
38 /**
39  * Copy the given TupleSchema into a new TupleSchema with some columns
40  * masked. This represents a sub-index type using the unmasked columns
41  * for indexing.
42  *
43  * \related TupleSchema
44  */
45 extern TupleSchema *TupleSchema_mask(TupleSchema *schema,...);
46
47 /**
48  * \brief Return 1/0 to indicate whether the Query matches the item.
49  *
50  * \related TupleSchema
51  */
52 extern int TupleSchema_match(TupleSchema *def,Tuple *query,Tuple *item);
53
54 /**
55  * \brief Generic macro to determine the number of expressions in a
56  * __VA_ARGS__
57  *
58  * \related TupleSchema
59  */
60 #define NUMARGS(...) (sizeof((void*[]){__VA_ARGS__})/sizeof(void*))
61
62 /**
63  * \brief Create a tuple with the given values.
64  *
65  * This invokes \ref tuple_create to allocate and assign a void*
66  * array with the given values.
67  *
68  * \related TupleSchema
69  */
70 #define TUPLE(...) Tuple_create( NUMARGS(__VA_ARGS__), __VA_ARGS__ )
71
72 /**
73  * \brief Create a \ref TupleSchema with the given column "types".
74  *
75  * This invokes \ref TupleSchema_create to allocate and initialize a
76  * \ref TupleSchema for the given columns via the \ref TUPLE macro.
77  *
78  * \related TupleSchema
79  */
80 #define TUPLESCHEMA(...) \
81     TupleSchema_create( TUPLE( __VA_ARGS__ ) )
82
83
84 #endif