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

📄 cpl_conv.cpp

📁 用于读取TAB、MIF、SHP文件的类
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    {        *pszTemp++ = *pszSrc++;        nMaxLen--;    }    if ( nMaxLen )        memset( pszTemp, ' ', nMaxLen );    return nMaxLen;}/************************************************************************//*                          CPLPrintInt32()                             *//************************************************************************//** * Print GInt32 value into specified string buffer. This string will not * be NULL-terminated. * * @param Pointer to the destination string buffer. Should be * large enough to hold the resulting string. Note, that the string will * not be NULL-terminated, so user should do this himself, if needed. * * @param iValue Numerical value to print. *  * @param nMaxLen Maximum length of the resulting string. If string length * is greater than nMaxLen, it will be truncated. *  * @return Number of characters printed. */int CPLPrintInt32( char *pszBuffer, GInt32 iValue, int nMaxLen ){    char    szTemp[64];    if ( !pszBuffer )        return 0;    if ( nMaxLen >= 64 )        nMaxLen = 63;#if UINT_MAX == 65535    sprintf( szTemp, "%*ld", nMaxLen, iValue );#else    sprintf( szTemp, "%*d", nMaxLen, iValue );#endif    return CPLPrintString( pszBuffer, szTemp, nMaxLen );}/************************************************************************//*                          CPLPrintUIntBig()                           *//************************************************************************//** * Print GUIntBig value into specified string buffer. This string will not * be NULL-terminated. * * @param Pointer to the destination string buffer. Should be * large enough to hold the resulting string. Note, that the string will * not be NULL-terminated, so user should do this himself, if needed. * * @param iValue Numerical value to print. *  * @param nMaxLen Maximum length of the resulting string. If string length * is greater than nMaxLen, it will be truncated. *  * @return Number of characters printed. */int CPLPrintUIntBig( char *pszBuffer, GUIntBig iValue, int nMaxLen ){    char    szTemp[64];    if ( !pszBuffer )        return 0;    if ( nMaxLen >= 64 )        nMaxLen = 63;#if defined(WIN32) && defined(_MSC_VER)    sprintf( szTemp, "%*I64d", nMaxLen, iValue );# elif HAVE_LONG_LONG    sprintf( szTemp, "%*lld", nMaxLen, (long long) iValue );//    sprintf( szTemp, "%*Ld", nMaxLen, (long long) iValue );#else    sprintf( szTemp, "%*ld", nMaxLen, iValue );#endif    return CPLPrintString( pszBuffer, szTemp, nMaxLen );}/************************************************************************//*                          CPLPrintPointer()                           *//************************************************************************//** * Print pointer value into specified string buffer. This string will not * be NULL-terminated. * * @param Pointer to the destination string buffer. Should be * large enough to hold the resulting string. Note, that the string will * not be NULL-terminated, so user should do this himself, if needed. * * @param pValue Pointer to ASCII encode. *  * @param nMaxLen Maximum length of the resulting string. If string length * is greater than nMaxLen, it will be truncated. *  * @return Number of characters printed. */int CPLPrintPointer( char *pszBuffer, void *pValue, int nMaxLen ){    char    szTemp[64];    if ( !pszBuffer )        return 0;    if ( nMaxLen >= 64 )        nMaxLen = 63;    sprintf( szTemp, "%p", pValue );    // On windows, and possibly some other platforms the sprintf("%p")    // does not prefix things with 0x so it is hard to know later if the    // value is hex encoded.  Fix this up here.     if( !EQUALN(szTemp,"0x",2) )        sprintf( szTemp, "0x%p", pValue );    return CPLPrintString( pszBuffer, szTemp, nMaxLen );}/************************************************************************//*                          CPLPrintDouble()                            *//************************************************************************//** * Print double value into specified string buffer. Exponential character * flag 'E' (or 'e') will be replaced with 'D', as in Fortran. Resulting * string will not to be NULL-terminated. * * @param Pointer to the destination string buffer. Should be * large enough to hold the resulting string. Note, that the string will * not be NULL-terminated, so user should do this himself, if needed. * * @param Format specifier (for example, "%16.9E"). * * @param dfValue Numerical value to print. *  * @param pszLocale Pointer to a character string containing locale name * ("C", "POSIX", "us_US", "ru_RU.KOI8-R" etc.). If NULL we will not * manipulate with locale settings and current process locale will be used for * printing. With the pszLocale option we can control what exact locale * will be used for printing a numeric value to the string (in most cases * it should be C/POSIX). * * @return Number of characters printed. */int CPLPrintDouble( char *pszBuffer, const char *pszFormat,                    double dfValue, char *pszLocale ){#define DOUBLE_BUFFER_SIZE 64    char    szTemp[DOUBLE_BUFFER_SIZE];    int     i;    if ( !pszBuffer )        return 0;#if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)    char        *pszCurLocale = NULL;    if ( pszLocale || EQUAL( pszLocale, "" ) )    {        // Save the current locale        pszCurLocale = setlocale(LC_ALL, NULL );        // Set locale to the specified value        setlocale( LC_ALL, pszLocale );    }#endif#if defined(HAVE_SNPRINTF)    snprintf( szTemp, DOUBLE_BUFFER_SIZE, pszFormat, dfValue );#else    sprintf( szTemp, pszFormat, dfValue );#endif    szTemp[DOUBLE_BUFFER_SIZE - 1] = '\0';    for( i = 0; szTemp[i] != '\0'; i++ )    {        if( szTemp[i] == 'E' || szTemp[i] == 'e' )            szTemp[i] = 'D';    }#if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)    // Restore stored locale back    if ( pszCurLocale )        setlocale( LC_ALL, pszCurLocale );#endif    return CPLPrintString( pszBuffer, szTemp, 64 );#undef DOUBLE_BUFFER_SIZE}/************************************************************************//*                            CPLPrintTime()                            *//************************************************************************//** * Print specified time value accordingly to the format options and * specified locale name. This function does following: *  *  - if locale parameter is not NULL, the current locale setting will be *  stored and replaced with the specified one; *  - format time value with the strftime(3) function; *  - restore back current locale, if was saved. *  * @param pszBuffer Pointer to the destination string buffer. Should be * large enough to hold the resulting string. Note, that the string will * not be NULL-terminated, so user should do this himself, if needed. * * @param nMaxLen Maximum length of the resulting string. If string length is * greater than nMaxLen, it will be truncated. *  * @param pszFormat Controls the output format. Options are the same as * for strftime(3) function. * * @param poBrokenTime Pointer to the broken-down time structure. May be * requested with the VSIGMTime() and VSILocalTime() functions. * * @param pszLocale Pointer to a character string containing locale name * ("C", "POSIX", "us_US", "ru_RU.KOI8-R" etc.). If NULL we will not * manipulate with locale settings and current process locale will be used for * printing. Be aware that it may be unsuitable to use current locale for * printing time, because all names will be printed in your native language, * as well as time format settings also may be ajusted differently from the * C/POSIX defaults. To solve these problems this option was introdiced. * * @return Number of characters printed. */#ifndef WIN32CE /* XXX - mloskot - strftime is not available yet. */int CPLPrintTime( char *pszBuffer, int nMaxLen, const char *pszFormat,                  const struct tm *poBrokenTime, char *pszLocale ){    char    *pszTemp = (char *)CPLMalloc( (nMaxLen + 1) * sizeof(char) );    int     nChars;#if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)    char        *pszCurLocale = NULL;    if ( pszLocale || EQUAL( pszLocale, "" ) )    {        // Save the current locale        pszCurLocale = setlocale(LC_ALL, NULL );        // Set locale to the specified value        setlocale( LC_ALL, pszLocale );    }#endif        if ( !strftime( pszTemp, nMaxLen + 1, pszFormat, poBrokenTime ) )        memset( pszTemp, 0, nMaxLen + 1);#if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)    // Restore stored locale back    if ( pszCurLocale )        setlocale( LC_ALL, pszCurLocale );#endif    nChars = CPLPrintString( pszBuffer, pszTemp, nMaxLen );    CPLFree( pszTemp );    return nChars;}#endif/************************************************************************//*                       CPLVerifyConfiguration()                       *//************************************************************************/void CPLVerifyConfiguration(){/* -------------------------------------------------------------------- *//*      Verify data types.                                              *//* -------------------------------------------------------------------- */    CPLAssert( sizeof(GInt32) == 4 );    CPLAssert( sizeof(GInt16) == 2 );    CPLAssert( sizeof(GByte) == 1 );    if( sizeof(GInt32) != 4 )        CPLError( CE_Fatal, CPLE_AppDefined,                   "sizeof(GInt32) == %d ... yow!\n",                   sizeof(GInt32) );/* -------------------------------------------------------------------- *//*      Verify byte order                                               *//* -------------------------------------------------------------------- */    GInt32   nTest;    nTest = 1;#ifdef CPL_LSB    if( ((GByte *) &nTest)[0] != 1 )#endif#ifdef CPL_MSB    if( ((GByte *) &nTest)[3] != 1 )#endif            CPLError( CE_Fatal, CPLE_AppDefined,                   "CPLVerifyConfiguration(): byte order set wrong.\n" );}/************************************************************************//*                         CPLGetConfigOption()                         *//************************************************************************/const char * CPL_STDCALLCPLGetConfigOption( const char *pszKey, const char *pszDefault ){    const char *pszResult = NULL;    {        CPLMutexHolderD( &hConfigMutex );        pszResult = CSLFetchNameValue( (char **) papszConfigOptions, pszKey );    }#if !defined(WIN32CE)     if( pszResult == NULL )        pszResult = getenv( pszKey );#endif        if( pszResult == NULL )        return pszDefault;    else        return pszResult;}/************************************************************************//*                         CPLSetConfigOption()                         *//************************************************************************/void CPL_STDCALL CPLSetConfigOption( const char *pszKey, const char *pszValue ){    CPLMutexHolderD( &hConfigMutex );    papszConfigOptions = (volatile char **)         CSLSetNameValue( (char **) papszConfigOptions, pszKey, pszValue );}/************************************************************************//*                           CPLFreeConfig()                            *//************************************************************************/void CPL_STDCALL CPLFreeConfig(){    CPLMutexHolderD( &hConfigMutex );    CSLDestroy( (char **) papszConfigOptions);    papszConfigOptions = NULL;}/************************************************************************//*                              CPLStat()                               *//*                                                                      *//*      Same as VSIStat() except it works on "C:" as if it were         *//*      "C:\".                                                          *//************************************************************************/int CPLStat( const char *pszPath, VSIStatBuf *psStatBuf ){    if( strlen(pszPath) == 2 && pszPath[1] == ':' )    {        char    szAltPath[10];                strncpy( szAltPath, pszPath, 10 );        strcat( szAltPath, "\\" );        return VSIStat( szAltPath, psStatBuf );    }

⌨️ 快捷键说明

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