return t;
}
+itemkeyfun tupleschema_callbacks = {
+ .hashcode = tupleitem_hashcode,
+ .haskey = tupleitem_haskey,
+ .itemkey = tupleitem_itemkey,
+ .releasekey = tupleitem_releasekey
+};
+
tupleschema *tupleschema_create(int arity,tuple *columns) {
tupleschema *ts = (tupleschema*) malloc( sizeof( tupleschema ) );
(*ts) = (tupleschema) {
- .base = {
- .hashcode = tupleitem_hashcode,
- .haskey = tupleitem_haskey,
- .itemkey = tupleitem_itemkey,
- .releasekey = tupleitem_releasekey
- },
+ .base = tupleschema_callbacks,
.arity = arity,
.columns = (itemkeyfun**) columns
};
/**
* A tupleschema record declares the itemkeyfun functions for tuple
- * items together with applicable arity and domain combinations. The
- * macro \ref TUPLEITEMINIT may be used to initialize particular
- * tupleschema records, which each become tupleitem declaration for
- * its particular arity and parts declarations
+ * items together with applicable arity and domain combinations.
+ * Records are created dynamically via the \ref tupleschema_create
+ * function or the \ref TUPLESCHEMA convenience macro.
+ *
* \extends itemkeyfun
*/
typedef struct {
/**
* Create a tuples with given values.
+ *
+ * \related tupleschema
*/
extern tuple *tuple_create(int arity,...);
/**
* Create a tuples with given values.
+ *
+ * \related tupleschema
*/
extern tupleschema *tupleschema_create(int arity,tuple *columns);
* Copy the given tupleschema into a new tupleschema with some columns
* masked. This represents a sub-index type using the unmasked columns
* for indexing.
+ *
+ * \related tupleschema
*/
extern tupleschema *tupleschema_mask(tupleschema *schema,...);
/**
* \brief Return 1/0 to indicate whether the query matches the item.
+ *
+ * \related tupleschema
*/
extern int tupleschema_match(tupleschema *def,tuple *query,tuple *item);
/**
- * The TUPLEITEMINIT macro is used for initializing a tupleschema
- * record appropriately for a given arity and corresponding sequence
- * of parts itemkeyfun pointers.
+ * \brief Generic macro to determine the number of expressions in a
+ * __VA_ARGS__
+ *
+ * \related tupleschema
*/
-#define TUPLEITEMINIT(arity, ... ) { \
- .functions = { \
- .hashcode = tupleitem_hashcode, \
- .haskey = tupleitem_haskey, \
- .itemkey = tupleitem_itemkey, \
- .releasekey = tupleitem_releasekey \
- }, \
- .arity = arity, \
- .schema = { __VA_ARGS__ } \
- }
+#define NUMARGS(...) (sizeof((void*[]){__VA_ARGS__})/sizeof(void*))
+
+/**
+ * \brief Create a tuple with the given values.
+ *
+ * This invokes \ref tuple_create to allocate and assign a void*
+ * array with the given values.
+ *
+ * \related tupleschema
+ */
+#define TUPLE(...) tuple_create( NUMARGS(__VA_ARGS__), __VA_ARGS__ )
+
+/**
+ * \brief Create a \ref tupleschema with the given column "types".
+ *
+ * This invokes \ref tupleschema_create to allocate and initialize a
+ * \ref tupleschema for the given columns via the \ref TUPLE macro.
+ *
+ * \related tupleschema
+ */
+#define TUPLESCHEMA(...) \
+ tupleschema_create( NUMARGS( __VA_ARGS__ ), TUPLE( __VA_ARGS__ ) )
+
#endif