31 "vtable or get_type is NULL for parameter '%s'",
44 "vtable or is_default is NULL for parameter '%s'",
57 "vtable or get_name is NULL");
69 "vtable or get_sub_count is NULL for parameter '%s'",
83 "vtable or get_sub_by_name is NULL for parameter '%s'",
96 "vtable or get_sub_by_index is NULL for parameter '%s'",
104 param,
"unsupported operation for empty parameter");
107 "vtable or append is NULL for parameter '%s'",
114 struct yac_param *param,
const char *value_str) {
116 param,
"unsupported operation for empty parameter");
119 "string-based setter not supported by this parameter");
124 const struct yac_param *param,
char *buf,
size_t buflen) {
125 if (!param && buf && buflen) buf[0] =
'\0';
127 param,
"unsupported operation for empty parameter");
130 "string-based getter not supported by this parameter");
136 param,
"unsupported operation for empty parameter");
139 "integer-based setter not supported by this parameter");
145 param,
"unsupported operation for empty parameter");
148 "double-based setter not supported by this parameter");
154 param,
"unsupported operation for empty parameter");
157 "integer-based getter not supported by this parameter");
163 param,
"unsupported operation for empty parameter");
166 "double-based getter not supported by this parameter");
178 const char *value_str,
const char *param_name,
double *
value) {
181 "No value provided for parameter '%s'", param_name);
183 *
value = strtod(value_str, &endptr);
185 (endptr != value_str) && (*endptr ==
'\0'),
186 "'%s' is not a valid double for parameter '%s'",
187 value_str, param_name);
192 const char *value_str,
const char *param_name,
double *
value,
197 YAC_ASSERT_F(unit,
"unit is NULL for parameter '%s'", param_name);
203 *
value = strtod(value_str, &endptr);
205 (endptr != value_str),
206 "'%s' is not a valid double for parameter '%s'", value_str, param_name);
210 if (*endptr !=
'\0') {
213 if (isspace((
unsigned char)*endptr)) {
218 yac_param_unit_table,
229 yac_param_unit_table, yac_param_unit_table_size, endptr);
232 unit_type != INT_MAX,
233 "'%s' has invalid unit suffix for parameter '%s'",
234 value_str, param_name);
248 char *buf,
size_t buflen,
double value,
const char *value_desc,
249 const char *param_name) {
257#if defined(DBL_DECIMAL_DIG)
258 MAX_PRECISION = DBL_DECIMAL_DIG,
268 buflen >= MIN_BUF_LEN,
269 "buffer too small for %s of parameter '%s' (need at least %d bytes)",
270 value_desc, param_name, MIN_BUF_LEN);
274 for (
int precision = MAX_PRECISION; (precision >= 1) && ret; --precision) {
275 int n = snprintf(buf, buflen,
"%.*g", precision,
value);
276 if ((n >= 0) && ((
size_t)n < buflen)) ret = 0;
280 ret == 0,
"failed to format double value '%g' with any precision",
value);
288 return buf ? buf :
"";
296 "vtable or delete is NULL for parameter '%s'",
307 double const two_pi = 2.0 * M_PI;
311 "value is NaN or Inf for parameter '%s'", param_name);
323 "value is NaN or Inf for parameter '%s'", param_name);
336 {.deg = -180.0, .rad = - M_PI},
337 {.deg = -540.0, .rad = - M_PI},
338 {.deg = 180.0, .rad = - M_PI},
339 {.deg = 540.0, .rad = - M_PI},
342 {.deg = -90.0, .rad = -M_PI_2},
343 {.deg = 90.0, .rad = M_PI_2},
344 {.deg = -450.0, .rad = -M_PI_2},
345 {.deg = -270.0, .rad = M_PI_2},
346 {.deg = 270.0, .rad = -M_PI_2},
347 {.deg = 450.0, .rad = M_PI_2},
350 {.deg = -135.0, .rad = - M_PI + M_PI_4},
351 {.deg = -45.0, .rad = - M_PI_4},
352 {.deg = 45.0, .rad = M_PI_4},
353 {.deg = 135.0, .rad = M_PI - M_PI_4},
354 {.deg = -495.0, .rad = - M_PI + M_PI_4},
355 {.deg = -405.0, .rad = - M_PI_4},
356 {.deg = -315.0, .rad = M_PI_4},
357 {.deg = -225.0, .rad = M_PI - M_PI_4},
358 {.deg = 225.0, .rad = - M_PI + M_PI_4},
359 {.deg = 315.0, .rad = - M_PI_4},
360 {.deg = 405.0, .rad = M_PI_4},
361 {.deg = 495.0, .rad = M_PI - M_PI_4},
363 {.deg = 0.0, .rad = 0.0},
364 {.deg = -720.0, .rad = 0.0},
365 {.deg = -360.0, .rad = 0.0},
366 {.deg = 360.0, .rad = 0.0},
367 {.deg = 720.0, .rad = 0.0},
375 !isnan(
deg) && !isinf(
deg),
376 "value is NaN or Inf for parameter '%s'", param_name);
388 !isnan(
rad) && !isinf(
rad),
389 "value is NaN or Inf for parameter '%s'", param_name);
#define YAC_ASSERT(exp, msg)
int yac_name_type_pair_get_type(struct yac_name_type_pair const *pairs, size_t count, char const *name)
#define DEF_NAME_TYPE_PAIR(NAME, TYPE)
#define DEF_NAME_TYPE_PAIRS(NAME,...)
int yac_param_parse_dble_with_unit(const char *value_str, const char *param_name, double *value, enum yac_param_angle_unit *unit)
int yac_param_get_scalar_dble(const struct yac_param *param, double *value)
Get the value of a scalar parameter as a double.
double yac_wrap_deg(double value, char const *param_name)
void yac_param_delete(struct yac_param *param)
int yac_param_get_sub_by_index(struct yac_param *param, size_t idx, struct yac_param **sub_param)
Get a handle to a subparameter by index.
int yac_param_is_default(const struct yac_param *param)
Check whether a parameter is at its default value.
static struct @47 deg_rad_lookup[]
double yac_deg_to_rad(double deg, char const *param_name)
double yac_wrap_rad(double value, char const *param_name)
double yac_rad_to_deg(double rad, char const *param_name)
int yac_param_get_scalar(const struct yac_param *param, char *buf, size_t buflen)
Get the value of a scalar parameter as a string.
int yac_param_set_scalar(struct yac_param *param, const char *value_str)
Set the value of a scalar parameter from a string.
enum yac_param_type yac_param_get_type(const struct yac_param *param)
Get the type of a parameter.
int yac_param_append(struct yac_param *param, struct yac_param **sub_param)
Append a new default subparameter to a list parameter and return a handle to it.
static char error_buf[ERROR_BUF_SIZE]
int yac_param_format_scalar_dble(char *buf, size_t buflen, double value, const char *value_desc, const char *param_name)
int yac_param_parse_dble(const char *value_str, const char *param_name, double *value)
int yac_param_set_scalar_int(struct yac_param *param, int value)
Set the value of a scalar parameter as an int.
void yac_param_get_error_buffer(char **buffer, size_t *buffer_size)
int yac_param_get_sub_count(const struct yac_param *param, size_t *count)
Get the number of subparameters.
int yac_param_set_scalar_dble(struct yac_param *param, double value)
Set the value of a scalar parameter as a double.
const char * yac_param_get_last_error(void)
Retrieve the last error message for the calling thread.
int yac_param_get_scalar_int(const struct yac_param *param, int *value)
Get the value of a scalar parameter as an int.
const char * yac_param_get_name(const struct yac_param *param)
Get the name of the current parameter.
int yac_param_get_sub_by_name(struct yac_param *param, const char *name, struct yac_param **sub_param)
Get a handle to a subparameter by name.
yac_param_type
Parameter type for generic configuration interface.
@ YAC_PARAM_TYPE_EMPTY
No value (used for optional/absent parameters)
@ YAC_PARAM_ANGLE_UNIT_RAD
@ YAC_PARAM_ANGLE_UNIT_DEG
#define YAC_PARAM_ASSERT(COND,...)
int(* get_scalar_int)(const struct yac_param *param, int *value)
int(* set_scalar_int)(struct yac_param *param, int value)
int(* get_scalar_dble)(const struct yac_param *param, double *value)
int(* get_sub_count)(const struct yac_param *param, size_t *count)
int(* is_default)(const struct yac_param *param)
int(* append)(struct yac_param *param, struct yac_param **sub_param)
int(* set_scalar_dble)(struct yac_param *param, double value)
const char *(* get_name)(const struct yac_param *param)
enum yac_param_type(* get_type)(const struct yac_param *param)
int(* set_scalar)(struct yac_param *param, const char *value_str)
int(* get_sub_by_name)(const struct yac_param *param, const char *name, struct yac_param **sub_param)
void(* delete)(struct yac_param *param)
int(* get_sub_by_index)(struct yac_param *param, size_t idx, struct yac_param **sub_param)
int(* get_scalar)(const struct yac_param *param, char *buf, size_t buflen)
struct yac_param_vtable const * vtable
#define YAC_ASSERT_F(exp, format,...)