Workbench Library  0.1b
workbench_config.h
Go to the documentation of this file.
1 
11 #pragma once
12 
26 #define WORKBENCH_CONFIG_DEFINE_STRUCT(type, field, default) type field;
27 
41 #define WORKBENCH_CONFIG_SET_DEFAULTS(type, field, default) .field = default,
42 
59 #define WORKBENCH_CONFIG_DEFINE_SETTERS(type, field, default) \
60  void config_set_##field(type field);
61 
74 #define WORKBENCH_CONFIG_IMPLEMENT_SETTERS(type, field, default) \
75  __attribute__((weak)) void config_set_##field(type field) { \
76  __cfg.field = field; \
77  }
78 
90 #define WORKBENCH_CONFIG_PARSE_ARGUMENTS(type, field, default) \
91  else if (strcmp(arg, #field) == 0) { \
92  arguments[(*args_parsed)++] = (Argument_t){.arg = arg, .val = val}; \
93  }
94 
106 #define WORKBENCH_CONFIG_PARSE_STRING(type, field, default) \
107  if (strcmp(arg, #field) == 0) { \
108  if (IS_TEXT_TYPE((type) default)) { \
109  *((char **)result) = strdup(val); \
110  } else if (IS_INT_TYPE((type) default)) { \
111  *((int32_t *)result) = strtoll(val, (char **)NULL, 10); \
112  } else if (IS_UINT_TYPE((type) default)) { \
113  *((uint32_t *)result) = strtoull(val, (char **)NULL, 10); \
114  } else if (IS_FLOAT_TYPE((type) default)) { \
115  *((double *)result) = strtod(val, (char **)NULL); \
116  } else { \
117  log_w("Unknown type '%s'. Can not take '%s' from config.", #type, arg); \
118  free(result); \
119  return; \
120  } \
121  config->field = *((type *)result); \
122  } else
123 
132 #define WORKBENCH_FLAG_DEFINE(FLAG) FLAG = (1 << FLAG##_BIT),
133 
143 #define WORKBENCH_FLAG_ENUMERATE(FLAG) FLAG##_BIT,