OGR
cpl_conv.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: cpl_conv.h 27121 2014-04-03 22:08:55Z rouault $
3  *
4  * Project: CPL - Common Portability Library
5  * Purpose: Convenience functions declarations.
6  * This is intended to remain light weight.
7  * Author: Frank Warmerdam, warmerdam@pobox.com
8  *
9  ******************************************************************************
10  * Copyright (c) 1998, Frank Warmerdam
11  * Copyright (c) 2007-2013, Even Rouault <even dot rouault at mines-paris dot org>
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included
21  * in all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29  * DEALINGS IN THE SOFTWARE.
30  ****************************************************************************/
31 
32 #ifndef CPL_CONV_H_INCLUDED
33 #define CPL_CONV_H_INCLUDED
34 
35 #include "cpl_port.h"
36 #include "cpl_vsi.h"
37 #include "cpl_error.h"
38 
46 /* -------------------------------------------------------------------- */
47 /* Runtime check of various configuration items. */
48 /* -------------------------------------------------------------------- */
49 CPL_C_START
50 
51 void CPL_DLL CPLVerifyConfiguration(void);
52 
53 const char CPL_DLL * CPL_STDCALL
54 CPLGetConfigOption( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
55 void CPL_DLL CPL_STDCALL CPLSetConfigOption( const char *, const char * );
56 void CPL_DLL CPL_STDCALL CPLSetThreadLocalConfigOption( const char *pszKey,
57  const char *pszValue );
58 void CPL_DLL CPL_STDCALL CPLFreeConfig(void);
59 
60 /* -------------------------------------------------------------------- */
61 /* Safe malloc() API. Thin cover over VSI functions with fatal */
62 /* error reporting if memory allocation fails. */
63 /* -------------------------------------------------------------------- */
64 void CPL_DLL *CPLMalloc( size_t ) CPL_WARN_UNUSED_RESULT;
65 void CPL_DLL *CPLCalloc( size_t, size_t ) CPL_WARN_UNUSED_RESULT;
66 void CPL_DLL *CPLRealloc( void *, size_t ) CPL_WARN_UNUSED_RESULT;
67 char CPL_DLL *CPLStrdup( const char * ) CPL_WARN_UNUSED_RESULT;
68 char CPL_DLL *CPLStrlwr( char *);
69 
70 #define CPLFree VSIFree
71 
72 /* -------------------------------------------------------------------- */
73 /* Read a line from a text file, and strip of CR/LF. */
74 /* -------------------------------------------------------------------- */
75 char CPL_DLL *CPLFGets( char *, int, FILE *);
76 const char CPL_DLL *CPLReadLine( FILE * );
77 const char CPL_DLL *CPLReadLineL( VSILFILE * );
78 const char CPL_DLL *CPLReadLine2L( VSILFILE * , int nMaxCols, char** papszOptions);
79 
80 /* -------------------------------------------------------------------- */
81 /* Convert ASCII string to floationg point number */
82 /* (THESE FUNCTIONS ARE NOT LOCALE AWARE!). */
83 /* -------------------------------------------------------------------- */
84 double CPL_DLL CPLAtof(const char *);
85 double CPL_DLL CPLAtofDelim(const char *, char);
86 double CPL_DLL CPLStrtod(const char *, char **);
87 double CPL_DLL CPLStrtodDelim(const char *, char **, char);
88 float CPL_DLL CPLStrtof(const char *, char **);
89 float CPL_DLL CPLStrtofDelim(const char *, char **, char);
90 
91 /* -------------------------------------------------------------------- */
92 /* Convert number to string. This function is locale agnostic */
93 /* (ie. it will support "," or "." regardless of current locale) */
94 /* -------------------------------------------------------------------- */
95 double CPL_DLL CPLAtofM(const char *);
96 
97 /* -------------------------------------------------------------------- */
98 /* Read a numeric value from an ASCII character string. */
99 /* -------------------------------------------------------------------- */
100 char CPL_DLL *CPLScanString( const char *, int, int, int );
101 double CPL_DLL CPLScanDouble( const char *, int );
102 long CPL_DLL CPLScanLong( const char *, int );
103 unsigned long CPL_DLL CPLScanULong( const char *, int );
104 GUIntBig CPL_DLL CPLScanUIntBig( const char *, int );
105 void CPL_DLL *CPLScanPointer( const char *, int );
106 
107 /* -------------------------------------------------------------------- */
108 /* Print a value to an ASCII character string. */
109 /* -------------------------------------------------------------------- */
110 int CPL_DLL CPLPrintString( char *, const char *, int );
111 int CPL_DLL CPLPrintStringFill( char *, const char *, int );
112 int CPL_DLL CPLPrintInt32( char *, GInt32 , int );
113 int CPL_DLL CPLPrintUIntBig( char *, GUIntBig , int );
114 int CPL_DLL CPLPrintDouble( char *, const char *, double, const char * );
115 int CPL_DLL CPLPrintTime( char *, int , const char *, const struct tm *,
116  const char * );
117 int CPL_DLL CPLPrintPointer( char *, void *, int );
118 
119 /* -------------------------------------------------------------------- */
120 /* Fetch a function from DLL / so. */
121 /* -------------------------------------------------------------------- */
122 
123 void CPL_DLL *CPLGetSymbol( const char *, const char * );
124 
125 /* -------------------------------------------------------------------- */
126 /* Fetch executable path. */
127 /* -------------------------------------------------------------------- */
128 int CPL_DLL CPLGetExecPath( char *pszPathBuf, int nMaxLength );
129 
130 /* -------------------------------------------------------------------- */
131 /* Filename handling functions. */
132 /* -------------------------------------------------------------------- */
133 const char CPL_DLL *CPLGetPath( const char * );
134 const char CPL_DLL *CPLGetDirname( const char * );
135 const char CPL_DLL *CPLGetFilename( const char * );
136 const char CPL_DLL *CPLGetBasename( const char * );
137 const char CPL_DLL *CPLGetExtension( const char * );
138 char CPL_DLL *CPLGetCurrentDir(void);
139 const char CPL_DLL *CPLFormFilename( const char *pszPath,
140  const char *pszBasename,
141  const char *pszExtension );
142 const char CPL_DLL *CPLFormCIFilename( const char *pszPath,
143  const char *pszBasename,
144  const char *pszExtension );
145 const char CPL_DLL *CPLResetExtension( const char *, const char * );
146 const char CPL_DLL *CPLProjectRelativeFilename( const char *pszProjectDir,
147  const char *pszSecondaryFilename );
148 int CPL_DLL CPLIsFilenameRelative( const char *pszFilename );
149 const char CPL_DLL *CPLExtractRelativePath(const char *, const char *, int *);
150 const char CPL_DLL *CPLCleanTrailingSlash( const char * );
151 char CPL_DLL **CPLCorrespondingPaths( const char *pszOldFilename,
152  const char *pszNewFilename,
153  char **papszFileList );
154 int CPL_DLL CPLCheckForFile( char *pszFilename, char **papszSiblingList );
155 
156 const char CPL_DLL *CPLGenerateTempFilename( const char *pszStem );
157 
158 /* -------------------------------------------------------------------- */
159 /* Find File Function */
160 /* -------------------------------------------------------------------- */
161 typedef const char *(*CPLFileFinder)(const char *, const char *);
162 
163 const char CPL_DLL *CPLFindFile(const char *pszClass,
164  const char *pszBasename);
165 const char CPL_DLL *CPLDefaultFindFile(const char *pszClass,
166  const char *pszBasename);
167 void CPL_DLL CPLPushFileFinder( CPLFileFinder pfnFinder );
168 CPLFileFinder CPL_DLL CPLPopFileFinder(void);
169 void CPL_DLL CPLPushFinderLocation( const char * );
170 void CPL_DLL CPLPopFinderLocation(void);
171 void CPL_DLL CPLFinderClean(void);
172 
173 /* -------------------------------------------------------------------- */
174 /* Safe version of stat() that works properly on stuff like "C:". */
175 /* -------------------------------------------------------------------- */
176 int CPL_DLL CPLStat( const char *, VSIStatBuf * );
177 
178 /* -------------------------------------------------------------------- */
179 /* Reference counted file handle manager. Makes sharing file */
180 /* handles more practical. */
181 /* -------------------------------------------------------------------- */
182 typedef struct {
183  FILE *fp;
184  int nRefCount;
185  int bLarge;
186  char *pszFilename;
187  char *pszAccess;
189 
190 FILE CPL_DLL *CPLOpenShared( const char *, const char *, int );
191 void CPL_DLL CPLCloseShared( FILE * );
192 CPLSharedFileInfo CPL_DLL *CPLGetSharedList( int * );
193 void CPL_DLL CPLDumpSharedList( FILE * );
194 void CPL_DLL CPLCleanupSharedFileMutex( void );
195 
196 /* -------------------------------------------------------------------- */
197 /* DMS to Dec to DMS conversion. */
198 /* -------------------------------------------------------------------- */
199 double CPL_DLL CPLDMSToDec( const char *is );
200 const char CPL_DLL *CPLDecToDMS( double dfAngle, const char * pszAxis,
201  int nPrecision );
202 double CPL_DLL CPLPackedDMSToDec( double );
203 double CPL_DLL CPLDecToPackedDMS( double dfDec );
204 
205 void CPL_DLL CPLStringToComplex( const char *pszString,
206  double *pdfReal, double *pdfImag );
207 
208 /* -------------------------------------------------------------------- */
209 /* Misc other functions. */
210 /* -------------------------------------------------------------------- */
211 int CPL_DLL CPLUnlinkTree( const char * );
212 int CPL_DLL CPLCopyFile( const char *pszNewPath, const char *pszOldPath );
213 int CPL_DLL CPLMoveFile( const char *pszNewPath, const char *pszOldPath );
214 
215 /* -------------------------------------------------------------------- */
216 /* ZIP Creation. */
217 /* -------------------------------------------------------------------- */
218 #define CPL_ZIP_API_OFFERED
219 void CPL_DLL *CPLCreateZip( const char *pszZipFilename, char **papszOptions );
220 CPLErr CPL_DLL CPLCreateFileInZip( void *hZip, const char *pszFilename,
221  char **papszOptions );
222 CPLErr CPL_DLL CPLWriteFileInZip( void *hZip, const void *pBuffer, int nBufferSize );
223 CPLErr CPL_DLL CPLCloseFileInZip( void *hZip );
224 CPLErr CPL_DLL CPLCloseZip( void *hZip );
225 
226 /* -------------------------------------------------------------------- */
227 /* ZLib compression */
228 /* -------------------------------------------------------------------- */
229 
230 void CPL_DLL *CPLZLibDeflate( const void* ptr, size_t nBytes, int nLevel,
231  void* outptr, size_t nOutAvailableBytes,
232  size_t* pnOutBytes );
233 void CPL_DLL *CPLZLibInflate( const void* ptr, size_t nBytes,
234  void* outptr, size_t nOutAvailableBytes,
235  size_t* pnOutBytes );
236 
237 /* -------------------------------------------------------------------- */
238 /* XML validation. */
239 /* -------------------------------------------------------------------- */
240 int CPL_DLL CPLValidateXML(const char* pszXMLFilename,
241  const char* pszXSDFilename,
242  char** papszOptions);
243 
244 /* -------------------------------------------------------------------- */
245 /* Locale handling. Prevents parallel executions of setlocale(). */
246 /* -------------------------------------------------------------------- */
247 char* CPLsetlocale (int category, const char* locale);
248 void CPLCleanupSetlocaleMutex(void);
249 
250 CPL_C_END
251 
252 /* -------------------------------------------------------------------- */
253 /* C++ object for temporariliy forcing a LC_NUMERIC locale to "C". */
254 /* -------------------------------------------------------------------- */
255 
256 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
257 
258 class CPL_DLL CPLLocaleC
259 {
260 public:
261  CPLLocaleC();
262  ~CPLLocaleC();
263 
264 private:
265  char *pszOldLocale;
266 
267  /* Make it non-copyable */
269  CPLLocaleC& operator=(CPLLocaleC&);
270 };
271 
272 #endif /* def __cplusplus */
273 
274 
275 #endif /* ndef CPL_CONV_H_INCLUDED */
int CPLIsFilenameRelative(const char *pszFilename)
Definition: cpl_path.cpp:686
const char * CPLProjectRelativeFilename(const char *pszProjectDir, const char *pszSecondaryFilename)
Definition: cpl_path.cpp:629
int CPLPrintString(char *, const char *, int)
Definition: cpl_conv.cpp:1065
const char * CPLFormFilename(const char *pszPath, const char *pszBasename, const char *pszExtension)
Definition: cpl_path.cpp:460
double CPLDecToPackedDMS(double dfDec)
Definition: cpl_conv.cpp:1949
const char * CPLExtractRelativePath(const char *, const char *, int *)
Definition: cpl_path.cpp:726
int CPLPrintDouble(char *, const char *, double, const char *)
Definition: cpl_conv.cpp:1284
const char * CPLFormCIFilename(const char *pszPath, const char *pszBasename, const char *pszExtension)
Definition: cpl_path.cpp:534
const char * CPLResetExtension(const char *, const char *)
Definition: cpl_path.cpp:388
int CPLPrintStringFill(char *, const char *, int)
Definition: cpl_conv.cpp:1109
int CPLPrintPointer(char *, void *, int)
Definition: cpl_conv.cpp:1235
double CPLAtof(const char *)
Definition: cpl_strtod.cpp:137
void * CPLGetSymbol(const char *, const char *)
Definition: cplgetsymbol.cpp:84
int CPLGetExecPath(char *pszPathBuf, int nMaxLength)
Definition: cpl_getexecpath.cpp:138
char * CPLsetlocale(int category, const char *locale)
Definition: cpl_conv.cpp:2468
const char * CPLReadLine(FILE *)
Definition: cpl_conv.cpp:518
void * CPLZLibInflate(const void *ptr, size_t nBytes, void *outptr, size_t nOutAvailableBytes, size_t *pnOutBytes)
Uncompress a buffer compressed with ZLib DEFLATE compression.
Definition: cpl_conv.cpp:2594
float CPLStrtof(const char *, char **)
Definition: cpl_strtod.cpp:400
char * CPLStrlwr(char *)
Definition: cpl_conv.cpp:282
void CPLSetThreadLocalConfigOption(const char *pszKey, const char *pszValue)
Definition: cpl_conv.cpp:1654
double CPLStrtodDelim(const char *, char **, char)
Definition: cpl_strtod.cpp:247
int CPLUnlinkTree(const char *)
Definition: cpl_conv.cpp:2243
const char * CPLReadLineL(VSILFILE *)
Definition: cpl_conv.cpp:583
CPLSharedFileInfo * CPLGetSharedList(int *)
Definition: cpl_conv.cpp:2182
const char * CPLGetDirname(const char *)
Definition: cpl_path.cpp:182
float CPLStrtofDelim(const char *, char **, char)
Definition: cpl_strtod.cpp:345
int CPLPrintTime(char *, int, const char *, const struct tm *, const char *)
Definition: cpl_conv.cpp:1374
Definition: cpl_conv.h:182
const char * CPLGetConfigOption(const char *, const char *)
Definition: cpl_conv.cpp:1547
FILE * CPLOpenShared(const char *, const char *, int)
Definition: cpl_conv.cpp:2027
char * CPLFGets(char *, int, FILE *)
Definition: cpl_conv.cpp:323
int CPLCheckForFile(char *pszFilename, char **papszSiblingList)
Definition: cpl_conv.cpp:2513
void CPLDumpSharedList(FILE *)
Definition: cpl_conv.cpp:2204
Definition: cpl_conv.h:258
unsigned long CPLScanULong(const char *, int)
Definition: cpl_conv.cpp:864
const char * CPLReadLine2L(VSILFILE *, int nMaxCols, char **papszOptions)
Definition: cpl_conv.cpp:608
const char * CPLGetPath(const char *)
Definition: cpl_path.cpp:129
void * CPLScanPointer(const char *, int)
Definition: cpl_conv.cpp:950
double CPLStrtod(const char *, char **)
Definition: cpl_strtod.cpp:319
const char * CPLGenerateTempFilename(const char *pszStem)
Definition: cpl_path.cpp:979
GUIntBig CPLScanUIntBig(const char *, int)
Definition: cpl_conv.cpp:904
char * CPLGetCurrentDir(void)
Definition: cpl_path.cpp:348
int CPLPrintInt32(char *, GInt32, int)
Definition: cpl_conv.cpp:1154
void CPLSetConfigOption(const char *, const char *)
Definition: cpl_conv.cpp:1609
double CPLScanDouble(const char *, int)
Definition: cpl_conv.cpp:1018
long CPLScanLong(const char *, int)
Definition: cpl_conv.cpp:825
const char * CPLGetBasename(const char *)
Definition: cpl_path.cpp:263
double CPLAtofM(const char *)
Definition: cpl_strtod.cpp:162
double CPLAtofDelim(const char *, char)
Definition: cpl_strtod.cpp:95
void * CPLCalloc(size_t, size_t)
Definition: cpl_conv.cpp:86
const char * CPLGetExtension(const char *)
Definition: cpl_path.cpp:313
const char * CPLGetFilename(const char *)
Definition: cpl_path.cpp:231
void * CPLMalloc(size_t)
Definition: cpl_conv.cpp:118
int CPLPrintUIntBig(char *, GUIntBig, int)
Definition: cpl_conv.cpp:1193
double CPLPackedDMSToDec(double)
Definition: cpl_conv.cpp:1913
void * CPLZLibDeflate(const void *ptr, size_t nBytes, int nLevel, void *outptr, size_t nOutAvailableBytes, size_t *pnOutBytes)
Compress a buffer with ZLib DEFLATE compression.
Definition: cpl_conv.cpp:2585
char * CPLScanString(const char *, int, int, int)
Definition: cpl_conv.cpp:769
char ** CPLCorrespondingPaths(const char *pszOldFilename, const char *pszNewFilename, char **papszFileList)
Definition: cpl_path.cpp:869
void CPLCloseShared(FILE *)
Definition: cpl_conv.cpp:2102
char * CPLStrdup(const char *)
Definition: cpl_conv.cpp:247
const char * CPLCleanTrailingSlash(const char *)
Definition: cpl_path.cpp:820
void * CPLRealloc(void *, size_t)
Definition: cpl_conv.cpp:181

Generated for GDAL by doxygen 1.8.11.