1 /******************************************************************************
2  * $Id: gdalproxydataset.cpp 28899 2015-04-14 09:27:00Z rouault $
3  *
4  * Project:  GDAL Core
5  * Purpose:  A dataset and raster band classes that act as proxy for underlying
6  *           GDALDataset* and GDALRasterBand*
7  * Author:   Even Rouault <even dot rouault at mines dash paris dot org>
8  *
9  ******************************************************************************
10  * Copyright (c) 2008-2014, Even Rouault <even dot rouault at mines-paris dot org>
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  ****************************************************************************/
30 
31 #include "gdal_proxy.h"
32 
33 CPL_CVSID("$Id: gdalproxydataset.cpp 28899 2015-04-14 09:27:00Z rouault $");
34 
35 /* ******************************************************************** */
36 /*                        GDALProxyDataset                              */
37 /* ******************************************************************** */
38 
39 #define D_PROXY_METHOD_WITH_RET(retType, retErrValue, methodName, argList, argParams) \
40 retType GDALProxyDataset::methodName argList \
41 { \
42     retType ret; \
43     GDALDataset* poUnderlyingDataset = RefUnderlyingDataset(); \
44     if (poUnderlyingDataset) \
45     { \
46         ret = poUnderlyingDataset->methodName argParams; \
47         UnrefUnderlyingDataset(poUnderlyingDataset); \
48     } \
49     else \
50     { \
51         ret = retErrValue; \
52     } \
53     return ret; \
54 }
55 
56 
57 D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, IRasterIO,
58                         ( GDALRWFlag eRWFlag,
59                         int nXOff, int nYOff, int nXSize, int nYSize,
60                         void * pData, int nBufXSize, int nBufYSize,
61                         GDALDataType eBufType,
62                         int nBandCount, int *panBandMap,
63                         GSpacing nPixelSpace, GSpacing nLineSpace, GSpacing nBandSpace,
64                         GDALRasterIOExtraArg* psExtraArg),
65                         ( eRWFlag, nXOff, nYOff, nXSize, nYSize,
66                         pData, nBufXSize, nBufYSize,
67                         eBufType, nBandCount, panBandMap,
68                         nPixelSpace, nLineSpace, nBandSpace, psExtraArg ))
69 
70 
71 D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, IBuildOverviews,
72                         ( const char *pszResampling,
73                           int nOverviews, int *panOverviewList,
74                           int nListBands, int *panBandList,
75                           GDALProgressFunc pfnProgress,
76                           void * pProgressData ),
77                         ( pszResampling, nOverviews, panOverviewList,
78                           nListBands, panBandList, pfnProgress, pProgressData ))
79 
FlushCache()80 void  GDALProxyDataset::FlushCache()
81 {
82     GDALDataset* poUnderlyingDataset = RefUnderlyingDataset();
83     if (poUnderlyingDataset)
84     {
85         poUnderlyingDataset->FlushCache();
86         UnrefUnderlyingDataset(poUnderlyingDataset);
87     }
88 }
89 
90 D_PROXY_METHOD_WITH_RET(char**, NULL, GetMetadataDomainList, (), ())
91 D_PROXY_METHOD_WITH_RET(char**, NULL, GetMetadata, (const char * pszDomain), (pszDomain))
92 D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetMetadata,
93                         (char ** papszMetadata, const char * pszDomain),
94                         (papszMetadata, pszDomain))
95 D_PROXY_METHOD_WITH_RET(const char*, NULL, GetMetadataItem,
96                         (const char * pszName, const char * pszDomain),
97                         (pszName, pszDomain))
98 D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetMetadataItem,
99                         (const char * pszName, const char * pszValue, const char * pszDomain),
100                         (pszName, pszValue, pszDomain))
101 
102 D_PROXY_METHOD_WITH_RET(const char *, NULL, GetProjectionRef, (), ())
103 D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetProjection, (const char* pszProjection), (pszProjection))
104 D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, GetGeoTransform, (double* padfGeoTransform), (padfGeoTransform))
105 D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetGeoTransform, (double* padfGeoTransform), (padfGeoTransform))
106 
107 D_PROXY_METHOD_WITH_RET(void *, NULL, GetInternalHandle, ( const char * arg1), (arg1))
108 D_PROXY_METHOD_WITH_RET(GDALDriver *, NULL, GetDriver, (), ())
109 D_PROXY_METHOD_WITH_RET(char **, NULL, GetFileList, (), ())
110 D_PROXY_METHOD_WITH_RET(int, 0, GetGCPCount, (), ())
111 D_PROXY_METHOD_WITH_RET(const char *, NULL, GetGCPProjection, (), ())
112 D_PROXY_METHOD_WITH_RET(const GDAL_GCP *, NULL, GetGCPs, (), ())
113 D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetGCPs,
114                         (int nGCPCount, const GDAL_GCP *pasGCPList,
115                          const char *pszGCPProjection),
116                         (nGCPCount, pasGCPList, pszGCPProjection))
117 D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, AdviseRead,
118                         ( int nXOff, int nYOff, int nXSize, int nYSize,
119                                 int nBufXSize, int nBufYSize,
120                                 GDALDataType eDT,
121                                 int nBandCount, int *panBandList,
122                                 char **papszOptions ),
123                         (nXOff, nYOff, nXSize, nYSize, nBufXSize, nBufYSize, eDT, nBandCount, panBandList, papszOptions))
124 D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, CreateMaskBand, ( int nFlags ), (nFlags))
125 
126 /************************************************************************/
127 /*                    UnrefUnderlyingDataset()                        */
128 /************************************************************************/
129 
UnrefUnderlyingDataset(CPL_UNUSED GDALDataset * poUnderlyingDataset)130 void GDALProxyDataset::UnrefUnderlyingDataset(CPL_UNUSED GDALDataset* poUnderlyingDataset)
131 {
132 }
133 
134 /* ******************************************************************** */
135 /*                        GDALProxyRasterBand                           */
136 /* ******************************************************************** */
137 
138 
139 #define RB_PROXY_METHOD_WITH_RET(retType, retErrValue, methodName, argList, argParams) \
140 retType GDALProxyRasterBand::methodName argList \
141 { \
142     retType ret; \
143     GDALRasterBand* poSrcBand = RefUnderlyingRasterBand(); \
144     if (poSrcBand) \
145     { \
146         ret = poSrcBand->methodName argParams; \
147         UnrefUnderlyingRasterBand(poSrcBand); \
148     } \
149     else \
150     { \
151         ret = retErrValue; \
152     } \
153     return ret; \
154 }
155 
156 
157 #define RB_PROXY_METHOD_WITH_RET_WITH_INIT_BLOCK(retType, retErrValue, methodName, argList, argParams) \
158 retType GDALProxyRasterBand::methodName argList \
159 { \
160     retType ret; \
161     GDALRasterBand* poSrcBand = RefUnderlyingRasterBand(); \
162     if (poSrcBand) \
163     { \
164         if( !poSrcBand->InitBlockInfo() ) \
165             ret = CE_Failure; \
166         else \
167             ret = poSrcBand->methodName argParams; \
168         UnrefUnderlyingRasterBand(poSrcBand); \
169     } \
170     else \
171     { \
172         ret = retErrValue; \
173     } \
174     return ret; \
175 }
176 
177 RB_PROXY_METHOD_WITH_RET_WITH_INIT_BLOCK(CPLErr, CE_Failure, IReadBlock,
178                                 ( int nXBlockOff, int nYBlockOff, void* pImage),
179                                 (nXBlockOff, nYBlockOff, pImage) )
180 RB_PROXY_METHOD_WITH_RET_WITH_INIT_BLOCK(CPLErr, CE_Failure, IWriteBlock,
181                                 ( int nXBlockOff, int nYBlockOff, void* pImage),
182                                 (nXBlockOff, nYBlockOff, pImage) )
183 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, IRasterIO,
184                         ( GDALRWFlag eRWFlag,
185                                 int nXOff, int nYOff, int nXSize, int nYSize,
186                                 void * pData, int nBufXSize, int nBufYSize,
187                                 GDALDataType eBufType,
188                                 GSpacing nPixelSpace,
189                                 GSpacing nLineSpace,
190                                 GDALRasterIOExtraArg* psExtraArg ),
191                         (eRWFlag, nXOff, nYOff, nXSize, nYSize,
192                                 pData, nBufXSize, nBufYSize, eBufType,
193                                 nPixelSpace, nLineSpace, psExtraArg ) )
194 
195 RB_PROXY_METHOD_WITH_RET(char**, NULL, GetMetadataDomainList, (), ())
196 RB_PROXY_METHOD_WITH_RET(char**, NULL, GetMetadata, (const char * pszDomain), (pszDomain))
197 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetMetadata,
198                         (char ** papszMetadata, const char * pszDomain),
199                         (papszMetadata, pszDomain))
200 RB_PROXY_METHOD_WITH_RET(const char*, NULL, GetMetadataItem,
201                         (const char * pszName, const char * pszDomain),
202                         (pszName, pszDomain))
203 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetMetadataItem,
204                         (const char * pszName, const char * pszValue, const char * pszDomain),
205                         (pszName, pszValue, pszDomain))
206 
207 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, FlushCache, (), ())
208 RB_PROXY_METHOD_WITH_RET(char**, NULL, GetCategoryNames, (), ())
209 RB_PROXY_METHOD_WITH_RET(double, 0, GetNoDataValue, (int *pbSuccess), (pbSuccess))
210 RB_PROXY_METHOD_WITH_RET(double, 0, GetMinimum, (int *pbSuccess), (pbSuccess))
211 RB_PROXY_METHOD_WITH_RET(double, 0, GetMaximum, (int *pbSuccess), (pbSuccess))
212 RB_PROXY_METHOD_WITH_RET(double, 0, GetOffset, (int *pbSuccess), (pbSuccess))
213 RB_PROXY_METHOD_WITH_RET(double, 0, GetScale, (int *pbSuccess), (pbSuccess))
214 RB_PROXY_METHOD_WITH_RET(const char*, NULL, GetUnitType, (), ())
215 RB_PROXY_METHOD_WITH_RET(GDALColorInterp, GCI_Undefined, GetColorInterpretation, (), ())
216 RB_PROXY_METHOD_WITH_RET(GDALColorTable*, NULL, GetColorTable, (), ())
217 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, Fill,
218                         (double dfRealValue, double dfImaginaryValue),
219                         (dfRealValue, dfImaginaryValue))
220 
221 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetCategoryNames, ( char ** arg ), (arg))
222 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetNoDataValue, ( double arg ), (arg))
223 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetColorTable, ( GDALColorTable *arg ), (arg))
224 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetColorInterpretation,
225                                     ( GDALColorInterp arg ), (arg))
226 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetOffset, ( double arg ), (arg))
227 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetScale, ( double arg ), (arg))
228 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetUnitType, ( const char * arg ), (arg))
229 
230 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, GetStatistics,
231                         ( int bApproxOK, int bForce,
232                         double *pdfMin, double *pdfMax,
233                         double *pdfMean, double *padfStdDev ),
234                         (bApproxOK, bForce, pdfMin, pdfMax, pdfMean, padfStdDev))
235 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, ComputeStatistics,
236                         ( int bApproxOK,
237                         double *pdfMin, double *pdfMax,
238                         double *pdfMean, double *pdfStdDev,
239                         GDALProgressFunc pfn, void *pProgressData ),
240                         ( bApproxOK, pdfMin, pdfMax, pdfMean, pdfStdDev, pfn, pProgressData))
241 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetStatistics,
242                         ( double dfMin, double dfMax,
243                         double dfMean, double dfStdDev ),
244                         (dfMin, dfMax, dfMean, dfStdDev))
245 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, ComputeRasterMinMax,
246                         ( int arg1, double* arg2 ), (arg1, arg2))
247 
248 RB_PROXY_METHOD_WITH_RET(int, 0, HasArbitraryOverviews, (), ())
249 RB_PROXY_METHOD_WITH_RET(int, 0,  GetOverviewCount, (), ())
250 RB_PROXY_METHOD_WITH_RET(GDALRasterBand*, NULL,  GetOverview, (int arg1), (arg1))
251 RB_PROXY_METHOD_WITH_RET(GDALRasterBand*, NULL,  GetRasterSampleOverview,
252                         (GUIntBig arg1), (arg1))
253 
254 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, BuildOverviews,
255                         (const char * arg1, int arg2, int *arg3,
256                         GDALProgressFunc arg4, void * arg5),
257                         (arg1, arg2, arg3, arg4, arg5))
258 
259 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, AdviseRead,
260                         ( int nXOff, int nYOff, int nXSize, int nYSize,
261                         int nBufXSize, int nBufYSize,
262                         GDALDataType eDT, char **papszOptions ),
263                         (nXOff, nYOff, nXSize, nYSize, nBufXSize, nBufYSize, eDT, papszOptions))
264 
265 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, GetHistogram,
266                         ( double dfMin, double dfMax,
267                         int nBuckets, GUIntBig * panHistogram,
268                         int bIncludeOutOfRange, int bApproxOK,
269                         GDALProgressFunc pfn, void *pProgressData ),
270                         (dfMin, dfMax, nBuckets, panHistogram, bIncludeOutOfRange,
271                         bApproxOK, pfn, pProgressData))
272 
273 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, GetDefaultHistogram,
274                         (double *pdfMin, double *pdfMax,
275                         int *pnBuckets, GUIntBig ** ppanHistogram,
276                         int bForce,
277                         GDALProgressFunc pfn, void *pProgressData ),
278                         (pdfMin, pdfMax, pnBuckets, ppanHistogram, bForce,
279                         pfn, pProgressData))
280 
281 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetDefaultHistogram,
282                         ( double dfMin, double dfMax,
283                         int nBuckets, GUIntBig * panHistogram ),
284                         (dfMin, dfMax, nBuckets, panHistogram))
285 
286 RB_PROXY_METHOD_WITH_RET(GDALRasterAttributeTable *, NULL,
287                         GetDefaultRAT, (), ())
288 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetDefaultRAT,
289                         ( const GDALRasterAttributeTable * arg1), (arg1))
290 
291 RB_PROXY_METHOD_WITH_RET(GDALRasterBand*, NULL, GetMaskBand, (), ())
292 RB_PROXY_METHOD_WITH_RET(int, 0, GetMaskFlags, (), ())
293 RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, CreateMaskBand, ( int nFlags ), (nFlags))
294 
295 RB_PROXY_METHOD_WITH_RET(CPLVirtualMem*, NULL, GetVirtualMemAuto,
296                          ( GDALRWFlag eRWFlag, int *pnPixelSpace, GIntBig *pnLineSpace, char **papszOptions ),
297                          (eRWFlag, pnPixelSpace, pnLineSpace, papszOptions) )
298 
299 /************************************************************************/
300 /*                 UnrefUnderlyingRasterBand()                        */
301 /************************************************************************/
302 
UnrefUnderlyingRasterBand(CPL_UNUSED GDALRasterBand * poUnderlyingRasterBand)303 void GDALProxyRasterBand::UnrefUnderlyingRasterBand(CPL_UNUSED GDALRasterBand* poUnderlyingRasterBand)
304 {
305 }
306