15#ifndef CPL_CONV_H_INCLUDED
16#define CPL_CONV_H_INCLUDED
22#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
39void CPL_DLL CPLVerifyConfiguration(
void);
42bool CPL_DLL CPLIsDebugEnabled(
void);
49#define CPL_NULL_VALUE "__CPL_NULL_VALUE__"
51const char CPL_DLL *CPL_STDCALL CPLGetConfigOption(
const char *,
const char *)
53const char CPL_DLL *CPL_STDCALL CPLGetThreadLocalConfigOption(
55const char CPL_DLL *CPL_STDCALL
57void CPL_DLL CPL_STDCALL CPLSetConfigOption(
const char *,
const char *);
58void CPL_DLL CPL_STDCALL CPLSetThreadLocalConfigOption(
const char *pszKey,
59 const char *pszValue);
60void CPL_DLL CPLDeclareKnownConfigOption(
const char *pszKey,
61 const char *pszDefinition);
62char CPL_DLL **CPLGetKnownConfigOptions(
void);
69int CPL_DLL CPLSubscribeToSetConfigOption(
71void CPL_DLL CPLUnsubscribeToSetConfigOption(
int nSubscriberId);
74void CPL_DLL CPL_STDCALL CPLFreeConfig(
void);
76char CPL_DLL **CPLGetConfigOptions(
void);
77void CPL_DLL CPLSetConfigOptions(
const char *
const *papszConfigOptions);
78char CPL_DLL **CPLGetThreadLocalConfigOptions(
void);
80CPLSetThreadLocalConfigOptions(
const char *
const *papszConfigOptions);
81void CPL_DLL CPLLoadConfigOptionsFromFile(
const char *pszFilename,
82 int bOverrideEnvVars);
83void CPL_DLL CPLLoadConfigOptionsFromPredefinedFiles(
void);
94char CPL_DLL *CPLStrlwr(
char *);
97#define CPLFree VSIFree
102char CPL_DLL *CPLFGets(
char *,
int, FILE *);
103const char CPL_DLL *CPLReadLine(FILE *);
104const char CPL_DLL *CPLReadLineL(
VSILFILE *);
112double CPL_DLL
CPLAtof(
const char *);
114double CPL_DLL
CPLStrtod(
const char *,
char **);
115double CPL_DLL
CPLStrtodM(
const char *,
char **);
117float CPL_DLL
CPLStrtof(
const char *,
char **);
124double CPL_DLL
CPLAtofM(
const char *);
129char CPL_DLL *CPLScanString(
const char *,
int,
int,
int);
130double CPL_DLL CPLScanDouble(
const char *,
int);
131long CPL_DLL CPLScanLong(
const char *,
int);
132unsigned long CPL_DLL CPLScanULong(
const char *,
int);
133GUIntBig CPL_DLL CPLScanUIntBig(
const char *,
int);
134GIntBig CPL_DLL CPLAtoGIntBig(
const char *pszString);
135GIntBig CPL_DLL CPLAtoGIntBigEx(
const char *pszString,
int bWarn,
137void CPL_DLL *CPLScanPointer(
const char *,
int);
142int CPL_DLL CPLPrintString(
char *,
const char *,
int);
143int CPL_DLL CPLPrintStringFill(
char *,
const char *,
int);
144int CPL_DLL CPLPrintInt32(
char *,
GInt32,
int);
145int CPL_DLL CPLPrintUIntBig(
char *,
GUIntBig,
int);
146int CPL_DLL CPLPrintDouble(
char *,
const char *,
double,
const char *);
147int CPL_DLL CPLPrintTime(
char *,
int,
const char *,
const struct tm *,
149int CPL_DLL CPLPrintPointer(
char *,
void *,
int);
151#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
154 std::string CPL_DLL CPLFormatReadableFileSize(uint64_t nSizeInBytes);
155 std::string CPL_DLL CPLFormatReadableFileSize(
double dfSizeInBytes);
174#if defined(DOXYGEN_SKIP) || !defined(__cplusplus) || \
175 !defined(GDAL_COMPILATION) || \
176 (defined(__cplusplus) && defined(ALLOW_DEPRECATED_CPL_PATH_FUNCTIONS))
186 const char *pszPath,
const char *pszBasename,
189 const char *pszPath,
const char *pszBasename,
194 const char *pszSecondaryFilename)
216int CPL_DLL CPLCheckForFile(
char *pszFilename,
CSLConstList papszSiblingList);
220#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
230 const char *pszPath,
const char *pszBasename,
233 const
char *pszPath, const
char *pszBasename,
238 const
char *pszProjectDir,
249 const std::
string &osName,
char chReplacementChar =
'_',
250 const
char *pszExtraReservedCharacters =
nullptr)
253#if defined(GDAL_COMPILATION) || __cplusplus >= 201703L
255 CPL_DLL CPLLexicallyNormalize(std::string_view svPath,
char sep1,
270typedef char const *(*CPLFileFinder)(
const char *,
const char *);
272const char CPL_DLL *
CPLFindFile(
const char *pszClass,
const char *pszBasename);
274 const char *pszBasename);
301FILE CPL_DLL *CPLOpenShared(
const char *,
const char *,
int);
302void CPL_DLL CPLCloseShared(FILE *);
304void CPL_DLL CPLDumpSharedList(FILE *);
306void CPL_DLL CPLCleanupSharedFileMutex(
void);
312double CPL_DLL CPLDMSToDec(
const char *is);
313const char CPL_DLL *CPLDecToDMS(
double dfAngle,
const char *pszAxis,
315double CPL_DLL CPLPackedDMSToDec(
double);
316double CPL_DLL CPLDecToPackedDMS(
double dfDec);
318CPLErr CPL_DLL CPLStringToComplex(
const char *pszString,
double *pdfReal,
324int CPL_DLL CPLUnlinkTree(
const char *);
325int CPL_DLL CPLCopyFile(
const char *pszNewPath,
const char *pszOldPath);
326int CPL_DLL CPLCopyTree(
const char *pszNewPath,
const char *pszOldPath);
327int CPL_DLL CPLMoveFile(
const char *pszNewPath,
const char *pszOldPath);
328int CPL_DLL CPLSymlink(
const char *pszOldPath,
const char *pszNewPath,
330int CPL_DLL CPLGetRemainingFileDescriptorCount(
void);
360#define CPL_ZIP_API_OFFERED
362void CPL_DLL *CPLCreateZip(
const char *pszZipFilename,
char **papszOptions);
363CPLErr CPL_DLL CPLCreateFileInZip(
void *hZip,
const char *pszFilename,
364 char **papszOptions);
365CPLErr CPL_DLL CPLWriteFileInZip(
void *hZip,
const void *pBuffer,
367CPLErr CPL_DLL CPLCloseFileInZip(
void *hZip);
369 const char *pszInputFilename,
VSILFILE *fpInput,
371 GDALProgressFunc pProgressFunc,
372 void *pProgressData);
373CPLErr CPL_DLL CPLCloseZip(
void *hZip);
379void CPL_DLL *CPLZLibDeflate(
const void *ptr,
size_t nBytes,
int nLevel,
380 void *outptr,
size_t nOutAvailableBytes,
382void CPL_DLL *CPLZLibInflate(
const void *ptr,
size_t nBytes,
void *outptr,
383 size_t nOutAvailableBytes,
size_t *pnOutBytes);
385 size_t nOutAvailableBytes,
386 bool bAllowResizeOutptr,
size_t *pnOutBytes);
392 const char *pszXSDFilename,
398char *CPLsetlocale(
int category,
const char *locale);
400void CPLCleanupSetlocaleMutex(
void);
408int CPL_DLL CPLIsPowerOfTwo(
unsigned int i);
414bool CPL_DLL CPLIsInteractive(FILE *f);
423#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
427 class CPL_DLL CPLLocaleC
442 class CPLThreadLocaleCPrivate;
444 class CPL_DLL CPLThreadLocaleC
453 CPLThreadLocaleCPrivate *m_private;
465#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
469 class CPL_DLL CPLConfigOptionSetter
473 CPLConfigOptionSetter(
const char *pszKey,
const char *pszValue,
474 bool bSetOnlyIfUndefined);
475 ~CPLConfigOptionSetter();
480 bool m_bRestoreOldValue;
487#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
493#include <type_traits>
507 template <
typename To,
typename From>
inline To
down_cast(From *f)
510 (std::is_base_of<From,
511 typename std::remove_pointer<To>::type>::value),
512 "target type not derived from source type");
513 CPLAssert(f ==
nullptr ||
dynamic_cast<To
>(f) !=
nullptr);
514 return static_cast<To
>(f);
520 return a / b + (((a % b) == 0) ? 0 : 1);
std::string CPLGenerateTempFilenameSafe(const char *pszStem)
Generate temporary file name.
Definition cpl_path.cpp:1457
const char * CPLGetHomeDir(void)
Return the path to the home directory.
Definition cpl_path.cpp:1574
const char * CPLExpandTilde(const char *pszFilename)
Expands ~/ at start of filename.
Definition cpl_path.cpp:1553
char const *(*) CPLFileFinder(const char *, const char *)
Callback for CPLPushFileFinder.
Definition cpl_conv.h:270
double CPLAtofDelim(const char *, char)
Converts ASCII string to floating point number.
Definition cpl_strtod.cpp:58
void(*) CPLSetConfigOptionSubscriber(const char *pszKey, const char *pszValue, bool bThreadLocal, void *pUserData)
Callback for CPLSubscribeToSetConfigOption().
Definition cpl_conv.h:65
void * CPLGetSymbol(const char *, const char *)
Fetch a function pointer from a shared library / DLL.
Definition cplgetsymbol.cpp:74
int CPLIsFilenameRelative(const char *pszFilename)
Is filename relative or absolute?
Definition cpl_path.cpp:1113
std::string CPLFormCIFilenameSafe(const char *pszPath, const char *pszBasename, const char *pszExtension=nullptr)
Case insensitive file searching, returning full path.
Definition cpl_path.cpp:896
std::string CPLLaunderForFilenameSafe(const char *pszName, const char *pszOutputPath)
Launder a string to be compatible of a filename.
Definition cpl_path.cpp:1599
std::string CPLProjectRelativeFilenameSafe(const char *pszProjectDir, const char *pszSecondaryFilename)
Find a file relative to a project file.
Definition cpl_path.cpp:1035
float CPLStrtof(const char *, char **)
Converts ASCII string to floating point number.
Definition cpl_strtod.cpp:496
double CPLStrtod(const char *, char **)
Converts ASCII string to floating point number.
Definition cpl_strtod.cpp:388
T div_round_up(T a, U b)
Computes ceil(a/b) where a and b are integers.
Definition cpl_conv.h:518
struct CPLLockFileStruct * CPLLockFileHandle
Handle type returned by CPLLockFileEx().
Definition cpl_conv.h:347
const char * CPLGetExtension(const char *)
Extract filename extension from full filename.
Definition cpl_path.cpp:549
std::string CPLGetExtensionSafe(const char *)
Extract filename extension from full filename.
Definition cpl_path.cpp:498
std::string CPLResetExtensionSafe(const char *, const char *)
Replace the extension with the provided one.
Definition cpl_path.cpp:620
std::string CPLExpandTildeSafe(const char *pszFilename)
Expands ~/ at start of filename.
Definition cpl_path.cpp:1523
std::string CPLGetBasenameSafe(const char *)
Extract basename (non-directory, non-extension) portion of filename.
Definition cpl_path.cpp:423
std::string CPLGetDirnameSafe(const char *)
Extract directory path portion of filename.
Definition cpl_path.cpp:274
float CPLStrtofDelim(const char *, char **, char)
Converts ASCII string to floating point number using specified delimiter.
Definition cpl_strtod.cpp:452
char ** CPLCorrespondingPaths(const char *pszOldFilename, const char *pszNewFilename, CSLConstList papszFileList)
Identify corresponding paths.
Definition cpl_path.cpp:1317
const char * CPLGetBasename(const char *)
Extract basename (non-directory, non-extension) portion of filename.
Definition cpl_path.cpp:468
const char * CPLLaunderForFilename(const char *pszName, const char *pszOutputPath)
Launder a string to be compatible of a filename.
Definition cpl_path.cpp:1702
const char * CPLGetDirname(const char *)
Extract directory path portion of filename.
Definition cpl_path.cpp:362
CPLErr CPLAddFileInZip(void *hZip, const char *pszArchiveFilename, const char *pszInputFilename, VSILFILE *fpInput, CSLConstList papszOptions, GDALProgressFunc pProgressFunc, void *pProgressData)
Add a file inside a ZIP file opened/created with CPLCreateZip().
Definition cpl_minizip_zip.cpp:2360
int CPLGetExecPath(char *pszPathBuf, int nMaxLength)
Fetch path of executable.
Definition cpl_getexecpath.cpp:51
bool CPLHasPathTraversal(const char *pszFilename)
Return whether the filename contains a path traversal pattern.
Definition cpl_path.cpp:1728
const char * CPLFormCIFilename(const char *pszPath, const char *pszBasename, const char *pszExtension)
Case insensitive file searching, returning full path.
Definition cpl_path.cpp:995
void CPLFinderClean(void)
CPLFinderClean.
Definition cpl_findfile.cpp:117
bool CPLHasUnbalancedPathTraversal(const char *pszFilename)
Return whether the filename contains a unbalanced path traversal pattern.
Definition cpl_path.cpp:1770
const char * CPLGenerateTempFilename(const char *pszStem)
Generate temporary file name.
Definition cpl_path.cpp:1500
const char * CPLGetPath(const char *)
Extract directory path portion of filename.
Definition cpl_path.cpp:242
std::string CPLFormFilenameSafe(const char *pszPath, const char *pszBasename, const char *pszExtension=nullptr)
Build a full file path from a passed path, file basename and extension.
Definition cpl_path.cpp:709
double CPLStrtodM(const char *, char **)
Converts ASCII string to floating point number.
Definition cpl_strtod.cpp:415
const char * CPLCleanTrailingSlash(const char *)
Remove trailing forward/backward slash from the path for UNIX/Windows resp.
Definition cpl_path.cpp:1282
int CPLValidateXML(const char *pszXMLFilename, const char *pszXSDFilename, CSLConstList papszOptions)
Validate a XML file against a XML schema.
Definition cpl_xml_validate.cpp:1038
std::string CPLGetPathSafe(const char *)
Extract directory path portion of filename.
Definition cpl_path.cpp:152
const char * CPLResetExtension(const char *, const char *)
Replace the extension with the provided one.
Definition cpl_path.cpp:669
std::string CPLCleanTrailingSlashSafe(const char *pszPath)
Remove trailing forward/backward slash from the path for UNIX/Windows resp.
Definition cpl_path.cpp:1246
void CPLPushFinderLocation(const char *)
CPLPushFinderLocation.
Definition cpl_findfile.cpp:235
char * CPLGetCurrentDir(void)
Get the current working directory name.
Definition cpl_path.cpp:599
void CPLPushFileFinder(CPLFileFinder pfnFinder)
CPLPushFileFinder.
Definition cpl_findfile.cpp:187
const char * CPLExtractRelativePath(const char *, const char *, int *)
Get relative path from directory to target file.
Definition cpl_path.cpp:1155
void CPLPopFinderLocation(void)
CPLPopFinderLocation.
Definition cpl_findfile.cpp:274
double CPLAtofM(const char *)
Converts ASCII string to floating point number using any numeric locale.
Definition cpl_strtod.cpp:127
const char * CPLProjectRelativeFilename(const char *pszProjectDir, const char *pszSecondaryFilename)
Find a file relative to a project file.
Definition cpl_path.cpp:1088
const char * CPLFindFile(const char *pszClass, const char *pszBasename)
CPLFindFile.
Definition cpl_findfile.cpp:164
double CPLStrtodDelim(const char *, char **, char)
Converts ASCII string to floating point number using specified delimiter.
Definition cpl_strtod.cpp:218
To down_cast(From *f)
Use cpl::down_cast<Derived*>(pointer_to_base) as equivalent of static_cast<Derived*>(pointer_to_base)...
Definition cpl_conv.h:507
const char * CPLGetFilename(const char *)
Extract non-directory portion of filename.
Definition cpl_path.cpp:391
CPLLockFileStatus
Return code of CPLLockFileEx().
Definition cpl_conv.h:338
@ CLFS_OK
CPLLockFileEx() succeeded.
Definition cpl_conv.h:339
@ CLFS_LOCK_BUSY
Lock already taken (and still alive).
Definition cpl_conv.h:341
@ CLFS_CANNOT_CREATE_LOCK
Lock file creation failed.
Definition cpl_conv.h:340
@ CLFS_API_MISUSE
API misuse.
Definition cpl_conv.h:342
@ CLFS_THREAD_CREATION_FAILED
Thread creation failed.
Definition cpl_conv.h:343
const char * CPLFormFilename(const char *pszPath, const char *pszBasename, const char *pszExtension)
Build a full file path from a passed path, file basename and extension.
Definition cpl_path.cpp:860
const char * CPLDefaultFindFile(const char *pszClass, const char *pszBasename)
CPLDefaultFindFile.
Definition cpl_findfile.cpp:132
CPLFileFinder CPLPopFileFinder(void)
CPLPopFileFinder.
Definition cpl_findfile.cpp:224
void * CPLZLibInflateEx(const void *ptr, size_t nBytes, void *outptr, size_t nOutAvailableBytes, bool bAllowResizeOutptr, size_t *pnOutBytes)
Uncompress a buffer compressed with ZLib compression.
Definition cpl_vsil_gzip.cpp:5087
double CPLAtof(const char *)
Converts ASCII string to floating point number.
Definition cpl_strtod.cpp:102
CPL error handling services.
#define CPLAssert(expr)
Assert on an expression.
Definition cpl_error.h:353
CPLErr
Error category / error level.
Definition cpl_error.h:45
Core portability definitions for CPL.
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition cpl_port.h:198
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:279
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:275
#define CPL_RETURNS_NONNULL
Qualifier for a function that does not return NULL.
Definition cpl_port.h:1073
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:1101
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1252
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition cpl_port.h:1035
int GInt32
Int32 type.
Definition cpl_port.h:155
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:195
struct VSIVirtualHandle VSILFILE
Opaque type for a FILE that implements the VSIVirtualHandle API.
Definition cpl_vsi.h:141
Information on a shared file.
Definition cpl_conv.h:293
char * pszAccess
Access mode.
Definition cpl_conv.h:298
FILE * fp
File pointer.
Definition cpl_conv.h:294
int nRefCount
Reference counter.
Definition cpl_conv.h:295
char * pszFilename
Filename.
Definition cpl_conv.h:297
int bLarge
Whether fp must be interpreted as VSIFILE*.
Definition cpl_conv.h:296