]> git.ozlabs.org Git - ccan/blob - ccan/order/order.h
f5dac818d898cec5762726fe1136d70e58a611b2
[ccan] / ccan / order / order.h
1 /* CC0 license (public domain) - see LICENSE file for details */
2 #ifndef CCAN_ORDER_H
3 #define CCAN_ORDER_H
4
5 #include <stdint.h>
6 #include <assert.h>
7
8 #include <ccan/typesafe_cb/typesafe_cb.h>
9
10 typedef int (*_total_order_cb)(const void *, const void *, void *);
11 typedef int (*total_order_noctx_cb)(const void *, const void *);
12
13 #define total_order_cb(_name, _item, _ctx)              \
14         int (*_name)(const __typeof__(_item) *,         \
15                      const __typeof__(_item) *,         \
16                      __typeof__(_ctx))
17
18 #define total_order_cast(cmp, item, ctx)                                \
19         typesafe_cb_cast(_total_order_cb, total_order_cb(, item, ctx),  \
20                          (cmp))
21
22 struct _total_order {
23         _total_order_cb cb;
24         void *ctx;
25 };
26
27 #define total_order(_name, _item, _ctx)                 \
28         struct {                                        \
29                 total_order_cb(cb, _item, _ctx);        \
30                 _ctx ctx;                               \
31         } _name
32
33 #endif /* CCAN_ORDER_H */