/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 | 301k | #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 | | /* -------------------------------------------------------------------- */ |
246 | | /* Find File Function */ |
247 | | /* -------------------------------------------------------------------- */ |
248 | | |
249 | | /** Callback for CPLPushFileFinder */ |
250 | | typedef char const *(*CPLFileFinder)(const char *, const char *); |
251 | | |
252 | | const char CPL_DLL *CPLFindFile(const char *pszClass, const char *pszBasename); |
253 | | const char CPL_DLL *CPLDefaultFindFile(const char *pszClass, |
254 | | const char *pszBasename); |
255 | | void CPL_DLL CPLPushFileFinder(CPLFileFinder pfnFinder); |
256 | | CPLFileFinder CPL_DLL CPLPopFileFinder(void); |
257 | | void CPL_DLL CPLPushFinderLocation(const char *); |
258 | | void CPL_DLL CPLPopFinderLocation(void); |
259 | | void CPL_DLL CPLFinderClean(void); |
260 | | |
261 | | /* -------------------------------------------------------------------- */ |
262 | | /* Safe version of stat() that works properly on stuff like "C:". */ |
263 | | /* -------------------------------------------------------------------- */ |
264 | | int CPL_DLL CPLStat(const char *, VSIStatBuf *) CPL_WARN_UNUSED_RESULT; |
265 | | |
266 | | /* -------------------------------------------------------------------- */ |
267 | | /* Reference counted file handle manager. Makes sharing file */ |
268 | | /* handles more practical. */ |
269 | | /* -------------------------------------------------------------------- */ |
270 | | |
271 | | /** Information on a shared file */ |
272 | | typedef struct |
273 | | { |
274 | | FILE *fp; /**< File pointer */ |
275 | | int nRefCount; /**< Reference counter */ |
276 | | int bLarge; /**< Whether fp must be interpreted as VSIFILE* */ |
277 | | char *pszFilename; /**< Filename */ |
278 | | char *pszAccess; /**< Access mode */ |
279 | | } CPLSharedFileInfo; |
280 | | |
281 | | FILE CPL_DLL *CPLOpenShared(const char *, const char *, int); |
282 | | void CPL_DLL CPLCloseShared(FILE *); |
283 | | CPLSharedFileInfo CPL_DLL *CPLGetSharedList(int *); |
284 | | void CPL_DLL CPLDumpSharedList(FILE *); |
285 | | /*! @cond Doxygen_Suppress */ |
286 | | void CPL_DLL CPLCleanupSharedFileMutex(void); |
287 | | /*! @endcond */ |
288 | | |
289 | | /* -------------------------------------------------------------------- */ |
290 | | /* DMS to Dec to DMS conversion. */ |
291 | | /* -------------------------------------------------------------------- */ |
292 | | double CPL_DLL CPLDMSToDec(const char *is); |
293 | | const char CPL_DLL *CPLDecToDMS(double dfAngle, const char *pszAxis, |
294 | | int nPrecision); |
295 | | double CPL_DLL CPLPackedDMSToDec(double); |
296 | | double CPL_DLL CPLDecToPackedDMS(double dfDec); |
297 | | |
298 | | CPLErr CPL_DLL CPLStringToComplex(const char *pszString, double *pdfReal, |
299 | | double *pdfImag); |
300 | | |
301 | | /* -------------------------------------------------------------------- */ |
302 | | /* Misc other functions. */ |
303 | | /* -------------------------------------------------------------------- */ |
304 | | int CPL_DLL CPLUnlinkTree(const char *); |
305 | | int CPL_DLL CPLCopyFile(const char *pszNewPath, const char *pszOldPath); |
306 | | int CPL_DLL CPLCopyTree(const char *pszNewPath, const char *pszOldPath); |
307 | | int CPL_DLL CPLMoveFile(const char *pszNewPath, const char *pszOldPath); |
308 | | int CPL_DLL CPLSymlink(const char *pszOldPath, const char *pszNewPath, |
309 | | CSLConstList papszOptions); |
310 | | |
311 | | /* -------------------------------------------------------------------- */ |
312 | | /* Lock related functions. */ |
313 | | /* -------------------------------------------------------------------- */ |
314 | | |
315 | | /** Return code of CPLLockFileEx(). */ |
316 | | typedef enum |
317 | | { |
318 | | CLFS_OK, /**< CPLLockFileEx() succeeded. */ |
319 | | CLFS_CANNOT_CREATE_LOCK, /**< Lock file creation failed. */ |
320 | | CLFS_LOCK_BUSY, /**< Lock already taken (and still alive). */ |
321 | | CLFS_API_MISUSE, /**< API misuse. */ |
322 | | CLFS_THREAD_CREATION_FAILED, /**< Thread creation failed. */ |
323 | | } CPLLockFileStatus; |
324 | | |
325 | | /** Handle type returned by CPLLockFileEx(). */ |
326 | | typedef struct CPLLockFileStruct *CPLLockFileHandle; |
327 | | |
328 | | CPLLockFileStatus CPL_DLL CPLLockFileEx(const char *pszLockFileName, |
329 | | CPLLockFileHandle *phLockFileHandle, |
330 | | CSLConstList papszOptions); |
331 | | |
332 | | void CPL_DLL CPLUnlockFileEx(CPLLockFileHandle hLockFileHandle); |
333 | | |
334 | | /* -------------------------------------------------------------------- */ |
335 | | /* ZIP Creation. */ |
336 | | /* -------------------------------------------------------------------- */ |
337 | | |
338 | | /*! @cond Doxygen_Suppress */ |
339 | | #define CPL_ZIP_API_OFFERED |
340 | | /*! @endcond */ |
341 | | void CPL_DLL *CPLCreateZip(const char *pszZipFilename, char **papszOptions); |
342 | | CPLErr CPL_DLL CPLCreateFileInZip(void *hZip, const char *pszFilename, |
343 | | char **papszOptions); |
344 | | CPLErr CPL_DLL CPLWriteFileInZip(void *hZip, const void *pBuffer, |
345 | | int nBufferSize); |
346 | | CPLErr CPL_DLL CPLCloseFileInZip(void *hZip); |
347 | | CPLErr CPL_DLL CPLAddFileInZip(void *hZip, const char *pszArchiveFilename, |
348 | | const char *pszInputFilename, VSILFILE *fpInput, |
349 | | CSLConstList papszOptions, |
350 | | GDALProgressFunc pProgressFunc, |
351 | | void *pProgressData); |
352 | | CPLErr CPL_DLL CPLCloseZip(void *hZip); |
353 | | |
354 | | /* -------------------------------------------------------------------- */ |
355 | | /* ZLib compression */ |
356 | | /* -------------------------------------------------------------------- */ |
357 | | |
358 | | void CPL_DLL *CPLZLibDeflate(const void *ptr, size_t nBytes, int nLevel, |
359 | | void *outptr, size_t nOutAvailableBytes, |
360 | | size_t *pnOutBytes); |
361 | | void CPL_DLL *CPLZLibInflate(const void *ptr, size_t nBytes, void *outptr, |
362 | | size_t nOutAvailableBytes, size_t *pnOutBytes); |
363 | | void CPL_DLL *CPLZLibInflateEx(const void *ptr, size_t nBytes, void *outptr, |
364 | | size_t nOutAvailableBytes, |
365 | | bool bAllowResizeOutptr, size_t *pnOutBytes); |
366 | | |
367 | | /* -------------------------------------------------------------------- */ |
368 | | /* XML validation. */ |
369 | | /* -------------------------------------------------------------------- */ |
370 | | int CPL_DLL CPLValidateXML(const char *pszXMLFilename, |
371 | | const char *pszXSDFilename, |
372 | | CSLConstList papszOptions); |
373 | | |
374 | | /* -------------------------------------------------------------------- */ |
375 | | /* Locale handling. Prevents parallel executions of setlocale(). */ |
376 | | /* -------------------------------------------------------------------- */ |
377 | | char *CPLsetlocale(int category, const char *locale); |
378 | | /*! @cond Doxygen_Suppress */ |
379 | | void CPLCleanupSetlocaleMutex(void); |
380 | | /*! @endcond */ |
381 | | |
382 | | /*! |
383 | | CPLIsPowerOfTwo() |
384 | | @param i - tested number |
385 | | @return TRUE if i is power of two otherwise return FALSE |
386 | | */ |
387 | | int CPL_DLL CPLIsPowerOfTwo(unsigned int i); |
388 | | |
389 | | /* -------------------------------------------------------------------- */ |
390 | | /* Terminal related */ |
391 | | /* -------------------------------------------------------------------- */ |
392 | | |
393 | | bool CPL_DLL CPLIsInteractive(FILE *f); |
394 | | |
395 | | CPL_C_END |
396 | | |
397 | | /* -------------------------------------------------------------------- */ |
398 | | /* C++ object for temporarily forcing a LC_NUMERIC locale to "C". */ |
399 | | /* -------------------------------------------------------------------- */ |
400 | | |
401 | | //! @cond Doxygen_Suppress |
402 | | #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) |
403 | | |
404 | | extern "C++" |
405 | | { |
406 | | class CPL_DLL CPLLocaleC |
407 | | { |
408 | | CPL_DISALLOW_COPY_ASSIGN(CPLLocaleC) |
409 | | public: |
410 | | CPLLocaleC(); |
411 | | ~CPLLocaleC(); |
412 | | |
413 | | private: |
414 | | char *pszOldLocale; |
415 | | }; |
416 | | |
417 | | // Does the same as CPLLocaleC except that, when available, it tries to |
418 | | // only affect the current thread. But code that would be dependent of |
419 | | // setlocale(LC_NUMERIC, NULL) returning "C", such as current proj.4 |
420 | | // versions, will not work depending on the actual implementation |
421 | | class CPLThreadLocaleCPrivate; |
422 | | |
423 | | class CPL_DLL CPLThreadLocaleC |
424 | | { |
425 | | CPL_DISALLOW_COPY_ASSIGN(CPLThreadLocaleC) |
426 | | |
427 | | public: |
428 | | CPLThreadLocaleC(); |
429 | | ~CPLThreadLocaleC(); |
430 | | |
431 | | private: |
432 | | CPLThreadLocaleCPrivate *m_private; |
433 | | }; |
434 | | } |
435 | | |
436 | | #endif /* def __cplusplus */ |
437 | | //! @endcond |
438 | | |
439 | | /* -------------------------------------------------------------------- */ |
440 | | /* C++ object for temporarily forcing a config option */ |
441 | | /* -------------------------------------------------------------------- */ |
442 | | |
443 | | //! @cond Doxygen_Suppress |
444 | | #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) |
445 | | |
446 | | extern "C++" |
447 | | { |
448 | | class CPL_DLL CPLConfigOptionSetter |
449 | | { |
450 | | CPL_DISALLOW_COPY_ASSIGN(CPLConfigOptionSetter) |
451 | | public: |
452 | | CPLConfigOptionSetter(const char *pszKey, const char *pszValue, |
453 | | bool bSetOnlyIfUndefined); |
454 | | ~CPLConfigOptionSetter(); |
455 | | |
456 | | private: |
457 | | char *m_pszKey; |
458 | | char *m_pszOldValue; |
459 | | bool m_bRestoreOldValue; |
460 | | }; |
461 | | } |
462 | | |
463 | | #endif /* def __cplusplus */ |
464 | | //! @endcond |
465 | | |
466 | | #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) |
467 | | |
468 | | extern "C++" |
469 | | { |
470 | | |
471 | | #ifndef DOXYGEN_SKIP |
472 | | #include <type_traits> // for std::is_base_of |
473 | | #endif |
474 | | |
475 | | namespace cpl |
476 | | { |
477 | | /** Use cpl::down_cast<Derived*>(pointer_to_base) as equivalent of |
478 | | * static_cast<Derived*>(pointer_to_base) with safe checking in debug |
479 | | * mode. |
480 | | * |
481 | | * Only works if no virtual inheritance is involved. |
482 | | * |
483 | | * @param f pointer to a base class |
484 | | * @return pointer to a derived class |
485 | | */ |
486 | | template <typename To, typename From> inline To down_cast(From *f) |
487 | 43.3k | { |
488 | 43.3k | static_assert( |
489 | 43.3k | (std::is_base_of<From, |
490 | 43.3k | typename std::remove_pointer<To>::type>::value), |
491 | 43.3k | "target type not derived from source type"); |
492 | 43.3k | CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr); |
493 | 43.3k | return static_cast<To>(f); |
494 | 43.3k | } 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 | 487 | 11.5k | { | 488 | 11.5k | static_assert( | 489 | 11.5k | (std::is_base_of<From, | 490 | 11.5k | typename std::remove_pointer<To>::type>::value), | 491 | 11.5k | "target type not derived from source type"); | 492 | 11.5k | CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr); | 493 | 11.5k | return static_cast<To>(f); | 494 | 11.5k | } |
Unexecuted instantiation: OGRPoint const* cpl::down_cast<OGRPoint const*, OGRGeometry const>(OGRGeometry const*) OGRCurve* cpl::down_cast<OGRCurve*, OGRGeometry>(OGRGeometry*) Line | Count | Source | 487 | 2.70k | { | 488 | 2.70k | static_assert( | 489 | 2.70k | (std::is_base_of<From, | 490 | 2.70k | typename std::remove_pointer<To>::type>::value), | 491 | 2.70k | "target type not derived from source type"); | 492 | 2.70k | CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr); | 493 | 2.70k | return static_cast<To>(f); | 494 | 2.70k | } |
Unexecuted instantiation: OGRCurve const* cpl::down_cast<OGRCurve const*, OGRGeometry const>(OGRGeometry const*) OGRSimpleCurve* cpl::down_cast<OGRSimpleCurve*, OGRGeometry>(OGRGeometry*) Line | Count | Source | 487 | 8.24k | { | 488 | 8.24k | static_assert( | 489 | 8.24k | (std::is_base_of<From, | 490 | 8.24k | typename std::remove_pointer<To>::type>::value), | 491 | 8.24k | "target type not derived from source type"); | 492 | 8.24k | CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr); | 493 | 8.24k | return static_cast<To>(f); | 494 | 8.24k | } |
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 | 487 | 428 | { | 488 | 428 | static_assert( | 489 | 428 | (std::is_base_of<From, | 490 | 428 | typename std::remove_pointer<To>::type>::value), | 491 | 428 | "target type not derived from source type"); | 492 | 428 | CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr); | 493 | 428 | return static_cast<To>(f); | 494 | 428 | } |
Unexecuted instantiation: OGRCompoundCurve const* cpl::down_cast<OGRCompoundCurve const*, OGRGeometry const>(OGRGeometry const*) OGRSurface* cpl::down_cast<OGRSurface*, OGRGeometry>(OGRGeometry*) Line | Count | Source | 487 | 382 | { | 488 | 382 | static_assert( | 489 | 382 | (std::is_base_of<From, | 490 | 382 | typename std::remove_pointer<To>::type>::value), | 491 | 382 | "target type not derived from source type"); | 492 | 382 | CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr); | 493 | 382 | return static_cast<To>(f); | 494 | 382 | } |
Unexecuted instantiation: OGRSurface const* cpl::down_cast<OGRSurface const*, OGRGeometry const>(OGRGeometry const*) OGRPolygon* cpl::down_cast<OGRPolygon*, OGRGeometry>(OGRGeometry*) Line | Count | Source | 487 | 129 | { | 488 | 129 | static_assert( | 489 | 129 | (std::is_base_of<From, | 490 | 129 | typename std::remove_pointer<To>::type>::value), | 491 | 129 | "target type not derived from source type"); | 492 | 129 | CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr); | 493 | 129 | return static_cast<To>(f); | 494 | 129 | } |
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 | 487 | 9.90k | { | 488 | 9.90k | static_assert( | 489 | 9.90k | (std::is_base_of<From, | 490 | 9.90k | typename std::remove_pointer<To>::type>::value), | 491 | 9.90k | "target type not derived from source type"); | 492 | 9.90k | CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr); | 493 | 9.90k | return static_cast<To>(f); | 494 | 9.90k | } |
Unexecuted instantiation: OGRCurvePolygon const* cpl::down_cast<OGRCurvePolygon const*, OGRGeometry const>(OGRGeometry const*) OGRGeometryCollection* cpl::down_cast<OGRGeometryCollection*, OGRGeometry>(OGRGeometry*) Line | Count | Source | 487 | 8.79k | { | 488 | 8.79k | static_assert( | 489 | 8.79k | (std::is_base_of<From, | 490 | 8.79k | typename std::remove_pointer<To>::type>::value), | 491 | 8.79k | "target type not derived from source type"); | 492 | 8.79k | CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr); | 493 | 8.79k | return static_cast<To>(f); | 494 | 8.79k | } |
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 | 487 | 621 | { | 488 | 621 | static_assert( | 489 | 621 | (std::is_base_of<From, | 490 | 621 | typename std::remove_pointer<To>::type>::value), | 491 | 621 | "target type not derived from source type"); | 492 | 621 | CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr); | 493 | 621 | return static_cast<To>(f); | 494 | 621 | } |
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 | 487 | 579 | { | 488 | 579 | static_assert( | 489 | 579 | (std::is_base_of<From, | 490 | 579 | typename std::remove_pointer<To>::type>::value), | 491 | 579 | "target type not derived from source type"); | 492 | 579 | CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr); | 493 | 579 | return static_cast<To>(f); | 494 | 579 | } |
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: 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: 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*) |
495 | | |
496 | | /** Computes ceil(a/b) where a and b are integers */ |
497 | | template <class T, class U> inline T div_round_up(T a, U b) |
498 | 1.54k | { |
499 | 1.54k | return a / b + (((a % b) == 0) ? 0 : 1); |
500 | 1.54k | } |
501 | | |
502 | | } // namespace cpl |
503 | | } // extern "C++" |
504 | | |
505 | | #endif /* def __cplusplus */ |
506 | | |
507 | | #endif /* ndef CPL_CONV_H_INCLUDED */ |