⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cplerror.cpp

📁 国际海图标准S-57格式数据读取源码VC
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "stdafx.h"#include "CplError.h"#include "CplVsi.h"#include "CplConv.h"#define TIMESTAMP_DEBUGCPL_CVSID("$Id: cpl_error.cpp,v 1.27 2003/05/27 20:44:16 warmerda Exp $");/* static buffer to store the last error message.  We'll assume that error * messages cannot be longer than 2000 chars... which is quite reasonable * (that's 25 lines of 80 chars!!!) */static char gszCPLLastErrMsg[2000] = "";static int  gnCPLLastErrNo = 0;static CPLErr geCPLLastErrType = CE_None;static CPLErrorHandler gpfnCPLErrorHandler = CPLDefaultErrorHandler;typedef struct errHandler{    struct errHandler   *psNext;    CPLErrorHandler     pfnHandler;} CPLErrorHandlerNode;static CPLErrorHandlerNode * psHandlerStack = NULL;/********************************************************************** *                          CPLError() **********************************************************************//** * Report an error. * * This function reports an error in a manner that can be hooked * and reported appropriate by different applications. * * The effect of this function can be altered by applications by installing * a custom error handling using CPLSetErrorHandler(). * * The eErrClass argument can have the value CE_Warning indicating that the * message is an informational warning, CE_Failure indicating that the * action failed, but that normal recover mechanisms will be used or * CE_Fatal meaning that a fatal error has occured, and that CPLError() * should not return.   * * The default behaviour of CPLError() is to report errors to stderr, * and to abort() after reporting a CE_Fatal error.  It is expected that * some applications will want to supress error reporting, and will want to * install a C++ exception, or longjmp() approach to no local fatal error * recovery. * * Regardless of how application error handlers or the default error * handler choose to handle an error, the error number, and message will * be stored for recovery with CPLGetLastErrorNo() and CPLGetLastErrorMsg(). * * @param eErrClass one of CE_Warning, CE_Failure or CE_Fatal. * @param err_no the error number (CPLE_*) from cpl_error.h. * @param fmt a printf() style format string.  Any additional arguments * will be treated as arguments to fill in this format in a manner * similar to printf(). */void    CPLError(CPLErr eErrClass, int err_no, const char *fmt, ...){    va_list args;    /* Expand the error message      */    va_start(args, fmt);    CPLErrorV( eErrClass, err_no, fmt, args );    va_end(args);}/************************************************************************//*                             CPLErrorV()                              *//************************************************************************/void    CPLErrorV(CPLErr eErrClass, int err_no, const char *fmt, va_list args ){    /* Expand the error message      */#if defined(HAVE_VSNPRINTF)    vsnprintf( gszCPLLastErrMsg, sizeof(gszCPLLastErrMsg), fmt, args );#else    vsprintf(gszCPLLastErrMsg, fmt, args);#endif    /* If the user provided his own error handling function, then call     * it, otherwise print the error to stderr and return.     */    gnCPLLastErrNo = err_no;    geCPLLastErrType = eErrClass;    if( CPLGetConfigOption("CPL_LOG_ERRORS",NULL) != NULL )        CPLDebug( "CPLError", "%s", gszCPLLastErrMsg );    if( gpfnCPLErrorHandler )        gpfnCPLErrorHandler(eErrClass, err_no, gszCPLLastErrMsg);    if( eErrClass == CE_Fatal )        abort();}/************************************************************************//*                              CPLDebug()                              *//************************************************************************//** * Display a debugging message. * * The category argument is used in conjunction with the CPL_DEBUG * environment variable to establish if the message should be displayed. * If the CPL_DEBUG environment variable is not set, no debug messages * are emitted (use CPLError(CE_Warning,...) to ensure messages are displayed). * If CPL_DEBUG is set, but is an empty string or the word "ON" then all * debug messages are shown.  Otherwise only messages whose category appears * somewhere within the CPL_DEBUG value are displayed (as determinted by * strstr()). * * Categories are usually an identifier for the subsystem producing the * error.  For instance "GDAL" might be used for the GDAL core, and "TIFF" * for messages from the TIFF translator.   * * @param pszCategory name of the debugging message category. * @param pszFormat printf() style format string for message to display. *        Remaining arguments are assumed to be for format. */ void CPLDebug( const char * pszCategory, const char * pszFormat, ... ){    char        *pszMessage;    va_list     args;    const char  *pszDebug = CPLGetConfigOption("CPL_DEBUG",NULL);#define ERROR_MAX 25000/* -------------------------------------------------------------------- *//*      Does this message pass our current criteria?                    *//* -------------------------------------------------------------------- */    if( pszDebug == NULL )        return;    if( !EQUAL(pszDebug,"ON") && !EQUAL(pszDebug,"") )    {        int            i, nLen = strlen(pszCategory);        for( i = 0; pszDebug[i] != '\0'; i++ )        {            if( EQUALN(pszCategory,pszDebug+i,nLen) )                break;        }        if( pszDebug[i] == '\0' )            return;    }/* -------------------------------------------------------------------- *//*    Allocate a block for the error.                                   *//* -------------------------------------------------------------------- */    pszMessage = (char *) VSIMalloc( ERROR_MAX );    if( pszMessage == NULL )        return;        /* -------------------------------------------------------------------- *//*      Dal -- always log a timestamp as the first part of the line     *//*      to ensure one is looking at what one should be looking at!      *//* -------------------------------------------------------------------- */    pszMessage[0] = '\0';#ifdef TIMESTAMP_DEBUG    if( CPLGetConfigOption( "CPL_TIMESTAMP", NULL ) != NULL )    {        strcpy( pszMessage, VSICTime( VSITime(NULL) ) );                // On windows anyway, ctime puts a \n at the end, but I'm not         // convinced this is standard behaviour, so we'll get rid of it        // carefully        if (pszMessage[strlen(pszMessage) -1 ] == '\n')        {            pszMessage[strlen(pszMessage) - 1] = 0; // blow it out        }        strcat( pszMessage, ": " );    }#endif/* -------------------------------------------------------------------- *//*      Add the category.                                               *//* -------------------------------------------------------------------- */    strcat( pszMessage, pszCategory );    strcat( pszMessage, ": " );    /* -------------------------------------------------------------------- *//*      Format the application provided portion of the debug message.   *//* -------------------------------------------------------------------- */    va_start(args, pszFormat);#if defined(HAVE_VSNPRINTF)    vsnprintf(pszMessage+strlen(pszMessage), ERROR_MAX - strlen(pszMessage),               pszFormat, args);#else    vsprintf(pszMessage+strlen(pszMessage), pszFormat, args);#endif    va_end(args);/* -------------------------------------------------------------------- *//*      If the user provided his own error handling function, then call *//*      it, otherwise print the error to stderr and return.             *//* -------------------------------------------------------------------- */    if( gpfnCPLErrorHandler )        gpfnCPLErrorHandler(CE_Debug, CPLE_None, pszMessage);    VSIFree( pszMessage );}/********************************************************************** *                          CPLErrorReset() **********************************************************************//** * Erase any traces of previous errors. * * This is normally used to ensure that an error which has been recovered * from does not appear to be still in play with high level functions. */void    CPLErrorReset(){    gnCPLLastErrNo = CPLE_None;    gszCPLLastErrMsg[0] = '\0';    geCPLLastErrType = CE_None;}/********************************************************************** *                          CPLGetLastErrorNo() **********************************************************************//** * Fetch the last error number. * * This is the error number, not the error class. * * @return the error number of the last error to occur, or CPLE_None (0) * if there are no posted errors. */int     CPLGetLastErrorNo(){    return gnCPLLastErrNo;}/********************************************************************** *                          CPLGetLastErrorType() **********************************************************************//** * Fetch the last error type. * * This is the error class, not the error number. * * @return the error number of the last error to occur, or CE_None (0) * if there are no posted errors. */CPLErr CPLGetLastErrorType(){    return geCPLLastErrType;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -