YAC 3.20.0
Yet Another Coupler
Loading...
Searching...
No Matches
param_internal.h File Reference
#include <stddef.h>
#include <stdio.h>
#include "parameter/param.h"
Include dependency graph for param_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  yac_param_vtable
 

Macros

#define YAC_PARAM_ASSERT(COND, ...)
 
#define YAC_PARAM_CHECK_BASIC()
 
#define ERROR_BUF_SIZE   (256)
 

Enumerations

enum  yac_param_angle_unit { YAC_PARAM_ANGLE_UNIT_DEG = 0 , YAC_PARAM_ANGLE_UNIT_RAD = 1 }
 

Functions

void yac_param_get_error_buffer (char **buffer, size_t *buffer_size)
 
int yac_param_parse_dble (const char *value_str, const char *param_name, double *value)
 
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_format_scalar_dble (char *buf, size_t buflen, double value, const char *value_desc, const char *param_name)
 
double yac_wrap_rad (double value, char const *param_name)
 
double yac_wrap_deg (double value, char const *param_name)
 
double yac_deg_to_rad (double deg, char const *param_name)
 
double yac_rad_to_deg (double rad, char const *param_name)
 

Macro Definition Documentation

◆ ERROR_BUF_SIZE

#define ERROR_BUF_SIZE   (256)

Definition at line 178 of file param_internal.h.

◆ YAC_PARAM_ASSERT

#define YAC_PARAM_ASSERT ( COND,
... )
Value:
do { \
if (!(COND)) { \
char *yac_param_error_buffer_ = NULL; \
size_t yac_param_error_buffer_size_ = 0; \
yac_param_get_error_buffer( \
&yac_param_error_buffer_, &yac_param_error_buffer_size_); \
if (yac_param_error_buffer_ && (yac_param_error_buffer_size_ > 0)) { \
snprintf(yac_param_error_buffer_, yac_param_error_buffer_size_, \
__VA_ARGS__); \
} \
return 1; \
} \
} while (0)

Definition at line 58 of file param_internal.h.

◆ YAC_PARAM_CHECK_BASIC

#define YAC_PARAM_CHECK_BASIC ( )
Value:
YAC_ASSERT(name, "name is NULL"); \
YAC_ASSERT(name[0] != '\0', "name is empty string"); \
YAC_ASSERT_F( \
value_ptr, "value_ptr is NULL for parameter '%s'", name);
#define YAC_ASSERT(exp, msg)
char const * name
Definition toy_scrip.c:114

Definition at line 172 of file param_internal.h.

Enumeration Type Documentation

◆ yac_param_angle_unit

Unit of an angle value used in the parameter string API.

Enumerator
YAC_PARAM_ANGLE_UNIT_DEG 

degrees

YAC_PARAM_ANGLE_UNIT_RAD 

radians

Definition at line 84 of file param_internal.h.

Function Documentation

◆ yac_deg_to_rad()

double yac_deg_to_rad ( double deg,
char const * param_name )

Convert degrees to radians

Will try to use a precise value from math.h if available, otherwise falls back to the standard formula. All angles are automatically warped to the range [-180, 180) degrees or [-pi, pi) radians by the caller, so no special handling for values outside that range is needed here.

Parameters
degangle in degrees
param_nameparameter name for error messages (can be NULL)
Returns
angle in radians

Definition at line 372 of file param.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_param_format_scalar_dble()

int yac_param_format_scalar_dble ( char * buf,
size_t buflen,
double value,
const char * value_desc,
const char * param_name )

Format a double scalar value into buf

Parameters
buftarget output buffer
buflensize of buf in bytes
valuevalue to be formatted
value_descdescription of the value for error messages
param_nameparameter name for error messages (can be NULL)
Returns
0 on success, 1 on failure (error message is set)
Remarks
The formatting tries to use the highest significant-digit precision that still fits into the buffer, but will fail if the buffer is too small to hold the shortest possible representation of the value.

Definition at line 247 of file param.c.

Here is the caller graph for this function:

◆ yac_param_get_error_buffer()

void yac_param_get_error_buffer ( char ** buffer,
size_t * buffer_size )

Definition at line 172 of file param.c.

Here is the caller graph for this function:

◆ yac_param_parse_dble()

int yac_param_parse_dble ( const char * value_str,
const char * param_name,
double * value )

Parse a double from value_str.

Parameters
value_strstring to parse; if NULL the call fails with an error
param_namename of the parameter, used in error messages
valuereceives the parsed double on success
Returns
0 on success, 1 on parse error (error message is set)

Definition at line 177 of file param.c.

Here is the caller graph for this function:

◆ yac_param_parse_dble_with_unit()

int yac_param_parse_dble_with_unit ( const char * value_str,
const char * param_name,
double * value,
enum yac_param_angle_unit * unit )

Parse a double and optional angle unit suffix from value_str.

Accepted forms: "<double>", "<double> <unit>", "<double><unit>" with unit in {deg, rad, d, r} (case-insensitive).

Parameters
[in]value_strstring to parse; if NULL the call fails with an error
[in]param_namename of the parameter, used in error messages
[out]valuereceives the parsed double on success
[out]unitreceives parsed/default unit on success
Returns
0 on success, 1 on parse error (error message is set)

Definition at line 191 of file param.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_rad_to_deg()

double yac_rad_to_deg ( double rad,
char const * param_name )

Convert radians to degrees

Will try to use a precise value from math.h if available, otherwise falls back to the standard formula. All angles are automatically warped to the range [-180, 180) degrees or [-pi, pi) radians by the caller, so no special handling for values outside that range is needed here.

Parameters
radangle in radians
param_nameparameter name for error messages (can be NULL)
Returns
angle in degrees

Definition at line 385 of file param.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_wrap_deg()

double yac_wrap_deg ( double value,
char const * param_name )

Utility functions for warpping angle values to the standard range [-180, 180) degrees.

Parameters
valueangle value to be wrapped
param_nameparameter name for error messages (can be NULL)
Returns
wrapped angle value

Definition at line 319 of file param.c.

Here is the caller graph for this function:

◆ yac_wrap_rad()

double yac_wrap_rad ( double value,
char const * param_name )

Utility functions for warpping angle values to the standard range [-pi, pi) radians.

Parameters
valueangle value to be wrapped
param_nameparameter name for error messages (can be NULL)
Returns
wrapped angle value

Definition at line 306 of file param.c.

Here is the caller graph for this function: