macros.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* Macros for simplifying to write subsystem's service functions */
  2. #ifndef _clish_macros_h
  3. #define _clish_macros_h
  4. #include <assert.h>
  5. /* Function to get value from structure by name */
  6. #define _CLISH_GET(obj, type, name) \
  7. type clish_##obj##__get_##name(const clish_##obj##_t *inst)
  8. #define CLISH_GET(obj, type, name) \
  9. _CLISH_GET(obj, type, name) { \
  10. assert(inst); \
  11. return inst->name; \
  12. }
  13. #define _CLISH_GET_STR(obj, name) \
  14. _CLISH_GET(obj, const char *, name)
  15. #define CLISH_GET_STR(obj, name) \
  16. CLISH_GET(obj, const char *, name)
  17. /* Function to set value to structure by name */
  18. #define _CLISH_SET(obj, type, name) \
  19. void clish_##obj##__set_##name(clish_##obj##_t *inst, type val)
  20. #define CLISH_SET(obj, type, name) \
  21. _CLISH_SET(obj, type, name) { \
  22. assert(inst); \
  23. inst->name = val; \
  24. }
  25. #define _CLISH_SET_STR(obj, name) \
  26. _CLISH_SET(obj, const char *, name)
  27. #define CLISH_SET_STR(obj, name) \
  28. _CLISH_SET_STR(obj, name) { \
  29. assert(inst); \
  30. lub_string_free(inst->name); \
  31. inst->name = lub_string_dup(val); \
  32. }
  33. #endif // _clish_macros_h