- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

# cpl_serv.h

    00001 /******************************************************************************
    00002  * Copyright (c) 1998, Frank Warmerdam
    00003  *
    00004  * Permission is hereby granted, free of charge, to any person obtaining a
    00005  * copy of this software and associated documentation files (the "Software"),
    00006  * to deal in the Software without restriction, including without limitation
    00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    00008  * and/or sell copies of the Software, and to permit persons to whom the
    00009  * Software is furnished to do so, subject to the following conditions:
    00010  *
    00011  * The above copyright notice and this permission notice shall be included
    00012  * in all copies or substantial portions of the Software.
    00013  *
    00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    00017  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00018  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    00019  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    00020  * DEALINGS IN THE SOFTWARE.
    00021  ******************************************************************************
    00022  *
    00023  * cpl_serv.h
    00024  *
    00025  * This include file derived and simplified from the GDAL Common Portability
    00026  * Library.
    00027  */
    00028
    00029 #ifndef CPL_SERV_H_INCLUDED
    00030 #define CPL_SERV_H_INCLUDED
    00031
    00032 /* ==================================================================== */
    00033 /*      Standard include files.                                         */
    00034 /* ==================================================================== */
    00035
    00036 #include "geo_config.h"
    00037 #include <stdio.h>
    00038
    00039 #include <math.h>
    00040
    00041 #ifdef HAVE_STRING_H
    00042 #  include <string.h>
    00043 #endif
    00044 #if defined(HAVE_STRINGS_H) && !defined(HAVE_STRING_H)
    00045 #  include <strings.h>
    00046 #endif
    00047 #ifdef HAVE_STDLIB_H
    00048 #  include <stdlib.h>
    00049 #endif
    00050
    00051 /**********************************************************************
    00052  * Do we want to build as a DLL on windows?
    00053  **********************************************************************/
    00054 #if !defined(CPL_DLL)
    00055 #  if defined(_WIN32) && defined(BUILD_AS_DLL)
    00056 #    define CPL_DLL     __declspec(dllexport)
    00057 #  else
    00058 #    define CPL_DLL
    00059 #  endif
    00060 #endif
    00061
    00062 /* ==================================================================== */
    00063 /*      Other standard services.                                        */
    00064 /* ==================================================================== */
    00065 #ifdef __cplusplus
    00066 #  define CPL_C_START           extern "C" {
    00067 #  define CPL_C_END             }
    00068 #else
    00069 #  define CPL_C_START
    00070 #  define CPL_C_END
    00071 #endif
    00072
    00073 #ifndef NULL
    00074 #  define NULL  0
    00075 #endif
    00076
    00077 #ifndef FALSE
    00078 #  define FALSE 0
    00079 #endif
    00080
    00081 #ifndef TRUE
    00082 #  define TRUE  1
    00083 #endif
    00084
    00085 #ifndef MAX
    00086 #  define MIN(a,b)      ((a<b) ? a : b)
    00087 #  define MAX(a,b)      ((a>b) ? a : b)
    00088 #endif
    00089
    00090 #ifndef NULL
    00091 #define NULL 0
    00092 #endif
    00093
    00094 #ifndef ABS
    00095 #  define ABS(x)        ((x<0) ? (-1*(x)) : x)
    00096 #endif
    00097
    00098 #ifndef EQUAL
    00099 #if defined(_WIN32) && !defined(__CYGWIN__)
    00100 #   if     (_MSC_FULL_VER >= 15000000)
    00101 #       define EQUALN(a,b,n)           (_strnicmp(a,b,n)==0)
    00102 #       define EQUAL(a,b)              (_stricmp(a,b)==0)
    00103 #   else
    00104 #       define EQUALN(a,b,n)           (strnicmp(a,b,n)==0)
    00105 #       define EQUAL(a,b)              (stricmp(a,b)==0)
    00106 #   endif
    00107 #else
    00108 #  define EQUALN(a,b,n)           (strncasecmp(a,b,n)==0)
    00109 #  define EQUAL(a,b)              (strcasecmp(a,b)==0)
    00110 #endif
    00111 #endif
    00112
    00113 /* ==================================================================== */
    00114 /*      VSI Services (just map directly onto Standard C services.       */
    00115 /* ==================================================================== */
    00116
    00117 #define VSIFOpen        fopen
    00118 #define VSIFClose       fclose
    00119 #define VSIFEof         feof
    00120 #define VSIFPrintf      fprintf
    00121 #define VSIFPuts        fputs
    00122 #define VSIFPutc        fputc
    00123 #define VSIFGets        fgets
    00124 #define VSIRewind       rewind
    00125 #define VSIFSeek        fseek
    00126 #define VSIFTell        ftell
    00127 #define VSIFRead        fread
    00128
    00129 #ifndef notdef
    00130 #define VSICalloc(x,y)  _GTIFcalloc(x*y)
    00131 #define VSIMalloc       _GTIFcalloc
    00132 #define VSIFree         _GTIFFree
    00133 #define VSIRealloc      _GTIFrealloc
    00134 #else
    00135 #define VSICalloc(x,y)  (((char *) _GTIFcalloc(x*y+4)) + 4)
    00136 #define VSIMalloc(x)    (((char *) _GTIFcalloc((x)+4)) + 4)
    00137 #define VSIFree(x)      _GTIFFree(((char *) (x)) - 4)
    00138 #define VSIRealloc(p,n) (((char *) _GTIFrealloc(((char *)p)-4,(n)+4)) + 4)
    00139 #endif
    00140
    00141
    00142 #if !defined(GTIFAtof)
    00143 #  define GTIFAtof atof
    00144 #endif
    00145
    00146
    00147 /* -------------------------------------------------------------------- */
    00148 /*      Safe malloc() API.  Thin cover over VSI functions with fatal    */
    00149 /*      error reporting if memory allocation fails.                     */
    00150 /* -------------------------------------------------------------------- */
    00151 CPL_C_START
    00152
    00153 #define CPLMalloc  gtCPLMalloc
    00154 #define CPLCalloc  gtCPLCalloc
    00155 #define CPLRealloc gtCPLRealloc
    00156 #define CPLStrdup  gtCPLStrdup
    00157
    00158 void CPL_DLL *CPLMalloc( int );
    00159 void CPL_DLL *CPLCalloc( int, int );
    00160 void CPL_DLL *CPLRealloc( void *, int );
    00161 char CPL_DLL *CPLStrdup( const char * );
    00162
    00163 #define CPLFree(x)      { if( x != NULL ) VSIFree(x); }
    00164
    00165 /* -------------------------------------------------------------------- */
    00166 /*      Locale insensitive string to float conversion.                  */
    00167 /* -------------------------------------------------------------------- */
    00168 /*double GTIFAtof(const char *nptr); */
    00169 double GTIFStrtod(const char *nptr, char **endptr);
    00170
    00171 /* -------------------------------------------------------------------- */
    00172 /*      Read a line from a text file, and strip of CR/LF.               */
    00173 /* -------------------------------------------------------------------- */
    00174
    00175 #define CPLReadLine gtCPLReadLine
    00176
    00177 const char CPL_DLL *CPLReadLine( FILE * );
    00178
    00179 /*=====================================================================
    00180                    Error handling functions (cpl_error.c)
    00181  =====================================================================*/
    00182
    00183 typedef enum
    00184 {
    00185     CE_None = 0,
    00186     CE_Log = 1,
    00187     CE_Warning = 2,
    00188     CE_Failure = 3,
    00189     CE_Fatal = 4
    00190 } CPLErr;
    00191
    00192 #define CPLError      gtCPLError
    00193 #define CPLErrorReset gtCPLErrorReset
    00194 #define CPLGetLastErrorNo gtCPLGetLastErrorNo
    00195 #define CPLGetLastErrorMsg gtCPLGetLastErrorMsg
    00196 #define CPLSetErrorHandler gtCPLSetErrorHandler
    00197 #define _CPLAssert    gt_CPLAssert
    00198
    00199 void CPL_DLL CPLError(CPLErr eErrClass, int err_no, const char *fmt, ...);
    00200 void CPL_DLL CPLErrorReset();
    00201 int  CPL_DLL CPLGetLastErrorNo();
    00202 const char CPL_DLL * CPLGetLastErrorMsg();
    00203 void CPL_DLL CPLSetErrorHandler(void(*pfnErrorHandler)(CPLErr,int,
    00204                                                        const char *));
    00205 void CPL_DLL _CPLAssert( const char *, const char *, int );
    00206
    00207 #ifdef DEBUG
    00208 #  define CPLAssert(expr)  ((expr) ? (void)(0) : _CPLAssert(#expr,__FILE__,__LINE__))
    00209 #else
    00210 #  define CPLAssert(expr)
    00211 #endif
    00212
    00213 CPL_C_END
    00214
    00215 /* ==================================================================== */
    00216 /*      Well known error codes.                                         */
    00217 /* ==================================================================== */
    00218
    00219 #define CPLE_AppDefined                 1
    00220 #define CPLE_OutOfMemory                2
    00221 #define CPLE_FileIO                     3
    00222 #define CPLE_OpenFailed                 4
    00223 #define CPLE_IllegalArg                 5
    00224 #define CPLE_NotSupported               6
    00225 #define CPLE_AssertionFailed            7
    00226 #define CPLE_NoWriteAccess              8
    00227
    00228 /*=====================================================================
    00229                    Stringlist functions (strlist.c)
    00230  =====================================================================*/
    00231 CPL_C_START
    00232
    00233 #define CSLAddString gtCSLAddString
    00234 #define CSLCount     gtCSLCount
    00235 #define CSLGetField  gtCSLGetField
    00236 #define CSLDestroy   gtCSLDestroy
    00237 #define CSLDuplicate gtCSLDuplicate
    00238 #define CSLTokenizeString gtCSLTokenizeString
    00239 #define CSLTokenizeStringComplex gtCSLTokenizeStringComplex
    00240
    00241 char CPL_DLL   **CSLAddString(char **papszStrList, const char *pszNewString);
    00242 int  CPL_DLL   CSLCount(char **papszStrList);
    00243 const char CPL_DLL *CSLGetField( char **, int );
    00244 void CPL_DLL   CSLDestroy(char **papszStrList);
    00245 char CPL_DLL   **CSLDuplicate(char **papszStrList);
    00246
    00247 char CPL_DLL   **CSLTokenizeString(const char *pszString );
    00248 char CPL_DLL   **CSLTokenizeStringComplex(const char *pszString,
    00249                                    const char *pszDelimiter,
    00250                                    int bHonourStrings, int bAllowEmptyTokens );
    00251
    00252 /* ==================================================================== */
    00253 /*      .csv file related functions (from cpl_csv.c)                    */
    00254 /* ==================================================================== */
    00255
    00256 typedef enum {
    00257     CC_ExactString,
    00258     CC_ApproxString,
    00259     CC_Integer
    00260 } CSVCompareCriteria;
    00261
    00262 #define CSVFilename gtCSVFilename
    00263 #define CSVReadParseLine gtCSVReadParseLine
    00264 #define CSVScanLines gtCSVScanLines
    00265 #define CSVScanFile gtCSVScanFile
    00266 #define CSVScanFileByName gtCSVScanFileByName
    00267 #define CSVGetFieldId gtCSVGetFieldId
    00268 #define CSVDeaccess gtCSVDeaccess
    00269 #define CSVGetField gtCSVGetField
    00270 #define SetCSVFilenameHook gtSetCSVFilenameHook
    00271 #define CSVGetFileFieldId gtCSVGetFileFieldId
    00272
    00273 const char CPL_DLL *CSVFilename( const char * );
    00274
    00275 char CPL_DLL **CSVReadParseLine( FILE * );
    00276 char CPL_DLL **CSVScanLines( FILE *, int, const char *, CSVCompareCriteria );
    00277 char CPL_DLL **CSVScanFile( const char *, int, const char *,
    00278                             CSVCompareCriteria );
    00279 char CPL_DLL **CSVScanFileByName( const char *, const char *, const char *,
    00280                                   CSVCompareCriteria );
    00281 int CPL_DLL CSVGetFieldId( FILE *, const char * );
    00282 int CPL_DLL CSVGetFileFieldId( const char *, const char * );
    00283
    00284 void CPL_DLL CSVDeaccess( const char * );
    00285
    00286 const char CPL_DLL *CSVGetField( const char *, const char *, const char *,
    00287                                  CSVCompareCriteria, const char * );
    00288
    00289 void CPL_DLL SetCSVFilenameHook( const char *(*)(const char *) );
    00290
    00291 CPL_C_END
    00292
    00293 #endif /* ndef CPL_SERV_H_INCLUDED */