GDAL
cpl_conv.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: cpl_conv.h 37866 2017-03-30 20:16:05Z rouault $
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 
00052 void CPL_DLL CPLVerifyConfiguration(void);
00055 const char CPL_DLL * CPL_STDCALL
00056 CPLGetConfigOption( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
00057 const char CPL_DLL * CPL_STDCALL
00058 CPLGetThreadLocalConfigOption( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
00059 void CPL_DLL CPL_STDCALL CPLSetConfigOption( const char *, const char * );
00060 void CPL_DLL CPL_STDCALL CPLSetThreadLocalConfigOption( const char *pszKey,
00061                                                         const char *pszValue );
00063 void CPL_DLL CPL_STDCALL CPLFreeConfig(void);
00065 char CPL_DLL** CPLGetConfigOptions(void);
00066 void CPL_DLL   CPLSetConfigOptions(const char* const * papszConfigOptions);
00067 char CPL_DLL** CPLGetThreadLocalConfigOptions(void);
00068 void CPL_DLL   CPLSetThreadLocalConfigOptions(const char* const * papszConfigOptions);
00069 
00070 /* -------------------------------------------------------------------- */
00071 /*      Safe malloc() API.  Thin cover over VSI functions with fatal    */
00072 /*      error reporting if memory allocation fails.                     */
00073 /* -------------------------------------------------------------------- */
00074 void CPL_DLL *CPLMalloc( size_t ) CPL_WARN_UNUSED_RESULT;
00075 void CPL_DLL *CPLCalloc( size_t, size_t ) CPL_WARN_UNUSED_RESULT;
00076 void CPL_DLL *CPLRealloc( void *, size_t ) CPL_WARN_UNUSED_RESULT;
00077 char CPL_DLL *CPLStrdup( const char * ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00078 char CPL_DLL *CPLStrlwr( char *);
00079 
00081 #define CPLFree VSIFree
00082 
00083 /* -------------------------------------------------------------------- */
00084 /*      Read a line from a text file, and strip of CR/LF.               */
00085 /* -------------------------------------------------------------------- */
00086 char CPL_DLL *CPLFGets( char *, int, FILE *);
00087 const char CPL_DLL *CPLReadLine( FILE * );
00088 const char CPL_DLL *CPLReadLineL( VSILFILE * );
00089 #ifdef __cplusplus
00090 const char CPL_DLL *CPLReadLine2L( VSILFILE * , int nMaxCols,
00091                                    const char * const * papszOptions );
00092 #else
00093 const char CPL_DLL *CPLReadLine2L( VSILFILE * , int nMaxCols,
00094                                    char** papszOptions );
00095 #endif
00096 
00097 /* -------------------------------------------------------------------- */
00098 /*      Convert ASCII string to floating point number                  */
00099 /*      (THESE FUNCTIONS ARE NOT LOCALE AWARE!).                        */
00100 /* -------------------------------------------------------------------- */
00101 double CPL_DLL CPLAtof(const char *);
00102 double CPL_DLL CPLAtofDelim(const char *, char);
00103 double CPL_DLL CPLStrtod(const char *, char **);
00104 double CPL_DLL CPLStrtodDelim(const char *, char **, char);
00105 float CPL_DLL CPLStrtof(const char *, char **);
00106 float CPL_DLL CPLStrtofDelim(const char *, char **, char);
00107 
00108 /* -------------------------------------------------------------------- */
00109 /*      Convert number to string.  This function is locale agnostic     */
00110 /*      (i.e. it will support "," or "." regardless of current locale)  */
00111 /* -------------------------------------------------------------------- */
00112 double CPL_DLL CPLAtofM(const char *);
00113 
00114 /* -------------------------------------------------------------------- */
00115 /*      Read a numeric value from an ASCII character string.            */
00116 /* -------------------------------------------------------------------- */
00117 char CPL_DLL *CPLScanString( const char *, int, int, int );
00118 double CPL_DLL CPLScanDouble( const char *, int );
00119 long CPL_DLL CPLScanLong( const char *, int );
00120 unsigned long CPL_DLL CPLScanULong( const char *, int );
00121 GUIntBig CPL_DLL CPLScanUIntBig( const char *, int );
00122 GIntBig CPL_DLL CPLAtoGIntBig( const char* pszString );
00123 GIntBig CPL_DLL CPLAtoGIntBigEx( const char* pszString, int bWarn, int *pbOverflow );
00124 void CPL_DLL *CPLScanPointer( const char *, int );
00125 
00126 /* -------------------------------------------------------------------- */
00127 /*      Print a value to an ASCII character string.                     */
00128 /* -------------------------------------------------------------------- */
00129 int CPL_DLL CPLPrintString( char *, const char *, int );
00130 int CPL_DLL CPLPrintStringFill( char *, const char *, int );
00131 int CPL_DLL CPLPrintInt32( char *, GInt32 , int );
00132 int CPL_DLL CPLPrintUIntBig( char *, GUIntBig , int );
00133 int CPL_DLL CPLPrintDouble( char *, const char *, double, const char * );
00134 int CPL_DLL CPLPrintTime( char *, int , const char *, const struct tm *,
00135                           const char * );
00136 int CPL_DLL CPLPrintPointer( char *, void *, int );
00137 
00138 /* -------------------------------------------------------------------- */
00139 /*      Fetch a function from DLL / so.                                 */
00140 /* -------------------------------------------------------------------- */
00141 
00142 void CPL_DLL *CPLGetSymbol( const char *, const char * );
00143 
00144 /* -------------------------------------------------------------------- */
00145 /*      Fetch executable path.                                          */
00146 /* -------------------------------------------------------------------- */
00147 int CPL_DLL CPLGetExecPath( char *pszPathBuf, int nMaxLength );
00148 
00149 /* -------------------------------------------------------------------- */
00150 /*      Filename handling functions.                                    */
00151 /* -------------------------------------------------------------------- */
00152 const char CPL_DLL *CPLGetPath( const char * ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00153 const char CPL_DLL *CPLGetDirname( const char * ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00154 const char CPL_DLL *CPLGetFilename( const char * ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00155 const char CPL_DLL *CPLGetBasename( const char * ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00156 const char CPL_DLL *CPLGetExtension( const char * ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00157 char       CPL_DLL *CPLGetCurrentDir(void);
00158 const char CPL_DLL *CPLFormFilename( const char *pszPath,
00159                                      const char *pszBasename,
00160                                      const char *pszExtension ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00161 const char CPL_DLL *CPLFormCIFilename( const char *pszPath,
00162                                        const char *pszBasename,
00163                                        const char *pszExtension ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00164 const char CPL_DLL *CPLResetExtension( const char *, const char * ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00165 const char CPL_DLL *CPLProjectRelativeFilename( const char *pszProjectDir,
00166                                             const char *pszSecondaryFilename ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00167 int CPL_DLL CPLIsFilenameRelative( const char *pszFilename );
00168 const char CPL_DLL *CPLExtractRelativePath(const char *, const char *, int *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00169 const char CPL_DLL *CPLCleanTrailingSlash( const char * ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00170 char CPL_DLL      **CPLCorrespondingPaths( const char *pszOldFilename,
00171                                            const char *pszNewFilename,
00172                                            char **papszFileList ) CPL_WARN_UNUSED_RESULT;
00173 int CPL_DLL CPLCheckForFile( char *pszFilename, char **papszSiblingList );
00174 
00175 const char CPL_DLL *CPLGenerateTempFilename( const char *pszStem ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00176 const char CPL_DLL *CPLExpandTilde( const char *pszFilename ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
00177 
00178 /* -------------------------------------------------------------------- */
00179 /*      Find File Function                                              */
00180 /* -------------------------------------------------------------------- */
00181 
00183 typedef const char *(*CPLFileFinder)(const char *, const char *);
00184 
00185 const char    CPL_DLL *CPLFindFile(const char *pszClass,
00186                                    const char *pszBasename);
00187 const char    CPL_DLL *CPLDefaultFindFile(const char *pszClass,
00188                                           const char *pszBasename);
00189 void          CPL_DLL CPLPushFileFinder( CPLFileFinder pfnFinder );
00190 CPLFileFinder CPL_DLL CPLPopFileFinder(void);
00191 void          CPL_DLL CPLPushFinderLocation( const char * );
00192 void          CPL_DLL CPLPopFinderLocation(void);
00193 void          CPL_DLL CPLFinderClean(void);
00194 
00195 /* -------------------------------------------------------------------- */
00196 /*      Safe version of stat() that works properly on stuff like "C:".  */
00197 /* -------------------------------------------------------------------- */
00198 int CPL_DLL     CPLStat( const char *, VSIStatBuf * ) CPL_WARN_UNUSED_RESULT;
00199 
00200 /* -------------------------------------------------------------------- */
00201 /*      Reference counted file handle manager.  Makes sharing file      */
00202 /*      handles more practical.                                         */
00203 /* -------------------------------------------------------------------- */
00204 
00206 typedef struct {
00207     FILE *fp;               
00208     int   nRefCount;        
00209     int   bLarge;           
00210     char  *pszFilename;     
00211     char  *pszAccess;       
00212 } CPLSharedFileInfo;
00213 
00214 FILE CPL_DLL    *CPLOpenShared( const char *, const char *, int );
00215 void CPL_DLL     CPLCloseShared( FILE * );
00216 CPLSharedFileInfo CPL_DLL *CPLGetSharedList( int * );
00217 void CPL_DLL     CPLDumpSharedList( FILE * );
00219 void CPL_DLL     CPLCleanupSharedFileMutex( void );
00222 /* -------------------------------------------------------------------- */
00223 /*      DMS to Dec to DMS conversion.                                   */
00224 /* -------------------------------------------------------------------- */
00225 double CPL_DLL CPLDMSToDec( const char *is );
00226 const char CPL_DLL *CPLDecToDMS( double dfAngle, const char * pszAxis,
00227                                  int nPrecision );
00228 double CPL_DLL CPLPackedDMSToDec( double );
00229 double CPL_DLL CPLDecToPackedDMS( double dfDec );
00230 
00231 void CPL_DLL CPLStringToComplex( const char *pszString,
00232                                  double *pdfReal, double *pdfImag );
00233 
00234 /* -------------------------------------------------------------------- */
00235 /*      Misc other functions.                                           */
00236 /* -------------------------------------------------------------------- */
00237 int CPL_DLL CPLUnlinkTree( const char * );
00238 int CPL_DLL CPLCopyFile( const char *pszNewPath, const char *pszOldPath );
00239 int CPL_DLL CPLCopyTree( const char *pszNewPath, const char *pszOldPath );
00240 int CPL_DLL CPLMoveFile( const char *pszNewPath, const char *pszOldPath );
00241 int CPL_DLL CPLSymlink( const char* pszOldPath, const char* pszNewPath, char** papszOptions );
00242 
00243 /* -------------------------------------------------------------------- */
00244 /*      ZIP Creation.                                                   */
00245 /* -------------------------------------------------------------------- */
00246 
00248 #define CPL_ZIP_API_OFFERED
00249 
00250 void CPL_DLL  *CPLCreateZip( const char *pszZipFilename, char **papszOptions );
00251 CPLErr CPL_DLL CPLCreateFileInZip( void *hZip, const char *pszFilename,
00252                                    char **papszOptions );
00253 CPLErr CPL_DLL CPLWriteFileInZip( void *hZip, const void *pBuffer, int nBufferSize );
00254 CPLErr CPL_DLL CPLCloseFileInZip( void *hZip );
00255 CPLErr CPL_DLL CPLCloseZip( void *hZip );
00256 
00257 /* -------------------------------------------------------------------- */
00258 /*      ZLib compression                                                */
00259 /* -------------------------------------------------------------------- */
00260 
00261 void CPL_DLL *CPLZLibDeflate( const void* ptr, size_t nBytes, int nLevel,
00262                               void* outptr, size_t nOutAvailableBytes,
00263                               size_t* pnOutBytes );
00264 void CPL_DLL *CPLZLibInflate( const void* ptr, size_t nBytes,
00265                               void* outptr, size_t nOutAvailableBytes,
00266                               size_t* pnOutBytes );
00267 
00268 /* -------------------------------------------------------------------- */
00269 /*      XML validation.                                                 */
00270 /* -------------------------------------------------------------------- */
00271 int CPL_DLL CPLValidateXML(const char* pszXMLFilename,
00272                            const char* pszXSDFilename,
00273                            char** papszOptions);
00274 
00275 /* -------------------------------------------------------------------- */
00276 /*      Locale handling. Prevents parallel executions of setlocale().   */
00277 /* -------------------------------------------------------------------- */
00278 char* CPLsetlocale (int category, const char* locale);
00280 void CPLCleanupSetlocaleMutex(void);
00283 CPL_C_END
00284 
00285 /* -------------------------------------------------------------------- */
00286 /*      C++ object for temporarily forcing a LC_NUMERIC locale to "C".  */
00287 /* -------------------------------------------------------------------- */
00288 
00290 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
00291 
00292 class CPL_DLL CPLLocaleC
00293 {
00294 public:
00295     CPLLocaleC();
00296     ~CPLLocaleC();
00297 
00298 private:
00299     char *pszOldLocale;
00300 
00301     /* Make it non-copyable */
00302     CPLLocaleC(const CPLLocaleC&);
00303     CPLLocaleC& operator=(const CPLLocaleC&);
00304 };
00305 
00306 // Does the same as CPLLocaleC except that, when available, it tries to
00307 // only affect the current thread. But code that would be dependent of
00308 // setlocale(LC_NUMERIC, NULL) returning "C", such as current proj.4 versions,
00309 // will not work depending on the actual implementation
00310 class CPL_DLL CPLThreadLocaleC
00311 {
00312 public:
00313     CPLThreadLocaleC();
00314     ~CPLThreadLocaleC();
00315 
00316 private:
00317 #ifdef HAVE_USELOCALE
00318     locale_t nNewLocale;
00319     locale_t nOldLocale;
00320 #else
00321 #if defined(_MSC_VER)
00322     int   nOldValConfigThreadLocale;
00323 #endif
00324     char *pszOldLocale;
00325 #endif
00326 
00327     /* Make it non-copyable */
00328     CPLThreadLocaleC(const CPLThreadLocaleC&);
00329     CPLThreadLocaleC& operator=(const CPLThreadLocaleC&);
00330 };
00331 
00332 #endif /* def __cplusplus */
00333 
00334 
00335 #endif /* ndef CPL_CONV_H_INCLUDED */

Generated for GDAL by doxygen 1.7.6.1.