X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Forder%2Forder.h;fp=ccan%2Forder%2Forder.h;h=edceab5551e2e68dd14bee39bf7ac4a12663841b;hb=37825438b65879dad1a343b45bb5ce9fc37ba8e7;hp=f5dac818d898cec5762726fe1136d70e58a611b2;hpb=c2a3098b254830f33e800bfa398882786632631e;p=ccan diff --git a/ccan/order/order.h b/ccan/order/order.h index f5dac818..edceab55 100644 --- a/ccan/order/order.h +++ b/ccan/order/order.h @@ -6,6 +6,7 @@ #include #include +#include typedef int (*_total_order_cb)(const void *, const void *, void *); typedef int (*total_order_noctx_cb)(const void *, const void *); @@ -30,4 +31,43 @@ struct _total_order { _ctx ctx; \ } _name +#define _DECL_ONAME(_oname, _itype) \ + extern int _order_##_oname(const void *, const void *, void *); \ + extern int order_##_oname(const _itype *, const _itype *, void *); \ + extern int order_##_oname##_noctx(const void *, const void *); + +#define _DECL_ONAME_BIDIR(_oname, _itype) \ + _DECL_ONAME(_oname, _itype) \ + _DECL_ONAME(_oname##_reverse, _itype) + +_DECL_ONAME_BIDIR(s8, int8_t) +_DECL_ONAME_BIDIR(s16, int16_t) +_DECL_ONAME_BIDIR(s32, int32_t) +_DECL_ONAME_BIDIR(s64, int64_t) + +_DECL_ONAME_BIDIR(u8, uint8_t) +_DECL_ONAME_BIDIR(u16, uint16_t) +_DECL_ONAME_BIDIR(u32, uint32_t) +_DECL_ONAME_BIDIR(u64, uint64_t) + +_DECL_ONAME_BIDIR(int, int) +_DECL_ONAME_BIDIR(uint, unsigned int) +_DECL_ONAME_BIDIR(long, long) +_DECL_ONAME_BIDIR(ulong, unsigned long) +_DECL_ONAME_BIDIR(size, size_t) +_DECL_ONAME_BIDIR(ptrdiff, ptrdiff_t) + +_DECL_ONAME_BIDIR(float, float) +_DECL_ONAME_BIDIR(double, double) + +#undef _DECL_ONAME +#undef _DECL_ONAME_BIDIR + +#define total_order_by_field(_name, _oname, _itype, _field) \ + total_order(_name, _itype, ptrint_t *) = { \ + (total_order_cb(, _itype, \ + ptrint_t *))(_order_##_oname), \ + int2ptr(offsetof(_itype, _field)), \ + } + #endif /* CCAN_ORDER_H */