1 /* Converted to D from C:/devLibs/gdal21/include/cpl_conv.h by htod */ 2 module gdal.cpl.conv; 3 /****************************************************************************** 4 * $Id: cpl_conv.h 33666 2016-03-07 05:21:07Z goatbar $ 5 * 6 * Project: CPL - Common Portability Library 7 * Purpose: Convenience functions declarations. 8 * This is intended to remain light weight. 9 * Author: Frank Warmerdam, warmerdam@pobox.com 10 * 11 ****************************************************************************** 12 * Copyright (c) 1998, Frank Warmerdam 13 * Copyright (c) 2007-2013, Even Rouault <even dot rouault at mines-paris dot org> 14 * 15 * Permission is hereby granted, free of charge, to any person obtaining a 16 * copy of this software and associated documentation files (the "Software"), 17 * to deal in the Software without restriction, including without limitation 18 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 19 * and/or sell copies of the Software, and to permit persons to whom the 20 * Software is furnished to do so, subject to the following conditions: 21 * 22 * The above copyright notice and this permission notice shall be included 23 * in all copies or substantial portions of the Software. 24 * 25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 26 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 28 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 30 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 31 * DEALINGS IN THE SOFTWARE. 32 ****************************************************************************/ 33 34 import gdal.cpl.port; 35 import gdal.cpl.vsi; 36 import gdal.cpl.error; 37 38 import core.stdc.stdio : FILE; 39 40 /** 41 * \file cpl_conv.h 42 * 43 * Various convenience functions for CPL. 44 * 45 */ 46 47 /* -------------------------------------------------------------------- */ 48 /* Runtime check of various configuration items. */ 49 /* -------------------------------------------------------------------- */ 50 extern (C): 51 void CPLVerifyConfiguration(); 52 53 extern (Windows): 54 const(char) * CPLGetConfigOption(const(char) *, const(char) *); 55 const(char) * CPLGetThreadLocalConfigOption(const(char) *, const(char) *); 56 void CPLSetConfigOption(const(char) *, const(char) *); 57 void CPLSetThreadLocalConfigOption(const(char) *pszKey, const(char) *pszValue); 58 void CPLFreeConfig(); 59 60 /* -------------------------------------------------------------------- */ 61 /* Safe malloc() API. Thin cover over VSI functions with fatal */ 62 /* error reporting if memory allocation fails. */ 63 /* -------------------------------------------------------------------- */ 64 //C void CPL_DLL *CPLMalloc( size_t ) CPL_WARN_UNUSED_RESULT; 65 extern (C): 66 void * CPLMalloc(size_t ); 67 void * CPLCalloc(size_t , size_t ); 68 void * CPLRealloc(void *, size_t ); 69 char * CPLStrdup(char *); 70 char * CPLStrlwr(char *); 71 72 alias VSIFree CPLFree; 73 /* -------------------------------------------------------------------- */ 74 /* Read a line from a text file, and strip of CR/LF. */ 75 /* -------------------------------------------------------------------- */ 76 char * CPLFGets(char *, int , FILE *); 77 const(char) * CPLReadLine(FILE *); 78 const(char) * CPLReadLineL(VSILFILE *); 79 const(char) * CPLReadLine2L(VSILFILE *, int nMaxCols, char **papszOptions); 80 81 /* -------------------------------------------------------------------- */ 82 /* Convert ASCII string to floating point number */ 83 /* (THESE FUNCTIONS ARE NOT LOCALE AWARE!). */ 84 /* -------------------------------------------------------------------- */ 85 double CPLAtof(const(char) *); 86 double CPLAtofDelim(const(char) *, char ); 87 double CPLStrtod(const(char) *, char **); 88 double CPLStrtodDelim(const(char) *, char **, char ); 89 float CPLStrtof(const(char) *, char **); 90 float CPLStrtofDelim(const(char) *, char **, char ); 91 92 /* -------------------------------------------------------------------- */ 93 /* Convert number to string. This function is locale agnostic */ 94 /* (i.e. it will support "," or "." regardless of current locale) */ 95 /* -------------------------------------------------------------------- */ 96 double CPLAtofM(const(char) *); 97 98 /* -------------------------------------------------------------------- */ 99 /* Read a numeric value from an ASCII character string. */ 100 /* -------------------------------------------------------------------- */ 101 char * CPLScanString(const(char) *, int , int , int ); 102 double CPLScanDouble(const(char) *, int ); 103 int CPLScanLong(const(char) *, int ); 104 uint CPLScanULong(const(char) *, int ); 105 GUIntBig CPLScanUIntBig(const(char) *, int ); 106 GIntBig CPLAtoGIntBig(const(char) *pszString); 107 GIntBig CPLAtoGIntBigEx(const(char) *pszString, int bWarn, int *pbOverflow); 108 void * CPLScanPointer(const(char) *, int ); 109 110 /* -------------------------------------------------------------------- */ 111 /* Print a value to an ASCII character string. */ 112 /* -------------------------------------------------------------------- */ 113 int CPLPrintString(char *, const(char) *, int ); 114 int CPLPrintStringFill(char *, const(char) *, int ); 115 int CPLPrintInt32(char *, GInt32 , int ); 116 int CPLPrintUIntBig(char *, GUIntBig , int ); 117 int CPLPrintDouble(char *, const(char) *, double , const(char) *); 118 //int CPLPrintTime(char *, int , const(char) *, tm *, const(char) *); 119 int CPLPrintPointer(char *, void *, int ); 120 121 /* -------------------------------------------------------------------- */ 122 /* Fetch a function from DLL / so. */ 123 /* -------------------------------------------------------------------- */ 124 125 void * CPLGetSymbol(const(char) *, const(char) *); 126 127 /* -------------------------------------------------------------------- */ 128 /* Fetch executable path. */ 129 /* -------------------------------------------------------------------- */ 130 int CPLGetExecPath(char *pszPathBuf, int nMaxLength); 131 132 /* -------------------------------------------------------------------- */ 133 /* Filename handling functions. */ 134 /* -------------------------------------------------------------------- */ 135 const(char) * CPLGetPath(const(char) *); 136 const(char) * CPLGetDirname(const(char) *); 137 const(char) * CPLGetFilename(const(char) *); 138 const(char) * CPLGetBasename(const(char) *); 139 const(char) * CPLGetExtension(const(char) *); 140 char * CPLGetCurrentDir(); 141 const(char) * CPLFormFilename(const(char) *pszPath, const(char) *pszBasename, const(char) *pszExtension); 142 const(char) * CPLFormCIFilename(const(char) *pszPath, const(char) *pszBasename, const(char) *pszExtension); 143 const(char) * CPLResetExtension(const(char) *, const(char) *); 144 const(char) * CPLProjectRelativeFilename(const(char) *pszProjectDir, const(char) *pszSecondaryFilename); 145 int CPLIsFilenameRelative(const(char) *pszFilename); 146 const(char) * CPLExtractRelativePath(const(char) *, const(char) *, int *); 147 const(char) * CPLCleanTrailingSlash(const(char) *); 148 char ** CPLCorrespondingPaths(const(char) *pszOldFilename, const(char) *pszNewFilename, char **papszFileList); 149 int CPLCheckForFile(char *pszFilename, char **papszSiblingList); 150 151 const(char) * CPLGenerateTempFilename(const(char) *pszStem); 152 153 /* -------------------------------------------------------------------- */ 154 /* Find File Function */ 155 /* -------------------------------------------------------------------- */ 156 alias const(char) * function(const(char) *, const(char) *)CPLFileFinder; 157 158 const(char) * CPLFindFile(const(char) *pszClass, const(char) *pszBasename); 159 const(char) * CPLDefaultFindFile(const(char) *pszClass, const(char) *pszBasename); 160 void CPLPushFileFinder(CPLFileFinder pfnFinder); 161 CPLFileFinder CPLPopFileFinder(); 162 void CPLPushFinderLocation(const(char) *); 163 void CPLPopFinderLocation(); 164 void CPLFinderClean(); 165 166 /* -------------------------------------------------------------------- */ 167 /* Reference counted file handle manager. Makes sharing file */ 168 /* handles more practical. */ 169 /* -------------------------------------------------------------------- */ 170 struct _N2 171 { 172 FILE *fp; 173 int nRefCount; 174 int bLarge; 175 char *pszFilename; 176 char *pszAccess; 177 } 178 alias _N2 CPLSharedFileInfo; 179 180 FILE * CPLOpenShared(const(char) *, const(char) *, int ); 181 void CPLCloseShared(FILE *); 182 CPLSharedFileInfo * CPLGetSharedList(int *); 183 void CPLDumpSharedList(FILE *); 184 void CPLCleanupSharedFileMutex(); 185 186 /* -------------------------------------------------------------------- */ 187 /* DMS to Dec to DMS conversion. */ 188 /* -------------------------------------------------------------------- */ 189 double CPLDMSToDec(const(char) *); 190 const(char) * CPLDecToDMS(double dfAngle, const(char) *pszAxis, int nPrecision); 191 double CPLPackedDMSToDec(double ); 192 double CPLDecToPackedDMS(double dfDec); 193 194 void CPLStringToComplex(const(char) *pszString, double *pdfReal, double *pdfImag); 195 196 /* -------------------------------------------------------------------- */ 197 /* Misc other functions. */ 198 /* -------------------------------------------------------------------- */ 199 int CPLUnlinkTree(const(char) *); 200 int CPLCopyFile(const(char) *pszNewPath, const(char) *pszOldPath); 201 int CPLCopyTree(const(char) *pszNewPath, const(char) *pszOldPath); 202 int CPLMoveFile(const(char) *pszNewPath, const(char) *pszOldPath); 203 int CPLSymlink(const(char) *pszOldPath, const(char) *pszNewPath, char **papszOptions); 204 205 /* -------------------------------------------------------------------- */ 206 /* ZIP Creation. */ 207 /* -------------------------------------------------------------------- */ 208 void * CPLCreateZip(const(char) *pszZipFilename, char **papszOptions); 209 CPLErr CPLCreateFileInZip(void *hZip, const(char) *pszFilename, char **papszOptions); 210 CPLErr CPLWriteFileInZip(void *hZip, void *pBuffer, int nBufferSize); 211 CPLErr CPLCloseFileInZip(void *hZip); 212 CPLErr CPLCloseZip(void *hZip); 213 214 /* -------------------------------------------------------------------- */ 215 /* ZLib compression */ 216 /* -------------------------------------------------------------------- */ 217 218 void * CPLZLibDeflate(void *ptr, size_t nBytes, int nLevel, void *outptr, size_t nOutAvailableBytes, size_t *pnOutBytes); 219 void * CPLZLibInflate(void *ptr, size_t nBytes, void *outptr, size_t nOutAvailableBytes, size_t *pnOutBytes); 220 221 /* -------------------------------------------------------------------- */ 222 /* XML validation. */ 223 /* -------------------------------------------------------------------- */ 224 int CPLValidateXML(const(char) *pszXMLFilename, const(char) *pszXSDFilename, char **papszOptions); 225 226 /* -------------------------------------------------------------------- */ 227 /* Locale handling. Prevents parallel executions of setlocale(). */ 228 /* -------------------------------------------------------------------- */ 229 char * CPLsetlocale(int category, const(char) *locale); 230 void CPLCleanupSetlocaleMutex();