cpl_conv.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: cpl_conv.h 33666 2016-03-07 05:21:07Z goatbar $
00003  *
00004  * Project:  CPL - Common Portability Library
00005  * Purpose:  Convenience functions declarations.
00006  *           This is intended to remain light weight.
00007  * Author:   Frank Warmerdam, warmerdam@pobox.com
00008  *
00009  ******************************************************************************
00010  * Copyright (c) 1998, Frank Warmerdam
00011  * Copyright (c) 2007-2013, Even Rouault <even dot rouault at mines-paris dot org>
00012  *
00013  * Permission is hereby granted, free of charge, to any person obtaining a
00014  * copy of this software and associated documentation files (the "Software"),
00015  * to deal in the Software without restriction, including without limitation
00016  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00017  * and/or sell copies of the Software, and to permit persons to whom the
00018  * Software is furnished to do so, subject to the following conditions:
00019  *
00020  * The above copyright notice and this permission notice shall be included
00021  * in all copies or substantial portions of the Software.
00022  *
00023  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00024  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00025  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00026  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00027  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00028  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00029  * DEALINGS IN THE SOFTWARE.
00030  ****************************************************************************/
00031 
00032 #ifndef CPL_CONV_H_INCLUDED
00033 #define CPL_CONV_H_INCLUDED
00034 
00035 #include "cpl_port.h"
00036 #include "cpl_vsi.h"
00037 #include "cpl_error.h"
00038 
00046 /* -------------------------------------------------------------------- */
00047 /*      Runtime check of various configuration items.                   */
00048 /* -------------------------------------------------------------------- */
00049 CPL_C_START
00050 
00051 void CPL_DLL CPLVerifyConfiguration(void);
00052 
00053 const char CPL_DLL * CPL_STDCALL
00054 CPLGetConfigOption( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
00055 const char CPL_DLL * CPL_STDCALL
00056 CPLGetThreadLocalConfigOption( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
00057 void CPL_DLL CPL_STDCALL CPLSetConfigOption( const char *, const char * );
00058 void CPL_DLL CPL_STDCALL CPLSetThreadLocalConfigOption( const char *pszKey,
00059                                                         const char *pszValue );
00060 void CPL_DLL CPL_STDCALL CPLFreeConfig(void);
00061 
00062 /* -------------------------------------------------------------------- */
00063 /*      Safe malloc() API.  Thin cover over VSI functions with fatal    */
00064 /*      error reporting if memory allocation fails.                     */
00065 /* -------------------------------------------------------------------- */
00066 void CPL_DLL *CPLMalloc( size_t ) CPL_WARN_UNUSED_RESULT;
00067 void CPL_DLL *CPLCalloc( size_t, size_t ) CPL_WARN_UNUSED_RESULT;
00068 void CPL_DLL *CPLRealloc( void *, size_t ) CPL_WARN_UNUSED_RESULT;
00069 char CPL_DLL *CPLStrdup( const char * ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00070 char CPL_DLL *CPLStrlwr( char *);
00071 
00072 #define CPLFree VSIFree
00073 
00074 /* -------------------------------------------------------------------- */
00075 /*      Read a line from a text file, and strip of CR/LF.               */
00076 /* -------------------------------------------------------------------- */
00077 char CPL_DLL *CPLFGets( char *, int, FILE *);
00078 const char CPL_DLL *CPLReadLine( FILE * );
00079 const char CPL_DLL *CPLReadLineL( VSILFILE * );
00080 const char CPL_DLL *CPLReadLine2L( VSILFILE * , int nMaxCols, char** papszOptions);
00081 
00082 /* -------------------------------------------------------------------- */
00083 /*      Convert ASCII string to floating point number                  */
00084 /*      (THESE FUNCTIONS ARE NOT LOCALE AWARE!).                        */
00085 /* -------------------------------------------------------------------- */
00086 double CPL_DLL CPLAtof(const char *);
00087 double CPL_DLL CPLAtofDelim(const char *, char);
00088 double CPL_DLL CPLStrtod(const char *, char **);
00089 double CPL_DLL CPLStrtodDelim(const char *, char **, char);
00090 float CPL_DLL CPLStrtof(const char *, char **);
00091 float CPL_DLL CPLStrtofDelim(const char *, char **, char);
00092 
00093 /* -------------------------------------------------------------------- */
00094 /*      Convert number to string.  This function is locale agnostic     */
00095 /*      (i.e. it will support "," or "." regardless of current locale)  */
00096 /* -------------------------------------------------------------------- */
00097 double CPL_DLL CPLAtofM(const char *);
00098 
00099 /* -------------------------------------------------------------------- */
00100 /*      Read a numeric value from an ASCII character string.            */
00101 /* -------------------------------------------------------------------- */
00102 char CPL_DLL *CPLScanString( const char *, int, int, int );
00103 double CPL_DLL CPLScanDouble( const char *, int );
00104 long CPL_DLL CPLScanLong( const char *, int );
00105 unsigned long CPL_DLL CPLScanULong( const char *, int );
00106 GUIntBig CPL_DLL CPLScanUIntBig( const char *, int );
00107 GIntBig CPL_DLL CPLAtoGIntBig( const char* pszString );
00108 GIntBig CPL_DLL CPLAtoGIntBigEx( const char* pszString, int bWarn, int *pbOverflow );
00109 void CPL_DLL *CPLScanPointer( const char *, int );
00110 
00111 /* -------------------------------------------------------------------- */
00112 /*      Print a value to an ASCII character string.                     */
00113 /* -------------------------------------------------------------------- */
00114 int CPL_DLL CPLPrintString( char *, const char *, int );
00115 int CPL_DLL CPLPrintStringFill( char *, const char *, int );
00116 int CPL_DLL CPLPrintInt32( char *, GInt32 , int );
00117 int CPL_DLL CPLPrintUIntBig( char *, GUIntBig , int );
00118 int CPL_DLL CPLPrintDouble( char *, const char *, double, const char * );
00119 int CPL_DLL CPLPrintTime( char *, int , const char *, const struct tm *,
00120                           const char * );
00121 int CPL_DLL CPLPrintPointer( char *, void *, int );
00122 
00123 /* -------------------------------------------------------------------- */
00124 /*      Fetch a function from DLL / so.                                 */
00125 /* -------------------------------------------------------------------- */
00126 
00127 void CPL_DLL *CPLGetSymbol( const char *, const char * );
00128 
00129 /* -------------------------------------------------------------------- */
00130 /*      Fetch executable path.                                          */
00131 /* -------------------------------------------------------------------- */
00132 int CPL_DLL CPLGetExecPath( char *pszPathBuf, int nMaxLength );
00133 
00134 /* -------------------------------------------------------------------- */
00135 /*      Filename handling functions.                                    */
00136 /* -------------------------------------------------------------------- */
00137 const char CPL_DLL *CPLGetPath( const char * ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00138 const char CPL_DLL *CPLGetDirname( const char * ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00139 const char CPL_DLL *CPLGetFilename( const char * ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00140 const char CPL_DLL *CPLGetBasename( const char * ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00141 const char CPL_DLL *CPLGetExtension( const char * ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00142 char       CPL_DLL *CPLGetCurrentDir(void);
00143 const char CPL_DLL *CPLFormFilename( const char *pszPath,
00144                                      const char *pszBasename,
00145                                      const char *pszExtension ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00146 const char CPL_DLL *CPLFormCIFilename( const char *pszPath,
00147                                        const char *pszBasename,
00148                                        const char *pszExtension ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00149 const char CPL_DLL *CPLResetExtension( const char *, const char * ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00150 const char CPL_DLL *CPLProjectRelativeFilename( const char *pszProjectDir,
00151                                             const char *pszSecondaryFilename ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00152 int CPL_DLL CPLIsFilenameRelative( const char *pszFilename );
00153 const char CPL_DLL *CPLExtractRelativePath(const char *, const char *, int *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00154 const char CPL_DLL *CPLCleanTrailingSlash( const char * ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00155 char CPL_DLL      **CPLCorrespondingPaths( const char *pszOldFilename,
00156                                            const char *pszNewFilename,
00157                                            char **papszFileList ) CPL_WARN_UNUSED_RESULT;
00158 int CPL_DLL CPLCheckForFile( char *pszFilename, char **papszSiblingList );
00159 
00160 const char CPL_DLL *CPLGenerateTempFilename( const char *pszStem ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00161 
00162 /* -------------------------------------------------------------------- */
00163 /*      Find File Function                                              */
00164 /* -------------------------------------------------------------------- */
00165 typedef const char *(*CPLFileFinder)(const char *, const char *);
00166 
00167 const char    CPL_DLL *CPLFindFile(const char *pszClass,
00168                                    const char *pszBasename);
00169 const char    CPL_DLL *CPLDefaultFindFile(const char *pszClass,
00170                                           const char *pszBasename);
00171 void          CPL_DLL CPLPushFileFinder( CPLFileFinder pfnFinder );
00172 CPLFileFinder CPL_DLL CPLPopFileFinder(void);
00173 void          CPL_DLL CPLPushFinderLocation( const char * );
00174 void          CPL_DLL CPLPopFinderLocation(void);
00175 void          CPL_DLL CPLFinderClean(void);
00176 
00177 /* -------------------------------------------------------------------- */
00178 /*      Safe version of stat() that works properly on stuff like "C:".  */
00179 /* -------------------------------------------------------------------- */
00180 int CPL_DLL     CPLStat( const char *, VSIStatBuf * ) CPL_WARN_UNUSED_RESULT;
00181 
00182 /* -------------------------------------------------------------------- */
00183 /*      Reference counted file handle manager.  Makes sharing file      */
00184 /*      handles more practical.                                         */
00185 /* -------------------------------------------------------------------- */
00186 typedef struct {
00187     FILE *fp;
00188     int   nRefCount;
00189     int   bLarge;
00190     char  *pszFilename;
00191     char  *pszAccess;
00192 } CPLSharedFileInfo;
00193 
00194 FILE CPL_DLL    *CPLOpenShared( const char *, const char *, int );
00195 void CPL_DLL     CPLCloseShared( FILE * );
00196 CPLSharedFileInfo CPL_DLL *CPLGetSharedList( int * );
00197 void CPL_DLL     CPLDumpSharedList( FILE * );
00198 void CPL_DLL     CPLCleanupSharedFileMutex( void );
00199 
00200 /* -------------------------------------------------------------------- */
00201 /*      DMS to Dec to DMS conversion.                                   */
00202 /* -------------------------------------------------------------------- */
00203 double CPL_DLL CPLDMSToDec( const char *is );
00204 const char CPL_DLL *CPLDecToDMS( double dfAngle, const char * pszAxis,
00205                                  int nPrecision );
00206 double CPL_DLL CPLPackedDMSToDec( double );
00207 double CPL_DLL CPLDecToPackedDMS( double dfDec );
00208 
00209 void CPL_DLL CPLStringToComplex( const char *pszString,
00210                                  double *pdfReal, double *pdfImag );
00211 
00212 /* -------------------------------------------------------------------- */
00213 /*      Misc other functions.                                           */
00214 /* -------------------------------------------------------------------- */
00215 int CPL_DLL CPLUnlinkTree( const char * );
00216 int CPL_DLL CPLCopyFile( const char *pszNewPath, const char *pszOldPath );
00217 int CPL_DLL CPLCopyTree( const char *pszNewPath, const char *pszOldPath );
00218 int CPL_DLL CPLMoveFile( const char *pszNewPath, const char *pszOldPath );
00219 int CPL_DLL CPLSymlink( const char* pszOldPath, const char* pszNewPath, char** papszOptions );
00220 
00221 /* -------------------------------------------------------------------- */
00222 /*      ZIP Creation.                                                   */
00223 /* -------------------------------------------------------------------- */
00224 #define CPL_ZIP_API_OFFERED
00225 void CPL_DLL  *CPLCreateZip( const char *pszZipFilename, char **papszOptions );
00226 CPLErr CPL_DLL CPLCreateFileInZip( void *hZip, const char *pszFilename,
00227                                    char **papszOptions );
00228 CPLErr CPL_DLL CPLWriteFileInZip( void *hZip, const void *pBuffer, int nBufferSize );
00229 CPLErr CPL_DLL CPLCloseFileInZip( void *hZip );
00230 CPLErr CPL_DLL CPLCloseZip( void *hZip );
00231 
00232 /* -------------------------------------------------------------------- */
00233 /*      ZLib compression                                                */
00234 /* -------------------------------------------------------------------- */
00235 
00236 void CPL_DLL *CPLZLibDeflate( const void* ptr, size_t nBytes, int nLevel,
00237                               void* outptr, size_t nOutAvailableBytes,
00238                               size_t* pnOutBytes );
00239 void CPL_DLL *CPLZLibInflate( const void* ptr, size_t nBytes,
00240                               void* outptr, size_t nOutAvailableBytes,
00241                               size_t* pnOutBytes );
00242 
00243 /* -------------------------------------------------------------------- */
00244 /*      XML validation.                                                 */
00245 /* -------------------------------------------------------------------- */
00246 int CPL_DLL CPLValidateXML(const char* pszXMLFilename,
00247                            const char* pszXSDFilename,
00248                            char** papszOptions);
00249 
00250 /* -------------------------------------------------------------------- */
00251 /*      Locale handling. Prevents parallel executions of setlocale().   */
00252 /* -------------------------------------------------------------------- */
00253 char* CPLsetlocale (int category, const char* locale);
00254 void CPLCleanupSetlocaleMutex(void);
00255 
00256 CPL_C_END
00257 
00258 /* -------------------------------------------------------------------- */
00259 /*      C++ object for temporarily forcing a LC_NUMERIC locale to "C".  */
00260 /* -------------------------------------------------------------------- */
00261 
00262 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
00263 
00264 class CPL_DLL CPLLocaleC
00265 {
00266 public:
00267     CPLLocaleC();
00268     ~CPLLocaleC();
00269 
00270 private:
00271     char *pszOldLocale;
00272 
00273     /* Make it non-copyable */
00274     CPLLocaleC(const CPLLocaleC&);
00275     CPLLocaleC& operator=(const CPLLocaleC&);
00276 };
00277 
00278 // Does the same as CPLLocaleC except that, when available, it tries to
00279 // only affect the current thread. But code that would be dependent of
00280 // setlocale(LC_NUMERIC, NULL) returning "C", such as current proj.4 versions,
00281 // will not work depending on the actual implementation
00282 class CPL_DLL CPLThreadLocaleC
00283 {
00284 public:
00285     CPLThreadLocaleC();
00286     ~CPLThreadLocaleC();
00287 
00288 private:
00289 #ifdef HAVE_USELOCALE
00290     locale_t nNewLocale;
00291     locale_t nOldLocale;
00292 #else
00293 #if defined(_MSC_VER)
00294     int   nOldValConfigThreadLocale;
00295 #endif
00296     char *pszOldLocale;
00297 #endif
00298 
00299     /* Make it non-copyable */
00300     CPLThreadLocaleC(const CPLThreadLocaleC&);
00301     CPLThreadLocaleC& operator=(const CPLThreadLocaleC&);
00302 };
00303 
00304 #endif /* def __cplusplus */
00305 
00306 
00307 #endif /* ndef CPL_CONV_H_INCLUDED */

Generated for GDAL by doxygen 1.6.1.