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() nothrow @nogc;
52 
53 extern (System):
54 const(char) * CPLGetConfigOption(const(char) *, const(char) *) nothrow @nogc;
55 const(char) * CPLGetThreadLocalConfigOption(const(char) *, const(char) *) nothrow @nogc;
56 void  CPLSetConfigOption(const(char) *, const(char) *) nothrow @nogc;
57 void  CPLSetThreadLocalConfigOption(const(char) *pszKey, const(char) *pszValue) nothrow @nogc;
58 void  CPLFreeConfig() nothrow @nogc;
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 ) nothrow @nogc;
67 void * CPLCalloc(size_t , size_t ) nothrow @nogc;
68 void * CPLRealloc(void *, size_t ) nothrow @nogc;
69 char * CPLStrdup(char *) nothrow @nogc;
70 char * CPLStrlwr(char *) nothrow @nogc;
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 *) nothrow @nogc;
77 const(char) * CPLReadLine(FILE *) nothrow @nogc;
78 const(char) * CPLReadLineL(VSILFILE *) nothrow @nogc;
79 const(char) * CPLReadLine2L(VSILFILE *, int nMaxCols, char **papszOptions) nothrow @nogc;
80 
81 /* -------------------------------------------------------------------- */
82 /*      Convert ASCII string to floating point number                   */
83 /*      (THESE FUNCTIONS ARE NOT LOCALE AWARE!).                        */
84 /* -------------------------------------------------------------------- */
85 double  CPLAtof(const(char) *) nothrow @nogc;
86 double  CPLAtofDelim(const(char) *, char ) nothrow @nogc;
87 double  CPLStrtod(const(char) *, char **) nothrow @nogc;
88 double  CPLStrtodDelim(const(char) *, char **, char ) nothrow @nogc;
89 float  CPLStrtof(const(char) *, char **) nothrow @nogc;
90 float  CPLStrtofDelim(const(char) *, char **, char ) nothrow @nogc;
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) *) nothrow @nogc;
97 
98 /* -------------------------------------------------------------------- */
99 /*      Read a numeric value from an ASCII character string.            */
100 /* -------------------------------------------------------------------- */
101 char * CPLScanString(const(char) *, int , int , int ) nothrow @nogc;
102 double  CPLScanDouble(const(char) *, int ) nothrow @nogc;
103 int  CPLScanLong(const(char) *, int ) nothrow @nogc;
104 uint  CPLScanULong(const(char) *, int ) nothrow @nogc;
105 GUIntBig  CPLScanUIntBig(const(char) *, int ) nothrow @nogc;
106 GIntBig  CPLAtoGIntBig(const(char) *pszString) nothrow @nogc;
107 GIntBig  CPLAtoGIntBigEx(const(char) *pszString, int bWarn, int *pbOverflow) nothrow @nogc;
108 void * CPLScanPointer(const(char) *, int ) nothrow @nogc;
109 
110 /* -------------------------------------------------------------------- */
111 /*      Print a value to an ASCII character string.                     */
112 /* -------------------------------------------------------------------- */
113 int  CPLPrintString(char *, const(char) *, int ) nothrow @nogc;
114 int  CPLPrintStringFill(char *, const(char) *, int ) nothrow @nogc;
115 int  CPLPrintInt32(char *, GInt32 , int ) nothrow @nogc;
116 int  CPLPrintUIntBig(char *, GUIntBig , int ) nothrow @nogc;
117 int  CPLPrintDouble(char *, const(char) *, double , const(char) *) nothrow @nogc;
118 //int  CPLPrintTime(char *, int , const(char) *, tm *, const(char) *);
119 int  CPLPrintPointer(char *, void *, int ) nothrow @nogc;
120 
121 /* -------------------------------------------------------------------- */
122 /*      Fetch a function from DLL / so.                                 */
123 /* -------------------------------------------------------------------- */
124 
125 void * CPLGetSymbol(const(char) *, const(char) *) nothrow @nogc;
126 
127 /* -------------------------------------------------------------------- */
128 /*      Fetch executable path.                                          */
129 /* -------------------------------------------------------------------- */
130 int  CPLGetExecPath(char *pszPathBuf, int nMaxLength) nothrow @nogc;
131 
132 /* -------------------------------------------------------------------- */
133 /*      Filename handling functions.                                    */
134 /* -------------------------------------------------------------------- */
135 const(char) * CPLGetPath(const(char) *) nothrow @nogc;
136 const(char) * CPLGetDirname(const(char) *) nothrow @nogc;
137 const(char) * CPLGetFilename(const(char) *) nothrow @nogc;
138 const(char) * CPLGetBasename(const(char) *) nothrow @nogc;
139 const(char) * CPLGetExtension(const(char) *) nothrow @nogc;
140 char * CPLGetCurrentDir() nothrow @nogc;
141 const(char) * CPLFormFilename(const(char) *pszPath, const(char) *pszBasename, const(char) *pszExtension) nothrow @nogc;
142 const(char) * CPLFormCIFilename(const(char) *pszPath, const(char) *pszBasename, const(char) *pszExtension) nothrow @nogc;
143 const(char) * CPLResetExtension(const(char) *, const(char) *) nothrow @nogc;
144 const(char) * CPLProjectRelativeFilename(const(char) *pszProjectDir, const(char) *pszSecondaryFilename) nothrow @nogc;
145 int  CPLIsFilenameRelative(const(char) *pszFilename) nothrow @nogc;
146 const(char) * CPLExtractRelativePath(const(char) *, const(char) *, int *) nothrow @nogc;
147 const(char) * CPLCleanTrailingSlash(const(char) *) nothrow @nogc;
148 char ** CPLCorrespondingPaths(const(char) *pszOldFilename, const(char) *pszNewFilename, char **papszFileList) nothrow @nogc;
149 int  CPLCheckForFile(char *pszFilename, char **papszSiblingList) nothrow @nogc;
150 
151 const(char) * CPLGenerateTempFilename(const(char) *pszStem) nothrow @nogc;
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) nothrow @nogc;
159 const(char) * CPLDefaultFindFile(const(char) *pszClass, const(char) *pszBasename) nothrow @nogc;
160 void  CPLPushFileFinder(CPLFileFinder pfnFinder) nothrow @nogc;
161 CPLFileFinder  CPLPopFileFinder() nothrow @nogc;
162 void  CPLPushFinderLocation(const(char) *) nothrow @nogc;
163 void  CPLPopFinderLocation() nothrow @nogc;
164 void  CPLFinderClean() nothrow @nogc;
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 ) nothrow @nogc;
181 void  CPLCloseShared(FILE *) nothrow @nogc;
182 CPLSharedFileInfo * CPLGetSharedList(int *) nothrow @nogc;
183 void  CPLDumpSharedList(FILE *) nothrow @nogc;
184 void  CPLCleanupSharedFileMutex() nothrow @nogc;
185 
186 /* -------------------------------------------------------------------- */
187 /*      DMS to Dec to DMS conversion.                                   */
188 /* -------------------------------------------------------------------- */
189 double  CPLDMSToDec(const(char) *) nothrow @nogc;
190 const(char) * CPLDecToDMS(double dfAngle, const(char) *pszAxis, int nPrecision) nothrow @nogc;
191 double  CPLPackedDMSToDec(double ) nothrow @nogc;
192 double  CPLDecToPackedDMS(double dfDec) nothrow @nogc;
193 
194 void  CPLStringToComplex(const(char) *pszString, double *pdfReal, double *pdfImag) nothrow @nogc;
195 
196 /* -------------------------------------------------------------------- */
197 /*      Misc other functions.                                           */
198 /* -------------------------------------------------------------------- */
199 int  CPLUnlinkTree(const(char) *) nothrow @nogc;
200 int  CPLCopyFile(const(char) *pszNewPath, const(char) *pszOldPath) nothrow @nogc;
201 int  CPLCopyTree(const(char) *pszNewPath, const(char) *pszOldPath) nothrow @nogc;
202 int  CPLMoveFile(const(char) *pszNewPath, const(char) *pszOldPath) nothrow @nogc;
203 int  CPLSymlink(const(char) *pszOldPath, const(char) *pszNewPath, char **papszOptions) nothrow @nogc;
204 
205 /* -------------------------------------------------------------------- */
206 /*      ZIP Creation.                                                   */
207 /* -------------------------------------------------------------------- */
208 void * CPLCreateZip(const(char) *pszZipFilename, char **papszOptions) nothrow @nogc;
209 CPLErr  CPLCreateFileInZip(void *hZip, const(char) *pszFilename, char **papszOptions) nothrow @nogc;
210 CPLErr  CPLWriteFileInZip(void *hZip, void *pBuffer, int nBufferSize) nothrow @nogc;
211 CPLErr  CPLCloseFileInZip(void *hZip) nothrow @nogc;
212 CPLErr  CPLCloseZip(void *hZip) nothrow @nogc;
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) nothrow @nogc;
219 void * CPLZLibInflate(void *ptr, size_t nBytes, void *outptr, size_t nOutAvailableBytes, size_t *pnOutBytes) nothrow @nogc;
220 
221 /* -------------------------------------------------------------------- */
222 /*      XML validation.                                                 */
223 /* -------------------------------------------------------------------- */
224 int  CPLValidateXML(const(char) *pszXMLFilename, const(char) *pszXSDFilename, char **papszOptions) nothrow @nogc;
225 
226 /* -------------------------------------------------------------------- */
227 /*      Locale handling. Prevents parallel executions of setlocale().   */
228 /* -------------------------------------------------------------------- */
229 char * CPLsetlocale(int category, const(char) *locale) nothrow @nogc;
230 void  CPLCleanupSetlocaleMutex() nothrow @nogc;