YAC 3.18.0
Yet Another Coupler
Loading...
Searching...
No Matches
param.h File Reference

Public interface for YAC parameters. More...

#include <stddef.h>
Include dependency graph for param.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  yac_param_type {
  YAC_PARAM_TYPE_INVALID = 0 , YAC_PARAM_TYPE_EMPTY , YAC_PARAM_TYPE_SCALAR , YAC_PARAM_TYPE_STRUCT ,
  YAC_PARAM_TYPE_LIST
}
 Parameter type for generic configuration interface. More...
 

Functions

enum yac_param_type yac_param_get_type (const struct yac_param *param)
 Get the type of a parameter.
 
int yac_param_is_default (const struct yac_param *param)
 Check whether a parameter is at its default value.
 
const char * yac_param_get_name (const struct yac_param *param)
 Get the name of the current parameter.
 
int yac_param_get_sub_count (const struct yac_param *param, size_t *count)
 Get the number of subparameters.
 
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.
 
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_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.
 
int yac_param_set_scalar (struct yac_param *param, const char *value_str)
 Set the value of a scalar parameter from a string.
 
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_int (struct yac_param *param, int value)
 Set the value of a scalar parameter as an int.
 
int yac_param_set_scalar_dble (struct yac_param *param, double value)
 Set the value of a scalar parameter as a double.
 
int yac_param_get_scalar_int (const struct yac_param *param, int *value)
 Get the value of a scalar parameter as an int.
 
int yac_param_get_scalar_dble (const struct yac_param *param, double *value)
 Get 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.
 
void yac_param_delete (struct yac_param *param)
 

Detailed Description

Public interface for YAC parameters.

See also
YAC Parameters

Definition in file param.h.

Enumeration Type Documentation

◆ yac_param_type

Parameter type for generic configuration interface.

Enumerator
YAC_PARAM_TYPE_INVALID 

Uninitialized or error state.

YAC_PARAM_TYPE_EMPTY 

No value (used for optional/absent parameters)

YAC_PARAM_TYPE_SCALAR 

Single typed value (e.g., int, double, string, enum)

YAC_PARAM_TYPE_STRUCT 

Named, fixed set of subparameters.

YAC_PARAM_TYPE_LIST 

Ordered, growable list of subparameters.

Definition at line 170 of file param.h.

Function Documentation

◆ yac_param_append()

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.

For list parameters, appends a new subparameter generated by the default_factory function provided at list construction. Returns a handle to the new subparameter via the output pointer.

Parameters
paramParameter handle (must be a list)
[out]sub_paramPointer to output handle for the new subparameter
Returns
0 on success, nonzero on error

Definition at line 107 of file param.c.

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

◆ yac_param_delete()

void yac_param_delete ( struct yac_param * param)

Definition at line 307 of file param.c.

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

◆ yac_param_get_last_error()

const char * yac_param_get_last_error ( void )

Retrieve the last error message for the calling thread.

If a parameter API function returns an error, this function returns a pointer to a thread-local buffer containing a human-readable error message. The pointer is valid until the next API call in the same thread.

Returns
Pointer to the last error message string (never NULL).

Definition at line 301 of file param.c.

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

◆ yac_param_get_name()

const char * yac_param_get_name ( const struct yac_param * param)

Get the name of the current parameter.

Returns the name of the parameter referenced by the handle. For root or unnamed parameters, returns NULL. The returned pointer is valid until the next API call in the same thread.

Parameters
paramParameter handle
Returns
Name of the parameter, or NULL if unnamed/root

Definition at line 50 of file param.c.

Here is the caller graph for this function:

◆ yac_param_get_scalar()

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.

The value is converted to a string representation and written to the output buffer. The output buffer must be large enough to hold the value and a null terminator. On error, returns nonzero and sets an error message.

Parameters
paramParameter handle
[out]bufOutput buffer for string value
buflenSize of output buffer
Returns
0 on success, nonzero on error

Definition at line 128 of file param.c.

Here is the caller graph for this function:

◆ yac_param_get_scalar_dble()

int yac_param_get_scalar_dble ( const struct yac_param * param,
double * value )

Get the value of a scalar parameter as a double.

Only works if the parameter supports double retrieval. On error or if not supported, returns nonzero and sets an error message.

Parameters
paramParameter handle
[out]valuePointer to output double value
Returns
0 on success, nonzero on error

Definition at line 166 of file param.c.

Here is the caller graph for this function:

◆ yac_param_get_scalar_int()

int yac_param_get_scalar_int ( const struct yac_param * param,
int * value )

Get the value of a scalar parameter as an int.

Only works if the parameter supports integer retrieval. On error or if not supported, returns nonzero and sets an error message.

Parameters
paramParameter handle
[out]valuePointer to output integer value
Returns
0 on success, nonzero on error

Definition at line 157 of file param.c.

Here is the caller graph for this function:

◆ yac_param_get_sub_by_index()

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.

For struct and list parameters, returns a handle to the i'th subparameter (0 <= idx < sub_count) via the output pointer. For oneof parameters, returns a handle to the active subparameter, if idx=0.

Note: The returned sub_param handle is managed internally and must NOT be freed or deleted by the caller.

Parameters
paramParameter handle
idxSubparameter index
[out]sub_paramPointer to output handle
Returns
0 on success, nonzero on error

Definition at line 92 of file param.c.

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

◆ yac_param_get_sub_by_name()

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.

For struct parameters, returns a handle to the subparameter with the given name via the output pointer. For list parameters, returns a handle to the subparameter with the given name. For oneof parameters, returns a handle to the subparameter with the given name, if it is the active one; otherwise returns an error.

Note: The returned sub_param handle is managed internally and must NOT be freed or deleted by the caller.

Parameters
paramParameter handle
nameSubparameter name
[out]sub_paramPointer to output handle
Returns
0 on success, nonzero on error

Definition at line 75 of file param.c.

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

◆ yac_param_get_sub_count()

int yac_param_get_sub_count ( const struct yac_param * param,
size_t * count )

Get the number of subparameters.

For struct parameters, sets count to the number of named subparameters. For list parameters, sets count to the current number of elements in the list. For oneof parameters, sets count to one. For scalar or empty parameters, sets count to 0 and sets an error message.

Parameters
paramParameter handle
[out]countPointer to output count
Returns
0 on success, nonzero on error

Definition at line 60 of file param.c.

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

◆ yac_param_get_type()

enum yac_param_type yac_param_get_type ( const struct yac_param * param)

Get the type of a parameter.

Returns the type of the parameter referenced by the handle. This can be used to determine if the parameter is a scalar, struct, list, or empty.

Parameters
paramParameter handle
Returns
Parameter type (see yac_param_type)

Definition at line 24 of file param.c.

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

◆ yac_param_is_default()

int yac_param_is_default ( const struct yac_param * param)

Check whether a parameter is at its default value.

Returns 1 if the parameter is currently set to its default value, 0 if not. On error (e.g., invalid handle), returns -1 and sets an error message.

Parameters
paramParameter handle
Returns
1 if at default, 0 if not, -1 on error

Definition at line 37 of file param.c.

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

◆ yac_param_set_scalar()

int yac_param_set_scalar ( struct yac_param * param,
const char * value_str )

Set the value of a scalar parameter from a string.

The value string is parsed and converted to the parameter's type internally. For example, "42" for an integer, "3.14" for a double, or "foo" for a string. On error (e.g., invalid format), returns nonzero and sets an error message.

Parameters
paramParameter handle
value_strString representation of the value
Returns
0 on success, nonzero on error

Definition at line 118 of file param.c.

Here is the caller graph for this function:

◆ yac_param_set_scalar_dble()

int yac_param_set_scalar_dble ( struct yac_param * param,
double value )

Set the value of a scalar parameter as a double.

Only works if the parameter supports double assignment. On error or if not supported, returns nonzero and sets an error message.

Parameters
paramParameter handle
valueDouble value to set
Returns
0 on success, nonzero on error

Definition at line 148 of file param.c.

Here is the caller graph for this function:

◆ yac_param_set_scalar_int()

int yac_param_set_scalar_int ( struct yac_param * param,
int value )

Set the value of a scalar parameter as an int.

Only works if the parameter supports integer assignment. On error or if not supported, returns nonzero and sets an error message.

Parameters
paramParameter handle
valueInteger value to set
Returns
0 on success, nonzero on error

Definition at line 139 of file param.c.

Here is the caller graph for this function: