/src/gdal/port/cpl_conv.h
Line  | Count  | Source  | 
1  |  | /******************************************************************************  | 
2  |  |  *  | 
3  |  |  * Project:  CPL - Common Portability Library  | 
4  |  |  * Purpose:  Convenience functions declarations.  | 
5  |  |  *           This is intended to remain light weight.  | 
6  |  |  * Author:   Frank Warmerdam, warmerdam@pobox.com  | 
7  |  |  *  | 
8  |  |  ******************************************************************************  | 
9  |  |  * Copyright (c) 1998, Frank Warmerdam  | 
10  |  |  * Copyright (c) 2007-2013, Even Rouault <even dot rouault at spatialys.com>  | 
11  |  |  *  | 
12  |  |  * SPDX-License-Identifier: MIT  | 
13  |  |  ****************************************************************************/  | 
14  |  |  | 
15  |  | #ifndef CPL_CONV_H_INCLUDED  | 
16  |  | #define CPL_CONV_H_INCLUDED  | 
17  |  |  | 
18  |  | #include "cpl_port.h"  | 
19  |  | #include "cpl_vsi.h"  | 
20  |  | #include "cpl_error.h"  | 
21  |  |  | 
22  |  | /**  | 
23  |  |  * \file cpl_conv.h  | 
24  |  |  *  | 
25  |  |  * Various convenience functions for CPL.  | 
26  |  |  *  | 
27  |  |  */  | 
28  |  |  | 
29  |  | /* -------------------------------------------------------------------- */  | 
30  |  | /*      Runtime check of various configuration items.                   */  | 
31  |  | /* -------------------------------------------------------------------- */  | 
32  |  | CPL_C_START  | 
33  |  |  | 
34  |  | /*! @cond Doxygen_Suppress */  | 
35  |  | void CPL_DLL CPLVerifyConfiguration(void);  | 
36  |  | /*! @endcond */  | 
37  |  |  | 
38  |  | bool CPL_DLL CPLIsDebugEnabled(void);  | 
39  |  |  | 
40  |  | const char CPL_DLL *CPL_STDCALL CPLGetConfigOption(const char *, const char *)  | 
41  |  |     CPL_WARN_UNUSED_RESULT;  | 
42  |  | const char CPL_DLL *CPL_STDCALL CPLGetThreadLocalConfigOption(  | 
43  |  |     const char *, const char *) CPL_WARN_UNUSED_RESULT;  | 
44  |  | const char CPL_DLL *CPL_STDCALL  | 
45  |  | CPLGetGlobalConfigOption(const char *, const char *) CPL_WARN_UNUSED_RESULT;  | 
46  |  | void CPL_DLL CPL_STDCALL CPLSetConfigOption(const char *, const char *);  | 
47  |  | void CPL_DLL CPL_STDCALL CPLSetThreadLocalConfigOption(const char *pszKey,  | 
48  |  |                                                        const char *pszValue);  | 
49  |  | void CPL_DLL CPLDeclareKnownConfigOption(const char *pszKey,  | 
50  |  |                                          const char *pszDefinition);  | 
51  |  | char CPL_DLL **CPLGetKnownConfigOptions(void);  | 
52  |  |  | 
53  |  | /** Callback for CPLSubscribeToSetConfigOption() */  | 
54  |  | typedef void (*CPLSetConfigOptionSubscriber)(const char *pszKey,  | 
55  |  |                                              const char *pszValue,  | 
56  |  |                                              bool bThreadLocal,  | 
57  |  |                                              void *pUserData);  | 
58  |  | int CPL_DLL CPLSubscribeToSetConfigOption(  | 
59  |  |     CPLSetConfigOptionSubscriber pfnCallback, void *pUserData);  | 
60  |  | void CPL_DLL CPLUnsubscribeToSetConfigOption(int nSubscriberId);  | 
61  |  |  | 
62  |  | /*! @cond Doxygen_Suppress */  | 
63  |  | void CPL_DLL CPL_STDCALL CPLFreeConfig(void);  | 
64  |  | /*! @endcond */  | 
65  |  | char CPL_DLL **CPLGetConfigOptions(void);  | 
66  |  | void CPL_DLL CPLSetConfigOptions(const char *const *papszConfigOptions);  | 
67  |  | char CPL_DLL **CPLGetThreadLocalConfigOptions(void);  | 
68  |  | void CPL_DLL  | 
69  |  | CPLSetThreadLocalConfigOptions(const char *const *papszConfigOptions);  | 
70  |  | void CPL_DLL CPLLoadConfigOptionsFromFile(const char *pszFilename,  | 
71  |  |                                           int bOverrideEnvVars);  | 
72  |  | void CPL_DLL CPLLoadConfigOptionsFromPredefinedFiles(void);  | 
73  |  |  | 
74  |  | /* -------------------------------------------------------------------- */  | 
75  |  | /*      Safe malloc() API.  Thin cover over VSI functions with fatal    */  | 
76  |  | /*      error reporting if memory allocation fails.                     */  | 
77  |  | /* -------------------------------------------------------------------- */  | 
78  |  | void CPL_DLL *CPLMalloc(size_t) CPL_WARN_UNUSED_RESULT;  | 
79  |  | void CPL_DLL *CPLCalloc(size_t, size_t) CPL_WARN_UNUSED_RESULT;  | 
80  |  | void CPL_DLL *CPLRealloc(void *, size_t) CPL_WARN_UNUSED_RESULT;  | 
81  |  | char CPL_DLL *  | 
82  |  | CPLStrdup(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;  | 
83  |  | char CPL_DLL *CPLStrlwr(char *);  | 
84  |  |  | 
85  |  | /** Alias of VSIFree() */  | 
86  | 291k  | #define CPLFree VSIFree  | 
87  |  |  | 
88  |  | /* -------------------------------------------------------------------- */  | 
89  |  | /*      Read a line from a text file, and strip of CR/LF.               */  | 
90  |  | /* -------------------------------------------------------------------- */  | 
91  |  | char CPL_DLL *CPLFGets(char *, int, FILE *);  | 
92  |  | const char CPL_DLL *CPLReadLine(FILE *);  | 
93  |  | const char CPL_DLL *CPLReadLineL(VSILFILE *);  | 
94  |  | const char CPL_DLL *CPLReadLine2L(VSILFILE *, int, CSLConstList);  | 
95  |  | const char CPL_DLL *CPLReadLine3L(VSILFILE *, int, int *, CSLConstList);  | 
96  |  |  | 
97  |  | /* -------------------------------------------------------------------- */  | 
98  |  | /*      Convert ASCII string to floating point number                  */  | 
99  |  | /*      (THESE FUNCTIONS ARE NOT LOCALE AWARE!).                        */  | 
100  |  | /* -------------------------------------------------------------------- */  | 
101  |  | double CPL_DLL CPLAtof(const char *);  | 
102  |  | double CPL_DLL CPLAtofDelim(const char *, char);  | 
103  |  | double CPL_DLL CPLStrtod(const char *, char **);  | 
104  |  | double CPL_DLL CPLStrtodM(const char *, char **);  | 
105  |  | double CPL_DLL CPLStrtodDelim(const char *, char **, char);  | 
106  |  | float CPL_DLL CPLStrtof(const char *, char **);  | 
107  |  | float CPL_DLL CPLStrtofDelim(const char *, char **, char);  | 
108  |  |  | 
109  |  | /* -------------------------------------------------------------------- */  | 
110  |  | /*      Convert number to string.  This function is locale agnostic     */  | 
111  |  | /*      (i.e. it will support "," or "." regardless of current locale)  */  | 
112  |  | /* -------------------------------------------------------------------- */  | 
113  |  | double CPL_DLL CPLAtofM(const char *);  | 
114  |  |  | 
115  |  | /* -------------------------------------------------------------------- */  | 
116  |  | /*      Read a numeric value from an ASCII character string.            */  | 
117  |  | /* -------------------------------------------------------------------- */  | 
118  |  | char CPL_DLL *CPLScanString(const char *, int, int, int);  | 
119  |  | double CPL_DLL CPLScanDouble(const char *, int);  | 
120  |  | long CPL_DLL CPLScanLong(const char *, int);  | 
121  |  | unsigned long CPL_DLL CPLScanULong(const char *, int);  | 
122  |  | GUIntBig CPL_DLL CPLScanUIntBig(const char *, int);  | 
123  |  | GIntBig CPL_DLL CPLAtoGIntBig(const char *pszString);  | 
124  |  | GIntBig CPL_DLL CPLAtoGIntBigEx(const char *pszString, int bWarn,  | 
125  |  |                                 int *pbOverflow);  | 
126  |  | void CPL_DLL *CPLScanPointer(const char *, int);  | 
127  |  |  | 
128  |  | /* -------------------------------------------------------------------- */  | 
129  |  | /*      Print a value to an ASCII character string.                     */  | 
130  |  | /* -------------------------------------------------------------------- */  | 
131  |  | int CPL_DLL CPLPrintString(char *, const char *, int);  | 
132  |  | int CPL_DLL CPLPrintStringFill(char *, const char *, int);  | 
133  |  | int CPL_DLL CPLPrintInt32(char *, GInt32, int);  | 
134  |  | int CPL_DLL CPLPrintUIntBig(char *, GUIntBig, int);  | 
135  |  | int CPL_DLL CPLPrintDouble(char *, const char *, double, const char *);  | 
136  |  | int CPL_DLL CPLPrintTime(char *, int, const char *, const struct tm *,  | 
137  |  |                          const char *);  | 
138  |  | int CPL_DLL CPLPrintPointer(char *, void *, int);  | 
139  |  |  | 
140  |  | #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)  | 
141  |  | extern "C++"  | 
142  |  | { | 
143  |  |     std::string CPL_DLL CPLFormatReadableFileSize(uint64_t nSizeInBytes);  | 
144  |  |     std::string CPL_DLL CPLFormatReadableFileSize(double dfSizeInBytes);  | 
145  |  | }  | 
146  |  | #endif  | 
147  |  |  | 
148  |  | /* -------------------------------------------------------------------- */  | 
149  |  | /*      Fetch a function from DLL / so.                                 */  | 
150  |  | /* -------------------------------------------------------------------- */  | 
151  |  |  | 
152  |  | void CPL_DLL *CPLGetSymbol(const char *, const char *);  | 
153  |  |  | 
154  |  | /* -------------------------------------------------------------------- */  | 
155  |  | /*      Fetch executable path.                                          */  | 
156  |  | /* -------------------------------------------------------------------- */  | 
157  |  | int CPL_DLL CPLGetExecPath(char *pszPathBuf, int nMaxLength);  | 
158  |  |  | 
159  |  | /* -------------------------------------------------------------------- */  | 
160  |  | /*      Filename handling functions.                                    */  | 
161  |  | /* -------------------------------------------------------------------- */  | 
162  |  |  | 
163  |  | #if defined(DOXYGEN_SKIP) || !defined(__cplusplus) ||                          \  | 
164  |  |     !defined(GDAL_COMPILATION) ||                                              \  | 
165  |  |     (defined(__cplusplus) && defined(ALLOW_DEPRECATED_CPL_PATH_FUNCTIONS))  | 
166  |  | const char CPL_DLL *  | 
167  |  | CPLGetPath(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;  | 
168  |  | const char CPL_DLL *  | 
169  |  | CPLGetDirname(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;  | 
170  |  | const char CPL_DLL *  | 
171  |  | CPLGetBasename(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;  | 
172  |  | const char CPL_DLL *  | 
173  |  | CPLGetExtension(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;  | 
174  |  | const char CPL_DLL *CPLFormFilename(  | 
175  |  |     const char *pszPath, const char *pszBasename,  | 
176  |  |     const char *pszExtension) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;  | 
177  |  | const char CPL_DLL *CPLFormCIFilename(  | 
178  |  |     const char *pszPath, const char *pszBasename,  | 
179  |  |     const char *pszExtension) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;  | 
180  |  | const char CPL_DLL *CPLResetExtension(const char *, const char *)  | 
181  |  |     CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;  | 
182  |  | const char CPL_DLL *CPLProjectRelativeFilename(const char *pszProjectDir,  | 
183  |  |                                                const char *pszSecondaryFilename)  | 
184  |  |     CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;  | 
185  |  | const char CPL_DLL *  | 
186  |  | CPLCleanTrailingSlash(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;  | 
187  |  | const char CPL_DLL *CPLGenerateTempFilename(const char *pszStem)  | 
188  |  |     CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;  | 
189  |  | const char CPL_DLL *CPLExpandTilde(const char *pszFilename)  | 
190  |  |     CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;  | 
191  |  | const char CPL_DLL *  | 
192  |  | CPLLaunderForFilename(const char *pszName,  | 
193  |  |                       const char *pszOutputPath) CPL_WARN_UNUSED_RESULT;  | 
194  |  | #endif  | 
195  |  |  | 
196  |  | char CPL_DLL *CPLGetCurrentDir(void);  | 
197  |  | const char CPL_DLL *  | 
198  |  | CPLGetFilename(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;  | 
199  |  | int CPL_DLL CPLIsFilenameRelative(const char *pszFilename);  | 
200  |  | const char CPL_DLL *CPLExtractRelativePath(const char *, const char *, int *)  | 
201  |  |     CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;  | 
202  |  | char CPL_DLL **  | 
203  |  | CPLCorrespondingPaths(const char *pszOldFilename, const char *pszNewFilename,  | 
204  |  |                       char **papszFileList) CPL_WARN_UNUSED_RESULT;  | 
205  |  | int CPL_DLL CPLCheckForFile(char *pszFilename, char **papszSiblingList);  | 
206  |  |  | 
207  |  | const char CPL_DLL *CPLGetHomeDir(void) CPL_WARN_UNUSED_RESULT;  | 
208  |  |  | 
209  |  | #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)  | 
210  |  |  | 
211  |  | extern "C++"  | 
212  |  | { | 
213  |  |     std::string CPL_DLL CPLGetPathSafe(const char *) CPL_WARN_UNUSED_RESULT;  | 
214  |  |     std::string CPL_DLL CPLGetDirnameSafe(const char *) CPL_WARN_UNUSED_RESULT;  | 
215  |  |     std::string CPL_DLL CPLGetBasenameSafe(const char *) CPL_WARN_UNUSED_RESULT;  | 
216  |  |     std::string CPL_DLL CPLGetExtensionSafe(const char *)  | 
217  |  |         CPL_WARN_UNUSED_RESULT;  | 
218  |  |     std::string CPL_DLL CPLFormFilenameSafe(  | 
219  |  |         const char *pszPath, const char *pszBasename,  | 
220  |  |         const char *pszExtension = nullptr) CPL_WARN_UNUSED_RESULT;  | 
221  |  |     std::string CPL_DLL CPLFormCIFilenameSafe(  | 
222  |  |         const char *pszPath, const char *pszBasename,  | 
223  |  |         const char *pszExtension = nullptr) CPL_WARN_UNUSED_RESULT;  | 
224  |  |     std::string CPL_DLL CPLResetExtensionSafe(const char *, const char *)  | 
225  |  |         CPL_WARN_UNUSED_RESULT;  | 
226  |  |     std::string CPL_DLL CPLProjectRelativeFilenameSafe(  | 
227  |  |         const char *pszProjectDir,  | 
228  |  |         const char *pszSecondaryFilename) CPL_WARN_UNUSED_RESULT;  | 
229  |  |     std::string CPL_DLL CPLCleanTrailingSlashSafe(const char *pszPath)  | 
230  |  |         CPL_WARN_UNUSED_RESULT;  | 
231  |  |     std::string CPL_DLL CPLGenerateTempFilenameSafe(const char *pszStem)  | 
232  |  |         CPL_WARN_UNUSED_RESULT;  | 
233  |  |     std::string CPL_DLL CPLExpandTildeSafe(const char *pszFilename)  | 
234  |  |         CPL_WARN_UNUSED_RESULT;  | 
235  |  |     std::string CPL_DLL CPLLaunderForFilenameSafe(  | 
236  |  |         const char *pszName, const char *pszOutputPath) CPL_WARN_UNUSED_RESULT;  | 
237  |  | }  | 
238  |  |  | 
239  |  | #endif  // defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)  | 
240  |  |  | 
241  |  | /* -------------------------------------------------------------------- */  | 
242  |  | /*      Find File Function                                              */  | 
243  |  | /* -------------------------------------------------------------------- */  | 
244  |  |  | 
245  |  | /** Callback for CPLPushFileFinder */  | 
246  |  | typedef char const *(*CPLFileFinder)(const char *, const char *);  | 
247  |  |  | 
248  |  | const char CPL_DLL *CPLFindFile(const char *pszClass, const char *pszBasename);  | 
249  |  | const char CPL_DLL *CPLDefaultFindFile(const char *pszClass,  | 
250  |  |                                        const char *pszBasename);  | 
251  |  | void CPL_DLL CPLPushFileFinder(CPLFileFinder pfnFinder);  | 
252  |  | CPLFileFinder CPL_DLL CPLPopFileFinder(void);  | 
253  |  | void CPL_DLL CPLPushFinderLocation(const char *);  | 
254  |  | void CPL_DLL CPLPopFinderLocation(void);  | 
255  |  | void CPL_DLL CPLFinderClean(void);  | 
256  |  |  | 
257  |  | /* -------------------------------------------------------------------- */  | 
258  |  | /*      Safe version of stat() that works properly on stuff like "C:".  */  | 
259  |  | /* -------------------------------------------------------------------- */  | 
260  |  | int CPL_DLL CPLStat(const char *, VSIStatBuf *) CPL_WARN_UNUSED_RESULT;  | 
261  |  |  | 
262  |  | /* -------------------------------------------------------------------- */  | 
263  |  | /*      Reference counted file handle manager.  Makes sharing file      */  | 
264  |  | /*      handles more practical.                                         */  | 
265  |  | /* -------------------------------------------------------------------- */  | 
266  |  |  | 
267  |  | /** Information on a shared file */  | 
268  |  | typedef struct  | 
269  |  | { | 
270  |  |     FILE *fp;          /**< File pointer */  | 
271  |  |     int nRefCount;     /**< Reference counter */  | 
272  |  |     int bLarge;        /**< Whether fp must be interpreted as VSIFILE* */  | 
273  |  |     char *pszFilename; /**< Filename */  | 
274  |  |     char *pszAccess;   /**< Access mode */  | 
275  |  | } CPLSharedFileInfo;  | 
276  |  |  | 
277  |  | FILE CPL_DLL *CPLOpenShared(const char *, const char *, int);  | 
278  |  | void CPL_DLL CPLCloseShared(FILE *);  | 
279  |  | CPLSharedFileInfo CPL_DLL *CPLGetSharedList(int *);  | 
280  |  | void CPL_DLL CPLDumpSharedList(FILE *);  | 
281  |  | /*! @cond Doxygen_Suppress */  | 
282  |  | void CPL_DLL CPLCleanupSharedFileMutex(void);  | 
283  |  | /*! @endcond */  | 
284  |  |  | 
285  |  | /* -------------------------------------------------------------------- */  | 
286  |  | /*      DMS to Dec to DMS conversion.                                   */  | 
287  |  | /* -------------------------------------------------------------------- */  | 
288  |  | double CPL_DLL CPLDMSToDec(const char *is);  | 
289  |  | const char CPL_DLL *CPLDecToDMS(double dfAngle, const char *pszAxis,  | 
290  |  |                                 int nPrecision);  | 
291  |  | double CPL_DLL CPLPackedDMSToDec(double);  | 
292  |  | double CPL_DLL CPLDecToPackedDMS(double dfDec);  | 
293  |  |  | 
294  |  | CPLErr CPL_DLL CPLStringToComplex(const char *pszString, double *pdfReal,  | 
295  |  |                                   double *pdfImag);  | 
296  |  |  | 
297  |  | /* -------------------------------------------------------------------- */  | 
298  |  | /*      Misc other functions.                                           */  | 
299  |  | /* -------------------------------------------------------------------- */  | 
300  |  | int CPL_DLL CPLUnlinkTree(const char *);  | 
301  |  | int CPL_DLL CPLCopyFile(const char *pszNewPath, const char *pszOldPath);  | 
302  |  | int CPL_DLL CPLCopyTree(const char *pszNewPath, const char *pszOldPath);  | 
303  |  | int CPL_DLL CPLMoveFile(const char *pszNewPath, const char *pszOldPath);  | 
304  |  | int CPL_DLL CPLSymlink(const char *pszOldPath, const char *pszNewPath,  | 
305  |  |                        CSLConstList papszOptions);  | 
306  |  |  | 
307  |  | /* -------------------------------------------------------------------- */  | 
308  |  | /*      Lock related functions.                                         */  | 
309  |  | /* -------------------------------------------------------------------- */  | 
310  |  |  | 
311  |  | /** Return code of CPLLockFileEx(). */  | 
312  |  | typedef enum  | 
313  |  | { | 
314  |  |     CLFS_OK,                     /**< CPLLockFileEx() succeeded. */  | 
315  |  |     CLFS_CANNOT_CREATE_LOCK,     /**< Lock file creation failed. */  | 
316  |  |     CLFS_LOCK_BUSY,              /**< Lock already taken (and still alive). */  | 
317  |  |     CLFS_API_MISUSE,             /**< API misuse. */  | 
318  |  |     CLFS_THREAD_CREATION_FAILED, /**< Thread creation failed. */  | 
319  |  | } CPLLockFileStatus;  | 
320  |  |  | 
321  |  | /** Handle type returned by CPLLockFileEx(). */  | 
322  |  | typedef struct CPLLockFileStruct *CPLLockFileHandle;  | 
323  |  |  | 
324  |  | CPLLockFileStatus CPL_DLL CPLLockFileEx(const char *pszLockFileName,  | 
325  |  |                                         CPLLockFileHandle *phLockFileHandle,  | 
326  |  |                                         CSLConstList papszOptions);  | 
327  |  |  | 
328  |  | void CPL_DLL CPLUnlockFileEx(CPLLockFileHandle hLockFileHandle);  | 
329  |  |  | 
330  |  | /* -------------------------------------------------------------------- */  | 
331  |  | /*      ZIP Creation.                                                   */  | 
332  |  | /* -------------------------------------------------------------------- */  | 
333  |  |  | 
334  |  | /*! @cond Doxygen_Suppress */  | 
335  |  | #define CPL_ZIP_API_OFFERED  | 
336  |  | /*! @endcond */  | 
337  |  | void CPL_DLL *CPLCreateZip(const char *pszZipFilename, char **papszOptions);  | 
338  |  | CPLErr CPL_DLL CPLCreateFileInZip(void *hZip, const char *pszFilename,  | 
339  |  |                                   char **papszOptions);  | 
340  |  | CPLErr CPL_DLL CPLWriteFileInZip(void *hZip, const void *pBuffer,  | 
341  |  |                                  int nBufferSize);  | 
342  |  | CPLErr CPL_DLL CPLCloseFileInZip(void *hZip);  | 
343  |  | CPLErr CPL_DLL CPLAddFileInZip(void *hZip, const char *pszArchiveFilename,  | 
344  |  |                                const char *pszInputFilename, VSILFILE *fpInput,  | 
345  |  |                                CSLConstList papszOptions,  | 
346  |  |                                GDALProgressFunc pProgressFunc,  | 
347  |  |                                void *pProgressData);  | 
348  |  | CPLErr CPL_DLL CPLCloseZip(void *hZip);  | 
349  |  |  | 
350  |  | /* -------------------------------------------------------------------- */  | 
351  |  | /*      ZLib compression                                                */  | 
352  |  | /* -------------------------------------------------------------------- */  | 
353  |  |  | 
354  |  | void CPL_DLL *CPLZLibDeflate(const void *ptr, size_t nBytes, int nLevel,  | 
355  |  |                              void *outptr, size_t nOutAvailableBytes,  | 
356  |  |                              size_t *pnOutBytes);  | 
357  |  | void CPL_DLL *CPLZLibInflate(const void *ptr, size_t nBytes, void *outptr,  | 
358  |  |                              size_t nOutAvailableBytes, size_t *pnOutBytes);  | 
359  |  | void CPL_DLL *CPLZLibInflateEx(const void *ptr, size_t nBytes, void *outptr,  | 
360  |  |                                size_t nOutAvailableBytes,  | 
361  |  |                                bool bAllowResizeOutptr, size_t *pnOutBytes);  | 
362  |  |  | 
363  |  | /* -------------------------------------------------------------------- */  | 
364  |  | /*      XML validation.                                                 */  | 
365  |  | /* -------------------------------------------------------------------- */  | 
366  |  | int CPL_DLL CPLValidateXML(const char *pszXMLFilename,  | 
367  |  |                            const char *pszXSDFilename,  | 
368  |  |                            CSLConstList papszOptions);  | 
369  |  |  | 
370  |  | /* -------------------------------------------------------------------- */  | 
371  |  | /*      Locale handling. Prevents parallel executions of setlocale().   */  | 
372  |  | /* -------------------------------------------------------------------- */  | 
373  |  | char *CPLsetlocale(int category, const char *locale);  | 
374  |  | /*! @cond Doxygen_Suppress */  | 
375  |  | void CPLCleanupSetlocaleMutex(void);  | 
376  |  | /*! @endcond */  | 
377  |  |  | 
378  |  | /*!  | 
379  |  |     CPLIsPowerOfTwo()  | 
380  |  |     @param i - tested number  | 
381  |  |     @return TRUE if i is power of two otherwise return FALSE  | 
382  |  | */  | 
383  |  | int CPL_DLL CPLIsPowerOfTwo(unsigned int i);  | 
384  |  |  | 
385  |  | /* -------------------------------------------------------------------- */  | 
386  |  | /*      Terminal related                                                */  | 
387  |  | /* -------------------------------------------------------------------- */  | 
388  |  |  | 
389  |  | bool CPL_DLL CPLIsInteractive(FILE *f);  | 
390  |  |  | 
391  |  | CPL_C_END  | 
392  |  |  | 
393  |  | /* -------------------------------------------------------------------- */  | 
394  |  | /*      C++ object for temporarily forcing a LC_NUMERIC locale to "C".  */  | 
395  |  | /* -------------------------------------------------------------------- */  | 
396  |  |  | 
397  |  | //! @cond Doxygen_Suppress  | 
398  |  | #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)  | 
399  |  |  | 
400  |  | extern "C++"  | 
401  |  | { | 
402  |  |     class CPL_DLL CPLLocaleC  | 
403  |  |     { | 
404  |  |         CPL_DISALLOW_COPY_ASSIGN(CPLLocaleC)  | 
405  |  |       public:  | 
406  |  |         CPLLocaleC();  | 
407  |  |         ~CPLLocaleC();  | 
408  |  |  | 
409  |  |       private:  | 
410  |  |         char *pszOldLocale;  | 
411  |  |     };  | 
412  |  |  | 
413  |  |     // Does the same as CPLLocaleC except that, when available, it tries to  | 
414  |  |     // only affect the current thread. But code that would be dependent of  | 
415  |  |     // setlocale(LC_NUMERIC, NULL) returning "C", such as current proj.4  | 
416  |  |     // versions, will not work depending on the actual implementation  | 
417  |  |     class CPLThreadLocaleCPrivate;  | 
418  |  |  | 
419  |  |     class CPL_DLL CPLThreadLocaleC  | 
420  |  |     { | 
421  |  |         CPL_DISALLOW_COPY_ASSIGN(CPLThreadLocaleC)  | 
422  |  |  | 
423  |  |       public:  | 
424  |  |         CPLThreadLocaleC();  | 
425  |  |         ~CPLThreadLocaleC();  | 
426  |  |  | 
427  |  |       private:  | 
428  |  |         CPLThreadLocaleCPrivate *m_private;  | 
429  |  |     };  | 
430  |  | }  | 
431  |  |  | 
432  |  | #endif /* def __cplusplus */  | 
433  |  | //! @endcond  | 
434  |  |  | 
435  |  | /* -------------------------------------------------------------------- */  | 
436  |  | /*      C++ object for temporarily forcing a config option              */  | 
437  |  | /* -------------------------------------------------------------------- */  | 
438  |  |  | 
439  |  | //! @cond Doxygen_Suppress  | 
440  |  | #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)  | 
441  |  |  | 
442  |  | extern "C++"  | 
443  |  | { | 
444  |  |     class CPL_DLL CPLConfigOptionSetter  | 
445  |  |     { | 
446  |  |         CPL_DISALLOW_COPY_ASSIGN(CPLConfigOptionSetter)  | 
447  |  |       public:  | 
448  |  |         CPLConfigOptionSetter(const char *pszKey, const char *pszValue,  | 
449  |  |                               bool bSetOnlyIfUndefined);  | 
450  |  |         ~CPLConfigOptionSetter();  | 
451  |  |  | 
452  |  |       private:  | 
453  |  |         char *m_pszKey;  | 
454  |  |         char *m_pszOldValue;  | 
455  |  |         bool m_bRestoreOldValue;  | 
456  |  |     };  | 
457  |  | }  | 
458  |  |  | 
459  |  | #endif /* def __cplusplus */  | 
460  |  | //! @endcond  | 
461  |  |  | 
462  |  | #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)  | 
463  |  |  | 
464  |  | extern "C++"  | 
465  |  | { | 
466  |  |  | 
467  |  | #ifndef DOXYGEN_SKIP  | 
468  |  | #include <type_traits>  // for std::is_base_of  | 
469  |  | #endif  | 
470  |  |  | 
471  |  |     namespace cpl  | 
472  |  |     { | 
473  |  |     /** Use cpl::down_cast<Derived*>(pointer_to_base) as equivalent of  | 
474  |  |      * static_cast<Derived*>(pointer_to_base) with safe checking in debug  | 
475  |  |      * mode.  | 
476  |  |      *  | 
477  |  |      * Only works if no virtual inheritance is involved.  | 
478  |  |      *  | 
479  |  |      * @param f pointer to a base class  | 
480  |  |      * @return pointer to a derived class  | 
481  |  |      */  | 
482  |  |     template <typename To, typename From> inline To down_cast(From *f)  | 
483  | 61.8k  |     { | 
484  | 61.8k  |         static_assert(  | 
485  | 61.8k  |             (std::is_base_of<From,  | 
486  | 61.8k  |                              typename std::remove_pointer<To>::type>::value),  | 
487  | 61.8k  |             "target type not derived from source type");  | 
488  | 61.8k  |         CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr);  | 
489  | 61.8k  |         return static_cast<To>(f);  | 
490  | 61.8k  |     } Unexecuted instantiation: VSIGZipFilesystemHandler* cpl::down_cast<VSIGZipFilesystemHandler*, VSIFilesystemHandler>(VSIFilesystemHandler*) Unexecuted instantiation: OGRPolygon const* cpl::down_cast<OGRPolygon const*, OGRGeometry const>(OGRGeometry const*) OGRPoint* cpl::down_cast<OGRPoint*, OGRGeometry>(OGRGeometry*) Line  | Count  | Source  |  483  | 11.3k  |     { |  484  | 11.3k  |         static_assert(  |  485  | 11.3k  |             (std::is_base_of<From,  |  486  | 11.3k  |                              typename std::remove_pointer<To>::type>::value),  |  487  | 11.3k  |             "target type not derived from source type");  |  488  | 11.3k  |         CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr);  |  489  | 11.3k  |         return static_cast<To>(f);  |  490  | 11.3k  |     }  |  
 Unexecuted instantiation: OGRPoint const* cpl::down_cast<OGRPoint const*, OGRGeometry const>(OGRGeometry const*) OGRCurve* cpl::down_cast<OGRCurve*, OGRGeometry>(OGRGeometry*) Line  | Count  | Source  |  483  | 4.59k  |     { |  484  | 4.59k  |         static_assert(  |  485  | 4.59k  |             (std::is_base_of<From,  |  486  | 4.59k  |                              typename std::remove_pointer<To>::type>::value),  |  487  | 4.59k  |             "target type not derived from source type");  |  488  | 4.59k  |         CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr);  |  489  | 4.59k  |         return static_cast<To>(f);  |  490  | 4.59k  |     }  |  
 Unexecuted instantiation: OGRCurve const* cpl::down_cast<OGRCurve const*, OGRGeometry const>(OGRGeometry const*) OGRSimpleCurve* cpl::down_cast<OGRSimpleCurve*, OGRGeometry>(OGRGeometry*) Line  | Count  | Source  |  483  | 13.6k  |     { |  484  | 13.6k  |         static_assert(  |  485  | 13.6k  |             (std::is_base_of<From,  |  486  | 13.6k  |                              typename std::remove_pointer<To>::type>::value),  |  487  | 13.6k  |             "target type not derived from source type");  |  488  | 13.6k  |         CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr);  |  489  | 13.6k  |         return static_cast<To>(f);  |  490  | 13.6k  |     }  |  
 Unexecuted instantiation: OGRSimpleCurve const* cpl::down_cast<OGRSimpleCurve const*, OGRGeometry const>(OGRGeometry const*) Unexecuted instantiation: OGRLineString* cpl::down_cast<OGRLineString*, OGRGeometry>(OGRGeometry*) Unexecuted instantiation: OGRLineString const* cpl::down_cast<OGRLineString const*, OGRGeometry const>(OGRGeometry const*) Unexecuted instantiation: OGRLinearRing* cpl::down_cast<OGRLinearRing*, OGRGeometry>(OGRGeometry*) Unexecuted instantiation: OGRLinearRing const* cpl::down_cast<OGRLinearRing const*, OGRGeometry const>(OGRGeometry const*) Unexecuted instantiation: OGRCircularString* cpl::down_cast<OGRCircularString*, OGRGeometry>(OGRGeometry*) Unexecuted instantiation: OGRCircularString const* cpl::down_cast<OGRCircularString const*, OGRGeometry const>(OGRGeometry const*) OGRCompoundCurve* cpl::down_cast<OGRCompoundCurve*, OGRGeometry>(OGRGeometry*) Line  | Count  | Source  |  483  | 542  |     { |  484  | 542  |         static_assert(  |  485  | 542  |             (std::is_base_of<From,  |  486  | 542  |                              typename std::remove_pointer<To>::type>::value),  |  487  | 542  |             "target type not derived from source type");  |  488  | 542  |         CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr);  |  489  | 542  |         return static_cast<To>(f);  |  490  | 542  |     }  |  
 Unexecuted instantiation: OGRCompoundCurve const* cpl::down_cast<OGRCompoundCurve const*, OGRGeometry const>(OGRGeometry const*) OGRSurface* cpl::down_cast<OGRSurface*, OGRGeometry>(OGRGeometry*) Line  | Count  | Source  |  483  | 719  |     { |  484  | 719  |         static_assert(  |  485  | 719  |             (std::is_base_of<From,  |  486  | 719  |                              typename std::remove_pointer<To>::type>::value),  |  487  | 719  |             "target type not derived from source type");  |  488  | 719  |         CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr);  |  489  | 719  |         return static_cast<To>(f);  |  490  | 719  |     }  |  
 Unexecuted instantiation: OGRSurface const* cpl::down_cast<OGRSurface const*, OGRGeometry const>(OGRGeometry const*) OGRPolygon* cpl::down_cast<OGRPolygon*, OGRGeometry>(OGRGeometry*) Line  | Count  | Source  |  483  | 151  |     { |  484  | 151  |         static_assert(  |  485  | 151  |             (std::is_base_of<From,  |  486  | 151  |                              typename std::remove_pointer<To>::type>::value),  |  487  | 151  |             "target type not derived from source type");  |  488  | 151  |         CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr);  |  489  | 151  |         return static_cast<To>(f);  |  490  | 151  |     }  |  
 Unexecuted instantiation: OGRTriangle* cpl::down_cast<OGRTriangle*, OGRGeometry>(OGRGeometry*) Unexecuted instantiation: OGRTriangle const* cpl::down_cast<OGRTriangle const*, OGRGeometry const>(OGRGeometry const*) OGRCurvePolygon* cpl::down_cast<OGRCurvePolygon*, OGRGeometry>(OGRGeometry*) Line  | Count  | Source  |  483  | 17.6k  |     { |  484  | 17.6k  |         static_assert(  |  485  | 17.6k  |             (std::is_base_of<From,  |  486  | 17.6k  |                              typename std::remove_pointer<To>::type>::value),  |  487  | 17.6k  |             "target type not derived from source type");  |  488  | 17.6k  |         CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr);  |  489  | 17.6k  |         return static_cast<To>(f);  |  490  | 17.6k  |     }  |  
 Unexecuted instantiation: OGRCurvePolygon const* cpl::down_cast<OGRCurvePolygon const*, OGRGeometry const>(OGRGeometry const*) OGRGeometryCollection* cpl::down_cast<OGRGeometryCollection*, OGRGeometry>(OGRGeometry*) Line  | Count  | Source  |  483  | 11.5k  |     { |  484  | 11.5k  |         static_assert(  |  485  | 11.5k  |             (std::is_base_of<From,  |  486  | 11.5k  |                              typename std::remove_pointer<To>::type>::value),  |  487  | 11.5k  |             "target type not derived from source type");  |  488  | 11.5k  |         CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr);  |  489  | 11.5k  |         return static_cast<To>(f);  |  490  | 11.5k  |     }  |  
 Unexecuted instantiation: OGRGeometryCollection const* cpl::down_cast<OGRGeometryCollection const*, OGRGeometry const>(OGRGeometry const*) Unexecuted instantiation: OGRMultiPoint* cpl::down_cast<OGRMultiPoint*, OGRGeometry>(OGRGeometry*) Unexecuted instantiation: OGRMultiPoint const* cpl::down_cast<OGRMultiPoint const*, OGRGeometry const>(OGRGeometry const*) Unexecuted instantiation: OGRMultiLineString* cpl::down_cast<OGRMultiLineString*, OGRGeometry>(OGRGeometry*) Unexecuted instantiation: OGRMultiLineString const* cpl::down_cast<OGRMultiLineString const*, OGRGeometry const>(OGRGeometry const*) Unexecuted instantiation: OGRMultiPolygon* cpl::down_cast<OGRMultiPolygon*, OGRGeometry>(OGRGeometry*) Unexecuted instantiation: OGRMultiPolygon const* cpl::down_cast<OGRMultiPolygon const*, OGRGeometry const>(OGRGeometry const*) OGRMultiCurve* cpl::down_cast<OGRMultiCurve*, OGRGeometry>(OGRGeometry*) Line  | Count  | Source  |  483  | 952  |     { |  484  | 952  |         static_assert(  |  485  | 952  |             (std::is_base_of<From,  |  486  | 952  |                              typename std::remove_pointer<To>::type>::value),  |  487  | 952  |             "target type not derived from source type");  |  488  | 952  |         CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr);  |  489  | 952  |         return static_cast<To>(f);  |  490  | 952  |     }  |  
 Unexecuted instantiation: OGRMultiCurve const* cpl::down_cast<OGRMultiCurve const*, OGRGeometry const>(OGRGeometry const*) Unexecuted instantiation: OGRMultiSurface* cpl::down_cast<OGRMultiSurface*, OGRGeometry>(OGRGeometry*) Unexecuted instantiation: OGRMultiSurface const* cpl::down_cast<OGRMultiSurface const*, OGRGeometry const>(OGRGeometry const*) Unexecuted instantiation: OGRPolyhedralSurface* cpl::down_cast<OGRPolyhedralSurface*, OGRGeometry>(OGRGeometry*) Unexecuted instantiation: OGRPolyhedralSurface const* cpl::down_cast<OGRPolyhedralSurface const*, OGRGeometry const>(OGRGeometry const*) Unexecuted instantiation: OGRTriangulatedSurface* cpl::down_cast<OGRTriangulatedSurface*, OGRGeometry>(OGRGeometry*) Unexecuted instantiation: OGRTriangulatedSurface const* cpl::down_cast<OGRTriangulatedSurface const*, OGRGeometry const>(OGRGeometry const*) OGRSimpleCurve* cpl::down_cast<OGRSimpleCurve*, OGRCurve>(OGRCurve*) Line  | Count  | Source  |  483  | 714  |     { |  484  | 714  |         static_assert(  |  485  | 714  |             (std::is_base_of<From,  |  486  | 714  |                              typename std::remove_pointer<To>::type>::value),  |  487  | 714  |             "target type not derived from source type");  |  488  | 714  |         CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr);  |  489  | 714  |         return static_cast<To>(f);  |  490  | 714  |     }  |  
 Unexecuted instantiation: OGRSimpleCurve const* cpl::down_cast<OGRSimpleCurve const*, OGRCurve const>(OGRCurve const*) Unexecuted instantiation: OGRLinearRing* cpl::down_cast<OGRLinearRing*, OGRCurve>(OGRCurve*) Unexecuted instantiation: OGRCodedFieldDomain* cpl::down_cast<OGRCodedFieldDomain*, OGRFieldDomain>(OGRFieldDomain*) Unexecuted instantiation: GDALProxyPoolDataset* cpl::down_cast<GDALProxyPoolDataset*, GDALDataset>(GDALDataset*) Unexecuted instantiation: GDALOverviewBand* cpl::down_cast<GDALOverviewBand*, GDALRasterBand>(GDALRasterBand*) Unexecuted instantiation: GDALOverviewDataset* cpl::down_cast<GDALOverviewDataset*, GDALDataset>(GDALDataset*) Unexecuted instantiation: VRTSourcedRasterBand* cpl::down_cast<VRTSourcedRasterBand*, GDALRasterBand>(GDALRasterBand*) Unexecuted instantiation: GDALMDArrayResampledDataset* cpl::down_cast<GDALMDArrayResampledDataset*, GDALDataset>(GDALDataset*) Unexecuted instantiation: GDALDatasetFromArray* cpl::down_cast<GDALDatasetFromArray*, GDALDataset>(GDALDataset*) Unexecuted instantiation: MEMRasterBand* cpl::down_cast<MEMRasterBand*, GDALRasterBand>(GDALRasterBand*) Unexecuted instantiation: VRTDataset* cpl::down_cast<VRTDataset*, GDALDataset>(GDALDataset*) Unexecuted instantiation: VRTSimpleSource* cpl::down_cast<VRTSimpleSource*, VRTSource>(VRTSource*) Unexecuted instantiation: VRTComplexSource* cpl::down_cast<VRTComplexSource*, VRTSource>(VRTSource*) Unexecuted instantiation: GDALProxyPoolRasterBand* cpl::down_cast<GDALProxyPoolRasterBand*, GDALRasterBand>(GDALRasterBand*) Unexecuted instantiation: VRTRasterBand* cpl::down_cast<VRTRasterBand*, GDALRasterBand>(GDALRasterBand*) Unexecuted instantiation: VRTComplexSource* cpl::down_cast<VRTComplexSource*, VRTSimpleSource>(VRTSimpleSource*) Unexecuted instantiation: VRTSourcedRasterBand* cpl::down_cast<VRTSourcedRasterBand*, VRTRasterBand>(VRTRasterBand*) Unexecuted instantiation: VRTProcessedDataset* cpl::down_cast<VRTProcessedDataset*, GDALDataset>(GDALDataset*) Unexecuted instantiation: OGRShapeLayer* cpl::down_cast<OGRShapeLayer*, OGRLayer>(OGRLayer*) Unexecuted instantiation: OGRShapeGeomFieldDefn* cpl::down_cast<OGRShapeGeomFieldDefn*, OGRGeomFieldDefn>(OGRGeomFieldDefn*) Unexecuted instantiation: OGRGenSQLGeomFieldDefn* cpl::down_cast<OGRGenSQLGeomFieldDefn*, OGRGeomFieldDefn>(OGRGeomFieldDefn*) Unexecuted instantiation: OGRUnionLayerGeomFieldDefn* cpl::down_cast<OGRUnionLayerGeomFieldDefn*, OGRGeomFieldDefn>(OGRGeomFieldDefn*) Unexecuted instantiation: GDALInConstructionAlgorithmArg* cpl::down_cast<GDALInConstructionAlgorithmArg*, GDALAlgorithmArg>(GDALAlgorithmArg*) Unexecuted instantiation: GDALPamRasterBand* cpl::down_cast<GDALPamRasterBand*, GDALRasterBand>(GDALRasterBand*) Unexecuted instantiation: RawRasterBand* cpl::down_cast<RawRasterBand*, GDALRasterBand>(GDALRasterBand*) Unexecuted instantiation: OGRCodedFieldDomain const* cpl::down_cast<OGRCodedFieldDomain const*, OGRFieldDomain const>(OGRFieldDomain const*) Unexecuted instantiation: GTiffRasterBand* cpl::down_cast<GTiffRasterBand*, GDALRasterBand>(GDALRasterBand*) Unexecuted instantiation: GTiffDataset* cpl::down_cast<GTiffDataset*, GDALDataset>(GDALDataset*) Unexecuted instantiation: GTiffJPEGOverviewDS* cpl::down_cast<GTiffJPEGOverviewDS*, GDALDataset>(GDALDataset*) Unexecuted instantiation: GTiffOddBitsBand* cpl::down_cast<GTiffOddBitsBand*, GDALRasterBand>(GDALRasterBand*)  | 
491  |  |  | 
492  |  |     /** Computes ceil(a/b) where a and b are integers */  | 
493  |  |     template <class T, class U> inline T div_round_up(T a, U b)  | 
494  | 2.37k  |     { | 
495  | 2.37k  |         return a / b + (((a % b) == 0) ? 0 : 1);  | 
496  | 2.37k  |     }  | 
497  |  |  | 
498  |  |     }  // namespace cpl  | 
499  |  | }  // extern "C++"  | 
500  |  |  | 
501  |  | #endif /* def __cplusplus */  | 
502  |  |  | 
503  |  | #endif /* ndef CPL_CONV_H_INCLUDED */  |