Cleanup Tuple to allow self-typing.
[rrq/rrqmisc.git] / vector / 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 is the number of columns in a tuple.
25      */
26     int arity;
27
28     /**
29      * This points to tuple whose elements is array of pointers to the
30      * tuple item domains as represented by their associated
31      * ItemKeyFun records.
32      */
33     Tuple *columns;
34 } TupleSchema;
35
36 /**
37  * Create a tuples with given values.
38  *
39  * \related TupleSchema
40  */
41 extern TupleSchema *TupleSchema_create(int arity,Tuple *columns);
42
43 /**
44  * Copy the given TupleSchema into a new TupleSchema with some columns
45  * masked. This represents a sub-index type using the unmasked columns
46  * for indexing.
47  *
48  * \related TupleSchema
49  */
50 extern TupleSchema *TupleSchema_mask(TupleSchema *schema,...);
51
52 /**
53  * \brief Return 1/0 to indicate whether the Query matches the item.
54  *
55  * \related TupleSchema
56  */
57 extern int TupleSchema_match(TupleSchema *def,Tuple *query,Tuple *item);
58
59 /**
60  * \brief Generic macro to determine the number of expressions in a
61  * __VA_ARGS__
62  *
63  * \related TupleSchema
64  */
65 #define NUMARGS(...) (sizeof((void*[]){__VA_ARGS__})/sizeof(void*))
66
67 /**
68  * \brief Create a tuple with the given values.
69  *
70  * This invokes \ref tuple_create to allocate and assign a void*
71  * array with the given values.
72  *
73  * \related TupleSchema
74  */
75 #define TUPLE(...) Tuple_create( NUMARGS(__VA_ARGS__), __VA_ARGS__ )
76
77 /**
78  * \brief Create a \ref TupleSchema with the given column "types".
79  *
80  * This invokes \ref TupleSchema_create to allocate and initialize a
81  * \ref TupleSchema for the given columns via the \ref TUPLE macro.
82  *
83  * \related TupleSchema
84  */
85 #define TUPLESCHEMA(...) \
86     TupleSchema_create( NUMARGS( __VA_ARGS__ ), TUPLE( __VA_ARGS__ ) )
87
88
89 #endif