Skip to content

Instantly share code, notes, and snippets.

@abissell
Last active January 3, 2016 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abissell/0079602f8e0f65019ee0 to your computer and use it in GitHub Desktop.
Save abissell/0079602f8e0f65019ee0 to your computer and use it in GitHub Desktop.
// "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