22 #ifndef LELY_UTIL_CMP_H_
23 #define LELY_UTIL_CMP_H_
34 #ifndef LELY_UTIL_CMP_INLINE
35 #define LELY_UTIL_CMP_INLINE static inline
50 typedef int cmp_t(
const void *p1,
const void *p2);
52 #define LELY_UTIL_DEFINE_TYPE(name, type) \
53 LELY_UTIL_CMP_INLINE int name##_cmp(const void *p1, const void *p2);
54 #include <lely/util/def/type.def>
55 LELY_UTIL_DEFINE_TYPE(ptr, )
56 LELY_UTIL_DEFINE_TYPE(str, )
57 LELY_UTIL_DEFINE_TYPE(str_case, )
58 #undef LELY_UTIL_DEFINE_TYPE
60 #define LELY_UTIL_DEFINE_TYPE(name, type) \
61 inline int name##_cmp(const void *p1, const void *p2) \
71 type v1 = *(const type *)p1; \
72 type v2 = *(const type *)p2; \
73 return (v2 < v1) - (v1 < v2); \
75 #include <lely/util/def/type.def>
76 #undef LELY_UTIL_DEFINE_TYPE
79 ptr_cmp(
const void *p1,
const void *p2)
81 uintptr_t v1 = (uintptr_t)p1;
82 uintptr_t v2 = (uintptr_t)p2;
83 return (v2 < v1) - (v1 < v2);
87 str_cmp(
const void *p1,
const void *p2)
97 return strcmp((
const char *)p1, (
const char *)p2);
101 str_case_cmp(
const void *p1,
const void *p2)
111 return strcasecmp((
const char *)p1, (
const char *)p2);
118 #endif // !LELY_UTIL_CMP_H_