Common Pipeline Library Reference 7.3.2
|
Macros | |
#define | cpl_ensure(BOOL, ERRCODE, RETURN) |
Set an error code and return iff a boolean expression is false. | |
#define | cpl_ensure_code(BOOL, ERRCODE) |
Set an error code and return it iff a boolean expression is false. | |
#define | cpl_error_ensure(CONDITION, CODE, ACTION, ...) |
Generic error handling macro. | |
#define | CPL_ERROR_MAX_MESSAGE_LENGTH 256 |
The maximum length of a CPL error message. | |
#define | cpl_error_set(function, code) |
Set CPL error code, function name, source file and line number where an error occurred. | |
#define | cpl_error_set_message(function, code, ...) |
Set CPL error code, function name, source file and line number where an error occurred along with a text message. | |
#define | cpl_error_set_where(function) |
Propagate a CPL-error to the current location. | |
#define | CPL_HAVE_VA_ARGS |
Flag to indicate support for variadic macros. | |
Typedefs | |
typedef enum _cpl_error_code_ | cpl_error_code |
The cpl_error_code type definition. | |
Functions | |
cpl_error_code | cpl_error_get_code (void) |
Get the last cpl_error_code set. | |
const char * | cpl_error_get_file (void) |
Get the source code file name where the last CPL error occurred. | |
const char * | cpl_error_get_function (void) |
Get the function name where the last CPL error occurred. | |
unsigned | cpl_error_get_line (void) |
Get the line number where the last CPL error occurred. | |
const char * | cpl_error_get_message (void) |
Get the text message of the current CPL error. | |
const char * | cpl_error_get_message_default (cpl_error_code code) |
Return the standard CPL error message of the current CPL error. | |
const char * | cpl_error_get_where (void) |
Get function name, source file and line number where the last CPL error occurred. | |
This module provides functions to maintain the cpl_error_code set by any CPL function, similarly to what is done with the errno variable of the standard C library. The following guidelines are respected:
A cpl_error_code equal to the enumeration constant CPL_ERROR_NONE
would indicate no error condition. Note, however, that the cpl_error_code is only set when an error occurs, and it is not reset by successful function calls. For this reason it may be appropriate in some cases to reset the cpl_error_code using the function cpl_error_reset()
. The cpl_error_code set by a CPL function can be obtained by calling the function cpl_error_get_code()
, but functions of type cpl_error_code would not only return this code directly, but would also return CPL_ERROR_NONE
in case of success. Other CPL functions return zero on success, or a non-zero value to indicate a change of the cpl_error_code, while CPL functions returning a pointer would flag an error by returning a NULL
.
To each cpl_error_code is associated a standard error message, that can be obtained by calling the function cpl_error_get_message()
. Conventionally, no CPL function will ever display any error message, leaving to the caller the decision of how to handle a given error condition. A call to the function cpl_error_get_function()
would return the name of the function where the error occurred, and the functions cpl_error_get_file()
and cpl_error_get_line()
would also return the name of the source file containing the function code, and the line number where the error occurred. The function cpl_error_get_where()
would gather all this items together, in a colon-separated string.
#define cpl_ensure | ( | BOOL, | |
ERRCODE, | |||
RETURN | |||
) |
Set an error code and return iff a boolean expression is false.
BOOL | The boolean to evaluate |
ERRCODE | The error code to set |
RETURN | The value to return |
#define cpl_ensure_code | ( | BOOL, | |
ERRCODE | |||
) |
Set an error code and return it iff a boolean expression is false.
BOOL | The boolean to evaluate |
ERRCODE | The error code to set and return |
#define cpl_error_ensure | ( | CONDITION, | |
CODE, | |||
ACTION, | |||
... | |||
) |
Generic error handling macro.
CONDITION | The condition to check |
CODE | The CPL error code to set if CONDTION is non-zero |
ACTION | A statement that is executed iff the CONDITION evaluates to non-zero. |
... | A printf-style message for cpl_error_set_message(). |
Useful definitions might include
or (same as above, but including printf-style error messages)
or
The check macros in the examples above can be used to check a command which sets the cpl_error_code in case of failure (or, by use of a comma expression, a longer sequence of such commands):
#define CPL_ERROR_MAX_MESSAGE_LENGTH 256 |
The maximum length of a CPL error message.
#define cpl_error_set | ( | function, | |
code | |||
) |
Set CPL error code, function name, source file and line number where an error occurred.
function | Character string with function name, cpl_func |
code | Error code |
#define cpl_error_set_message | ( | function, | |
code, | |||
... | |||
) |
Set CPL error code, function name, source file and line number where an error occurred along with a text message.
function | Character string with function name, cpl_func |
code | Error code |
... | Variable argument list with message |
Examples of usage:
Example of usage if and only if variadic macros are unavaiable (e.g. when compiling with gcc -ansi):
#define cpl_error_set_where | ( | function | ) |
Propagate a CPL-error to the current location.
function | Character string with function name, cpl_func |
If a CPL error already exists, this function creates a new CPL error with the preexisting CPL error code and the current location.
In a function of type cpl_error_code an error can be propagated with:
#define CPL_HAVE_VA_ARGS |
Flag to indicate support for variadic macros.
typedef enum _cpl_error_code_ cpl_error_code |
The cpl_error_code type definition.
enum _cpl_error_code_ |
Available error codes.
CPL_ERROR_NONE
is equal to zero and compares to less than all other error codes.
All error codes are guaranteed to be less than CPL_ERROR_EOL
(End Of List). CPL_ERROR_EOL
allows user defined error codes to be added in this fashion:
Extensive use of user defined error codes should be avoided. Instead a request of new CPL error codes should be emailed to cpl-h.nosp@m.elp@.nosp@m.eso.o.nosp@m.rg.
cpl_error_code cpl_error_get_code | ( | void | ) |
Get the last cpl_error_code set.
Get cpl_error_code of last occurred error.
References CPL_ERROR_NONE.
Referenced by cpl_apertures_extract_window(), cpl_bivector_interpolate_linear(), cpl_detector_interpolate_rejected(), cpl_dfs_save_paf(), cpl_dfs_setup_product_header(), cpl_dfs_sign_products(), cpl_errorstate_dump(), cpl_frameset_dump(), cpl_frameset_extract(), cpl_frameset_labelise(), cpl_image_abs_create(), cpl_image_add_scalar_create(), cpl_image_collapse_create(), cpl_image_divide_scalar_create(), cpl_image_exponential_create(), cpl_image_fft(), cpl_image_filter_median(), cpl_image_filter_stdev(), cpl_image_get_fwhm(), cpl_image_get_interpolated(), cpl_image_logarithm_create(), cpl_image_multiply_scalar_create(), cpl_image_normalise(), cpl_image_power_create(), cpl_image_subtract_scalar_create(), cpl_image_warp_polynomial(), cpl_imagelist_add_scalar(), cpl_imagelist_divide_scalar(), cpl_imagelist_dump_structure(), cpl_imagelist_dump_window(), cpl_imagelist_exponential(), cpl_imagelist_load_frameset(), cpl_imagelist_logarithm(), cpl_imagelist_multiply_scalar(), cpl_imagelist_normalise(), cpl_imagelist_power(), cpl_imagelist_subtract_scalar(), cpl_imagelist_threshold(), cpl_plot_image_col(), cpl_sprintf(), cpl_test_end(), cpl_vector_copy(), cpl_vector_fill_kernel_profile(), and cpl_wcs_platesol().
const char * cpl_error_get_file | ( | void | ) |
Get the source code file name where the last CPL error occurred.
Get the source code file name where the last CPL error occurred.
Referenced by cpl_error_get_where().
const char * cpl_error_get_function | ( | void | ) |
Get the function name where the last CPL error occurred.
Get the function name where the last CPL error occurred.
Referenced by cpl_error_get_where().
unsigned cpl_error_get_line | ( | void | ) |
Get the line number where the last CPL error occurred.
Get the line number of the source file where the last CPL error occurred.
Referenced by cpl_error_get_where().
const char * cpl_error_get_message | ( | void | ) |
Get the text message of the current CPL error.
If the cpl_error_code is equal to CPL_ERROR_NONE
, an empty string is returned. Otherwise, the message is the default message for the current CPL error code, possibly extended with a custom message supplied when the error was set.
References cpl_error_get_message_default(), and CPL_ERROR_NONE.
const char * cpl_error_get_message_default | ( | cpl_error_code | code | ) |
Return the standard CPL error message of the current CPL error.
code | The error code of the current CPL error |
References CPL_ERROR_ACCESS_OUT_OF_RANGE, CPL_ERROR_ASSIGNING_STREAM, CPL_ERROR_BAD_FILE_FORMAT, CPL_ERROR_CONTINUE, CPL_ERROR_DATA_NOT_FOUND, CPL_ERROR_DIVISION_BY_ZERO, CPL_ERROR_DUPLICATING_STREAM, CPL_ERROR_EOL, CPL_ERROR_FILE_ALREADY_OPEN, CPL_ERROR_FILE_IO, CPL_ERROR_FILE_NOT_CREATED, CPL_ERROR_FILE_NOT_FOUND, CPL_ERROR_HISTORY_LOST, CPL_ERROR_ILLEGAL_INPUT, CPL_ERROR_ILLEGAL_OUTPUT, CPL_ERROR_INCOMPATIBLE_INPUT, CPL_ERROR_INVALID_TYPE, CPL_ERROR_NO_WCS, CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, CPL_ERROR_SINGULAR_MATRIX, CPL_ERROR_TYPE_MISMATCH, CPL_ERROR_UNSPECIFIED, and CPL_ERROR_UNSUPPORTED_MODE.
Referenced by cpl_error_get_message().
const char * cpl_error_get_where | ( | void | ) |
Get function name, source file and line number where the last CPL error occurred.
Get where the last CPL error occurred in the form function_name:source_file:line_number
References cpl_error_get_file(), cpl_error_get_function(), and cpl_error_get_line().