// "chkd_array_factory_defs.h" -- first part | |
// Guards to ensure lists of types for which to create defs are defined | |
#ifndef CHKD_ARRAY_TYPES | |
#error "CHKD_ARRAY_TYPES not defined for defs" | |
#endif | |
#ifndef CHKD_ARRAY_PRIMITIVE_TYPES | |
#error "CHKD_ARRAY_PRIMITIVE_TYPES not defined for defs" | |
#endif | |
DECLARE(CHKD_ARRAY_TYPES) // See XX factory macro discussion below | |
// Definition of implementations for the generic functions. | |
#define CHKD_ARRAY_DEF(T, T_NM, DESC_LIT) \ | |
\ | |
static CHKD_ARRAY(T_NM) * CREATE(T_NM)(unsigned length, T *err_val) \ | |
{ /* implementation omitted */ } \ | |
\ | |
static inline T SET(T_NM)(CHKD_ARRAY(T_NM) *self, unsigned idx, T *val) \ | |
{ /* implementation omitted */ } \ | |
\ | |
static inline T *GET(T_NM)(CHKD_ARRAY(T_NM) * self, unsigned idx) \ | |
{ \ | |
if (idx >= self->length) { \ | |
return &self->err_val; \ | |
} \ | |
\ | |
return &self->data[idx]; \ | |
} \ | |
\ | |
static inline char *DESC(T_NM)() \ | |
{ \ | |
return (DESC_LIT); \ | |
} | |
// Definition of IS_EQUAL impl for types using == operator | |
#define IS_EQUAL_DEF(T, T_NM, DESC_LIT) \ | |
\ | |
static inline bool IS_EQUAL(T_NM)(T *first, T *second) \ | |
{ \ | |
return *first == *second; \ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment