xchange v0.9
Structured data exchange for C/C++
|
A collection of commonly used functions for standard data exchange for scalars and arrays, and ASCII representations. More...
Macros | |
#define | __XCHANGE_INTERNAL_API__ |
Use internal definitions. | |
#define | EIXPLICIT_PARSE_SPECIAL_DOUBLES TRUE |
Functions | |
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) |
int | xGetElementCount (int ndim, const int *sizes) |
boolean | xIsCharSequence (XType type) |
boolean | xIsVerbose () |
boolean | xParseBoolean (char *str, char **end) |
int | xParseDims (const char *src, int *sizes) |
double | xParseDouble (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) |
Variables | |
boolean | xDebug = FALSE |
Switch to enable debugging (very verbose) output for XChange operations. | |
boolean | xVerbose |
Switch to enable verbose console output for XChange operations. | |
A collection of commonly used functions for standard data exchange for scalars and arrays, and ASCII representations.
#define EIXPLICIT_PARSE_SPECIAL_DOUBLES TRUE |
Check if we need to parse special floating point values, such as 'nan', 'infinity' or 'inf'... These were added in the C99 standard, at the same time as the constant INFINITY was added.
int x_error | ( | int | ret, |
int | en, | ||
const char * | from, | ||
const char * | desc, | ||
... | |||
) |
(for internal use) Sets errno and reports errors to the standard error, depending on the current debug mode, before returning the supplied return code.
ret | return value |
en | UNIX error code (see errno.h) |
from | function (:location) where error originated |
desc | description of error, with information to convey to user. |
References xDebug.
int x_trace | ( | const char * | loc, |
const char * | op, | ||
int | n | ||
) |
(for internal use) Propagates an error (if any). If the error is non-zero, it returns with the offset error value. Otherwise it keeps going as if it weren't even there...
loc | Function [:location] where error was produced. |
op | (optional) further info or NULL. |
n | error code that was received. |
References xDebug.
void * x_trace_null | ( | const char * | loc, |
const char * | op | ||
) |
(for internal use) Traces an error before returning NULL.
loc | Function [:location] where error was produced. |
op | (optional) further info or NULL. |
References xDebug.
int x_warn | ( | const char * | from, |
const char * | desc, | ||
... | |||
) |
void * xAlloc | ( | XType | type, |
int | count | ||
) |
Allocates a buffer for a given SMA-X type and element count. The buffer is initialized with zeroes.
type | SMA-X type |
count | number of elements. |
References x_error(), x_trace_null(), and xElementSizeOf().
int xElementSizeOf | ( | XType | type | ) |
Returns the storage byte size of a single element of a given type.
type | The data type, as defined in 'xchange.h' |
References X_BOOLEAN, X_BYTE, X_BYTE_HEX, X_DOUBLE, X_FLOAT, X_INT, X_INT_HEX, X_LONG, X_LONG_HEX, X_RAW, X_SHORT, X_SHORT_HEX, X_STRING, and X_STRUCT.
int xError | ( | const char * | fn, |
int | code | ||
) |
Prints a descriptive error message to stderr, and returns the error code.
fn | String that describes the function or location where the error occurred. |
code | The xchange error code that describes the failure (see xchange.h). |
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.)
code | One of the error codes defined in 'xchange.h' |
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.
int xGetElementCount | ( | int | ndim, |
const int * | sizes | ||
) |
Returns the total element count specified by along a number of dimensions. It ignores dimensions that have size components <= 0;
ndim | Number of dimensions |
sizes | Sizes along each dimension. |
References x_error(), and X_MAX_DIMS.
Checks if the type represents a fixed-size character / binary sequence.
type | X-Change type to check. |
boolean xIsVerbose | ( | ) |
Checks if verbosity is enabled for the xchange library.
References xVerbose.
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.
str | Pointer to the string token. |
end | Where the pointer to after the successfully parsed token is returned, on NULL. |
int xParseDims | ( | const char * | src, |
int * | sizes | ||
) |
Deserializes the sizes from a space-separated list of dimensions. The parsing will terminate at the first non integer value or the end of string, whichever comes first. Integer values <= 0 are ignored.
src | Pointer to a string buffer that contains the serialized dimensions, as a list of space separated integers. |
sizes | Pointer to an array of ints (usually of X_MAX_DIMS size) to which the valid dimensions are deserialized. |
References x_error(), and X_MAX_DIMS.
double xParseDouble | ( | const char * | str, |
char ** | tail | ||
) |
Same as strtod() on C99, but with explicit parsing of NaN and Infinity values on older platforms also.
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. |
int xPrintDims | ( | char * | dst, |
int | ndim, | ||
const int * | sizes | ||
) |
Serializes the dimensions to a string as a space-separated list of integers.
[out] | dst | Pointer to a string buffer with at least X_MAX_STRING_DIMS bytes size. |
[in] | ndim | Number of dimensions |
[in] | sizes | Sizes along each dimension. |
References x_error(), and X_MAX_DIMS.
int xPrintDouble | ( | char * | str, |
double | value | ||
) |
Prints a double precision number, restricted to IEEE double-precision range. If the native value has abolute value smaller than the smallest non-zero value, then 0 will printed instead. For values that exceed the IEEE double precision range, "nan" will be printed.
str | Pointer to buffer for printed value. |
value | Value to print. |
References x_error().
int xPrintFloat | ( | char * | str, |
float | value | ||
) |
Prints a single-precision number, restricted to IEEE single-precision range. If the native value has abolute value smaller than the smallest non-zero value, then 0 will printed instead. For values that exceed the IEEE double precision range, "nan" will be printed.
str | Pointer to buffer for printed value. |
value | Value to print. |
References x_error().
void xSetDebug | ( | boolean | value | ) |
Enables or disables debugging output.
value | TRUE (non-zero) to enable verbose output, or else FALSE (0). |
void xSetVerbose | ( | boolean | value | ) |
Sets verbose output for the xchange library.
value | TRUE (non-zero) to enable verbose output, or else FALSE (0). |
char * xStringCopyOf | ( | const char * | str | ) |
Returns a freshly allocated string with the same content as the argument.
str | Pointer to string we want to copy. |
int xStringElementSizeOf | ( | XType | type | ) |
Returns the number of characters, including a '\0' termination that a single element of the might be expected to fill.
type | X-Change type to check. |
References X_BOOLEAN, X_BYTE, X_BYTE_HEX, X_DOUBLE, x_error(), X_FLOAT, X_INT, X_INT_HEX, X_LONG, X_LONG_HEX, X_SHORT, and X_SHORT_HEX.
char xTypeChar | ( | XType | type | ) |
Returns the character of the field type. For X_CHAR types it returns 'C' (without the length specification), and for all other types it returns the constant XType value itself.
type | The single-character IF of the field type. |
References x_error().
void xZero | ( | void * | buf, |
XType | type, | ||
int | count | ||
) |
Zeroes out the contents of an SMA-X buffer.
buf | Pointer to the buffer to fill with zeroes. |
type | SMA-X type |
count | number of elements. |
References xElementSizeOf().