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