Main Page   Compound List   File List   Compound Members   File Members   Related Pages  

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 #  define EQUALN(a,b,n)           (strnicmp(a,b,n)==0)
00101 #  define EQUAL(a,b)              (stricmp(a,b)==0)
00102 #else
00103 #  define EQUALN(a,b,n)           (strncasecmp(a,b,n)==0)
00104 #  define EQUAL(a,b)              (strcasecmp(a,b)==0)
00105 #endif
00106 #endif
00107 
00108 /* ==================================================================== */
00109 /*      VSI Services (just map directly onto Standard C services.       */
00110 /* ==================================================================== */
00111 
00112 #define VSIFOpen        fopen
00113 #define VSIFClose       fclose
00114 #define VSIFEof         feof
00115 #define VSIFPrintf      fprintf
00116 #define VSIFPuts        fputs
00117 #define VSIFPutc        fputc
00118 #define VSIFGets        fgets
00119 #define VSIRewind       rewind
00120 
00121 #define VSICalloc(x,y)  _GTIFcalloc(x*y)
00122 #define VSIMalloc       _GTIFcalloc
00123 #define VSIFree         _GTIFFree
00124 #define VSIRealloc      _GTIFrealloc
00125 
00126 /* -------------------------------------------------------------------- */
00127 /*      Safe malloc() API.  Thin cover over VSI functions with fatal    */
00128 /*      error reporting if memory allocation fails.                     */
00129 /* -------------------------------------------------------------------- */
00130 CPL_C_START
00131 void  *CPLMalloc( int );
00132 void  *CPLCalloc( int, int );
00133 void  *CPLRealloc( void *, int );
00134 char  *CPLStrdup( const char * );
00135 
00136 #define CPLFree VSIFree
00137 
00138 /* -------------------------------------------------------------------- */
00139 /*      Read a line from a text file, and strip of CR/LF.               */
00140 /* -------------------------------------------------------------------- */
00141 const char *CPLReadLine( FILE * );
00142 
00143 /*=====================================================================
00144                    Error handling functions (cpl_error.c)
00145  =====================================================================*/
00146 
00147 typedef enum
00148 {
00149     CE_None = 0,
00150     CE_Log = 1,
00151     CE_Warning = 2,
00152     CE_Failure = 3,
00153     CE_Fatal = 4
00154   
00155 } CPLErr;
00156 
00157 void  CPLError(CPLErr eErrClass, int err_no, const char *fmt, ...);
00158 void  CPLErrorReset();
00159 int  CPLGetLastErrorNo();
00160 const char  * CPLGetLastErrorMsg();
00161 void  CPLSetErrorHandler(void(*pfnErrorHandler)(CPLErr,int,
00162                                                        const char *));
00163 void  _CPLAssert( const char *, const char *, int );
00164 
00165 #ifdef DEBUG
00166 #  define CPLAssert(expr)  ((expr) ? (void)(0) : _CPLAssert(#expr,__FILE__,__LINE__))
00167 #else
00168 #  define CPLAssert(expr)
00169 #endif
00170 
00171 CPL_C_END
00172 
00173 /* ==================================================================== */
00174 /*      Well known error codes.                                         */
00175 /* ==================================================================== */
00176 
00177 #define CPLE_AppDefined                 1
00178 #define CPLE_OutOfMemory                2
00179 #define CPLE_FileIO                     3
00180 #define CPLE_OpenFailed                 4
00181 #define CPLE_IllegalArg                 5
00182 #define CPLE_NotSupported               6
00183 #define CPLE_AssertionFailed            7
00184 #define CPLE_NoWriteAccess              8
00185 
00186 /*=====================================================================
00187                    Stringlist functions (strlist.c)
00188  =====================================================================*/
00189 CPL_C_START
00190 
00191 char    **CSLAddString(char **papszStrList, const char *pszNewString);
00192 int     CSLCount(char **papszStrList);
00193 const char *CSLGetField( char **, int );
00194 void    CSLDestroy(char **papszStrList);
00195 char    **CSLDuplicate(char **papszStrList);
00196 
00197 char    **CSLTokenizeString(const char *pszString );
00198 char    **CSLTokenizeStringComplex(const char *pszString,
00199                                    const char *pszDelimiter,
00200                                    int bHonourStrings, int bAllowEmptyTokens );
00201 
00202 int     CSLPrint(char **papszStrList, FILE *fpOut);
00203 char    **CSLLoad(const char *pszFname);
00204 int     CSLSave(char **papszStrList, const char *pszFname);
00205 
00206 char  **CSLInsertStrings(char **papszStrList, int nInsertAtLineNo, 
00207                          char **papszNewLines);
00208 char  **CSLInsertString(char **papszStrList, int nInsertAtLineNo, 
00209                         char *pszNewLine);
00210 char  **CSLRemoveStrings(char **papszStrList, int nFirstLineToDelete,
00211                          int nNumToRemove, char ***ppapszRetStrings);
00212 
00213 const char *CPLSPrintf(char *fmt, ...);
00214 char  **CSLAppendPrintf(char **papszStrList, char *fmt, ...);
00215 
00216 const char *CSLFetchNameValue(char **papszStrList, const char *pszName);
00217 char  **CSLFetchNameValueMultiple(char **papszStrList, const char *pszName);
00218 char  **CSLAddNameValue(char **papszStrList, 
00219                         const char *pszName, const char *pszValue);
00220 char  **CSLSetNameValue(char **papszStrList, 
00221                         const char *pszName, const char *pszValue);
00222 
00223 CPL_C_END
00224 
00225 #endif /* ndef CPL_SERV_H_INCLUDED */

Generated at Sun Mar 4 23:32:44 2001 for libgeotiff by doxygen1.2.3-20001105 written by Dimitri van Heesch, © 1997-2000