Skip to content

Commit

Permalink
typemacros: split macros for class macros
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Klotzbuecher <mk@mkio.de>
  • Loading branch information
kmarkus committed Apr 27, 2020
1 parent 56a7ad4 commit 1244d99
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions libubx/typemacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,40 +163,45 @@ def_cfg_getptr_fun(cfg_getptr_ ## SUFFIX, TYPENAME)
#ifdef __cplusplus
#include <type_traits>

/*
* The following macro define helper functions for working with C++
* objects with struct reflection. This checks for (and errors) if the
* class is not a standard_layout class.
*/

#define gen_class_accessors(SUFFIX, CLASS, UBXTYPE) \
static_assert(std::is_standard_layout<CLASS>::value, QUOTE(CLASS) "has no standard layout"); \
/* generate overloaded port RW and config accessors */
#define gen_class_accessors(SUFFIX, CLASS, UBXTYPE) \
\
def_type_accessors(SUFFIX, UBXTYPE); \
\
long portRead ## SUFFIX(const ubx_port_t *p, CLASS* x, const int len) \
long portRead(const ubx_port_t *p, CLASS* x, const int len) \
{ \
return read_ ## SUFFIX ## _array(p, (UBXTYPE*) x, len); \
} \
\
long portRead ## SUFFIX(const ubx_port_t *p, CLASS* x) \
long portRead(const ubx_port_t *p, CLASS* x) \
{ \
return read_ ## SUFFIX(p, (UBXTYPE*) x); \
} \
\
long portWrite ## SUFFIX(const ubx_port_t *p, CLASS* x, const int len) \
long portWrite(const ubx_port_t *p, const CLASS* x, const int len) \
{ \
return write_ ## SUFFIX ## _array(p, (const UBXTYPE*) x, len); \
} \
\
long portWrite ## SUFFIX(const ubx_port_t *p, CLASS* x) \
long portWrite(const ubx_port_t *p, const CLASS* x) \
{ \
return write_ ## SUFFIX(p, (const UBXTYPE*) x); \
} \
\
long configGet ## SUFFIX(const ubx_block_t *b, const char *cfg_name, const CLASS **valptr) \
long configGet(const ubx_block_t *b, const char *cfg_name, const CLASS **valptr) \
{ \
return cfg_getptr_ ## SUFFIX(b, cfg_name, (const UBXTYPE**) valptr); \
return cfg_getptr_ ## SUFFIX(b, cfg_name, (const UBXTYPE**) valptr); \
} \

/*
* The following macro define helper functions for working with C++
* objects with struct reflection. This checks for (and errors) if the
* class is not a standard_layout class.
*/

#define def_class_accessors(SUFFIX, CLASS, UBXTYPE) \
static_assert(std::is_standard_layout<CLASS>::value, QUOTE(CLASS) "has no standard layout"); \
\
def_type_accessors(SUFFIX, UBXTYPE); \
\
gen_class_accessors(SUFFIX, CLASS, UBXTYPE); \

#endif

0 comments on commit 1244d99

Please sign in to comment.