A collection of commonly used functions for standard data exchange for scalars and arrays, and ASCII representations.
More...
|
int | x_error (int ret, int en, const char *from, const char *desc,...) |
|
int | x_trace (const char *loc, const char *op, int n) |
|
void * | x_trace_null (const char *loc, const char *op) |
|
int | x_warn (const char *from, const char *desc,...) |
|
void * | xAlloc (XType type, int count) |
|
int | xElementSizeOf (XType type) |
|
int | xError (const char *fn, int code) |
|
const char * | xErrorDescription (int code) |
|
long | xGetElementCount (int ndim, const int *sizes) |
|
boolean | xIsCharSequence (XType type) |
|
boolean | xIsDecimal (XType type) |
|
boolean | xIsInteger (XType type) |
|
boolean | xIsNumeric (XType type) |
|
boolean | xIsVerbose () |
|
boolean | xParseBoolean (char *str, char **end) |
|
int | xParseDims (const char *src, int *sizes) |
|
double | xParseDouble (const char *str, char **tail) |
|
float | xParseFloat (const char *str, char **tail) |
|
int | xPrintDims (char *dst, int ndim, const int *sizes) |
|
int | xPrintDouble (char *str, double value) |
|
int | xPrintFloat (char *str, float value) |
|
void | xSetDebug (boolean value) |
|
void | xSetVerbose (boolean value) |
|
char * | xStringCopyOf (const char *str) |
|
int | xStringElementSizeOf (XType type) |
|
char | xTypeChar (XType type) |
|
void | xZero (void *buf, XType type, int count) |
|
A collection of commonly used functions for standard data exchange for scalars and arrays, and ASCII representations.
- Date
- Nov 25, 2020
- Author
- Attila Kovacs
int xElementSizeOf |
( |
XType |
type | ) |
|
Returns the storage byte size of a single element of a given type.
- Parameters
-
- Returns
- [bytes] the native storage size of a single element of that type. E.g. for X_CHAR(20) it will return 20. X_DOUBLE will return 8, etc. Unrecognised types will return 0.
References X_BOOLEAN, X_BYTE, X_DOUBLE, X_FIELD, X_FLOAT, X_INT16, X_INT32, X_INT64, X_RAW, X_STRING, and X_STRUCT.
int xError |
( |
const char * |
fn, |
|
|
int |
code |
|
) |
| |
Prints a descriptive error message to stderr, and returns the error code.
- Parameters
-
fn | String that describes the function or location where the error occurred. |
code | The xchange error code that describes the failure (see xchange.h). |
- Returns
- Same error code as specified on input.
References X_ALREADY_OPEN, x_error(), X_FAILURE, X_GROUP_INVALID, X_INCOMPLETE, X_INTERRUPTED, X_NAME_INVALID, X_NO_BLOCKED_READ, X_NO_INIT, X_NO_PIPELINE, X_NO_SERVICE, X_NOT_ENOUGH_TOKENS, X_NULL, X_PARSE_ERROR, X_SIZE_INVALID, X_SUCCESS, X_TIMEDOUT, and X_TYPE_INVALID.
const char * xErrorDescription |
( |
int |
code | ) |
|
Returns a string description for one of the standard X-change error codes, and sets errno as appropriate also. (The mapping to error codes is not one-to-one. The same errno may be used to describe different X-change errors. Nevertheless, it is a guide that can be used when the X-change error is not directtly available, e.g. because it is not returned by a given function.)
- Parameters
-
code | One of the error codes defined in 'xchange.h' |
- Returns
- A constant string with the error description.
References X_ALREADY_OPEN, X_FAILURE, X_GROUP_INVALID, X_INCOMPLETE, X_INTERRUPTED, X_NAME_INVALID, X_NO_BLOCKED_READ, X_NO_INIT, X_NO_PIPELINE, X_NO_SERVICE, X_NOT_ENOUGH_TOKENS, X_NULL, X_PARSE_ERROR, X_SIZE_INVALID, X_SUCCESS, X_TIMEDOUT, and X_TYPE_INVALID.
boolean xParseBoolean |
( |
char * |
str, |
|
|
char ** |
end |
|
) |
| |
Parses a boolean value, either as a zero/non-zero number or as a case-insensitive match to the next token to one of the recognized boolean terms, such as "true"/"false", "on"/"off", "yes"/"no", "t"/"f", "y"/"n", "enabled"/"disabled" or "active"/"inactive". If a boolean value cannot be matched, FALSE is returned, and errno is set to ERANGE.
- Parameters
-
str | Pointer to the string token. |
end | Where the pointer to after the successfully parsed token is returned, on NULL. |
- Returns
- TRUE (1) or FALSE (0).
References FALSE, TRUE, and x_error().
double xParseDouble |
( |
const char * |
str, |
|
|
char ** |
tail |
|
) |
| |
Parses a double-precision floating point value from its decimal string representation. Effectively the same as strtod() on C99, but it checks the input string for NULL, resets errno before parsing so you don't have to, and will parse Infinity values even on older platforms that do not have built-in support for these.
- Parameters
-
str | String to parse floating-point value from |
tail | (optional) reference to pointed in which to return the parse position after successfully parsing a floating-point value. |
- Returns
- the floating-point value at the head of the string, or NAN if the input string is NULL, or 0.0 if the string does not start with a numerical value, or is a value near zero that cannot be represented by a float (underflow) or +/- INFINITY (or
HUGE_VAL
if INFINITY is not defined in math.h) if the value exceeds the float range (overflow). In cases of underflow or overflow errno will be set to ERANGE.
- See also
- xParseFloat()
-
xPrintDouble()
References INFINITY, NAN, and x_error().
float xParseFloat |
( |
const char * |
str, |
|
|
char ** |
tail |
|
) |
| |
Parses a single-precision floating point value from its decimal string representation. Effectively the same as or similar to strtof(), but it checks the input string for NULL, resets errno before parsing so you don't have to, and will parse Infinity values even on older platforms that do not have built-in support for these.
On older platforms, which do not have a builtin strtof()
function, this will parse the string as as double, before checking for range and returning the result recast as a float. The conversion may result in a decimal rounding 'error' if the returned value is then printed, whereby the last decimal digit may differ by one from the original input string.
- Parameters
-
str | String to parse floating-point value from |
tail | (optional) reference to pointed in which to return the parse position after successfully parsing a floating-point value. |
- Returns
- the floating-point value at the head of the string, or NAN if the input string is NULL, or 0.0F if the string does not start with a numerical value, or is a value near zero that cannot be represented by a float (underflow) or +/- INFINITY (or
HUGE_VAL
if INFINITY is not defined in math.h) if the value exceeds the float range (overflow). In cases of underflow or overflow errno will be set to ERANGE.
- Since
- 1.1
- See also
- xParseDouble()
-
xPrintFloat()
References INFINITY, NAN, x_error(), and xParseDouble().
int xStringElementSizeOf |
( |
XType |
type | ) |
|
Returns the number of characters, including a '\0' termination that a single element of the might be expected to fill.
- Parameters
-
type | X-Change type to check. |
- Returns
- Number of characters (including termination) required for the string representation of an element of the given variable, or 0 if the variable is of unknown type.
References X_BOOLEAN, X_BYTE, X_DOUBLE, x_error(), X_FLOAT, X_INT16, X_INT32, and X_INT64.