1 : /******************************************************************************
2 : * $Id: gdalproxydataset.cpp 21866 2011-02-26 21:04:58Z 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, Even Rouault
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 21866 2011-02-26 21:04:58Z 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 1 : 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 : int nPixelSpace, int nLineSpace, int nBandSpace),
64 : ( eRWFlag, nXOff, nYOff, nXSize, nYSize,
65 : pData, nBufXSize, nBufYSize,
66 : eBufType, nBandCount, panBandMap,
67 : nPixelSpace, nLineSpace, nBandSpace ))
68 :
69 :
70 0 : D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, IBuildOverviews,
71 : ( const char *pszResampling,
72 : int nOverviews, int *panOverviewList,
73 : int nListBands, int *panBandList,
74 : GDALProgressFunc pfnProgress,
75 : void * pProgressData ),
76 : ( pszResampling, nOverviews, panOverviewList,
77 : nListBands, panBandList, pfnProgress, pProgressData ))
78 :
79 0 : void GDALProxyDataset::FlushCache()
80 : {
81 0 : GDALDataset* poUnderlyingDataset = RefUnderlyingDataset();
82 0 : if (poUnderlyingDataset)
83 : {
84 0 : poUnderlyingDataset->FlushCache();
85 0 : UnrefUnderlyingDataset(poUnderlyingDataset);
86 : }
87 0 : }
88 :
89 0 : D_PROXY_METHOD_WITH_RET(char**, NULL, GetMetadata, (const char * pszDomain), (pszDomain))
90 0 : D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetMetadata,
91 : (char ** papszMetadata, const char * pszDomain),
92 : (papszMetadata, pszDomain))
93 0 : D_PROXY_METHOD_WITH_RET(const char*, NULL, GetMetadataItem,
94 : (const char * pszName, const char * pszDomain),
95 : (pszName, pszDomain))
96 0 : D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetMetadataItem,
97 : (const char * pszName, const char * pszValue, const char * pszDomain),
98 : (pszName, pszValue, pszDomain))
99 :
100 4 : D_PROXY_METHOD_WITH_RET(const char *, NULL, GetProjectionRef, (), ())
101 0 : D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetProjection, (const char* pszProjection), (pszProjection))
102 0 : D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, GetGeoTransform, (double* padfGeoTransform), (padfGeoTransform))
103 0 : D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetGeoTransform, (double* padfGeoTransform), (padfGeoTransform))
104 :
105 0 : D_PROXY_METHOD_WITH_RET(void *, NULL, GetInternalHandle, ( const char * arg1), (arg1))
106 9 : D_PROXY_METHOD_WITH_RET(GDALDriver *, NULL, GetDriver, (), ())
107 0 : D_PROXY_METHOD_WITH_RET(char **, NULL, GetFileList, (), ())
108 0 : D_PROXY_METHOD_WITH_RET(int, 0, GetGCPCount, (), ())
109 0 : D_PROXY_METHOD_WITH_RET(const char *, NULL, GetGCPProjection, (), ())
110 0 : D_PROXY_METHOD_WITH_RET(const GDAL_GCP *, NULL, GetGCPs, (), ())
111 0 : D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetGCPs,
112 : (int nGCPCount, const GDAL_GCP *pasGCPList,
113 : const char *pszGCPProjection),
114 : (nGCPCount, pasGCPList, pszGCPProjection))
115 0 : D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, AdviseRead,
116 : ( int nXOff, int nYOff, int nXSize, int nYSize,
117 : int nBufXSize, int nBufYSize,
118 : GDALDataType eDT,
119 : int nBandCount, int *panBandList,
120 : char **papszOptions ),
121 : (nXOff, nYOff, nXSize, nYSize, nBufXSize, nBufYSize, eDT, nBandCount, panBandList, papszOptions))
122 0 : D_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, CreateMaskBand, ( int nFlags ), (nFlags))
123 :
124 : /************************************************************************/
125 : /* UnrefUnderlyingDataset() */
126 : /************************************************************************/
127 :
128 0 : void GDALProxyDataset::UnrefUnderlyingDataset(GDALDataset* poUnderlyingDataset)
129 : {
130 0 : }
131 :
132 : /* ******************************************************************** */
133 : /* GDALProxyRasterBand */
134 : /* ******************************************************************** */
135 :
136 :
137 : #define RB_PROXY_METHOD_WITH_RET(retType, retErrValue, methodName, argList, argParams) \
138 : retType GDALProxyRasterBand::methodName argList \
139 : { \
140 : retType ret; \
141 : GDALRasterBand* poSrcBand = RefUnderlyingRasterBand(); \
142 : if (poSrcBand) \
143 : { \
144 : ret = poSrcBand->methodName argParams; \
145 : UnrefUnderlyingRasterBand(poSrcBand); \
146 : } \
147 : else \
148 : { \
149 : ret = retErrValue; \
150 : } \
151 : return ret; \
152 : }
153 :
154 :
155 : #define RB_PROXY_METHOD_WITH_RET_WITH_INIT_BLOCK(retType, retErrValue, methodName, argList, argParams) \
156 : retType GDALProxyRasterBand::methodName argList \
157 : { \
158 : retType ret; \
159 : GDALRasterBand* poSrcBand = RefUnderlyingRasterBand(); \
160 : if (poSrcBand) \
161 : { \
162 : if( !poSrcBand->InitBlockInfo() ) \
163 : ret = CE_Failure; \
164 : else \
165 : ret = poSrcBand->methodName argParams; \
166 : UnrefUnderlyingRasterBand(poSrcBand); \
167 : } \
168 : else \
169 : { \
170 : ret = retErrValue; \
171 : } \
172 : return ret; \
173 : }
174 :
175 0 : RB_PROXY_METHOD_WITH_RET_WITH_INIT_BLOCK(CPLErr, CE_Failure, IReadBlock,
176 : ( int nXBlockOff, int nYBlockOff, void* pImage),
177 : (nXBlockOff, nYBlockOff, pImage) )
178 0 : RB_PROXY_METHOD_WITH_RET_WITH_INIT_BLOCK(CPLErr, CE_Failure, IWriteBlock,
179 : ( int nXBlockOff, int nYBlockOff, void* pImage),
180 : (nXBlockOff, nYBlockOff, pImage) )
181 14179 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, IRasterIO,
182 : ( GDALRWFlag eRWFlag,
183 : int nXOff, int nYOff, int nXSize, int nYSize,
184 : void * pData, int nBufXSize, int nBufYSize,
185 : GDALDataType eBufType,
186 : int nPixelSpace,
187 : int nLineSpace ),
188 : (eRWFlag, nXOff, nYOff, nXSize, nYSize,
189 : pData, nBufXSize, nBufYSize, eBufType,
190 : nPixelSpace, nLineSpace ) )
191 :
192 0 : RB_PROXY_METHOD_WITH_RET(char**, NULL, GetMetadata, (const char * pszDomain), (pszDomain))
193 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetMetadata,
194 : (char ** papszMetadata, const char * pszDomain),
195 : (papszMetadata, pszDomain))
196 0 : RB_PROXY_METHOD_WITH_RET(const char*, NULL, GetMetadataItem,
197 : (const char * pszName, const char * pszDomain),
198 : (pszName, pszDomain))
199 10 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetMetadataItem,
200 : (const char * pszName, const char * pszValue, const char * pszDomain),
201 : (pszName, pszValue, pszDomain))
202 :
203 32 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, FlushCache, (), ())
204 0 : RB_PROXY_METHOD_WITH_RET(char**, NULL, GetCategoryNames, (), ())
205 0 : RB_PROXY_METHOD_WITH_RET(double, 0, GetNoDataValue, (int *pbSuccess), (pbSuccess))
206 2 : RB_PROXY_METHOD_WITH_RET(double, 0, GetMinimum, (int *pbSuccess), (pbSuccess))
207 2 : RB_PROXY_METHOD_WITH_RET(double, 0, GetMaximum, (int *pbSuccess), (pbSuccess))
208 0 : RB_PROXY_METHOD_WITH_RET(double, 0, GetOffset, (int *pbSuccess), (pbSuccess))
209 0 : RB_PROXY_METHOD_WITH_RET(double, 0, GetScale, (int *pbSuccess), (pbSuccess))
210 0 : RB_PROXY_METHOD_WITH_RET(const char*, NULL, GetUnitType, (), ())
211 0 : RB_PROXY_METHOD_WITH_RET(GDALColorInterp, GCI_Undefined, GetColorInterpretation, (), ())
212 0 : RB_PROXY_METHOD_WITH_RET(GDALColorTable*, NULL, GetColorTable, (), ())
213 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, Fill,
214 : (double dfRealValue, double dfImaginaryValue),
215 : (dfRealValue, dfImaginaryValue))
216 :
217 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetCategoryNames, ( char ** arg ), (arg))
218 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetNoDataValue, ( double arg ), (arg))
219 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetColorTable, ( GDALColorTable *arg ), (arg))
220 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetColorInterpretation,
221 : ( GDALColorInterp arg ), (arg))
222 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetOffset, ( double arg ), (arg))
223 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetScale, ( double arg ), (arg))
224 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetUnitType, ( const char * arg ), (arg))
225 :
226 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, GetStatistics,
227 : ( int bApproxOK, int bForce,
228 : double *pdfMin, double *pdfMax,
229 : double *pdfMean, double *padfStdDev ),
230 : (bApproxOK, bForce, pdfMin, pdfMax, pdfMean, padfStdDev))
231 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, ComputeStatistics,
232 : ( int bApproxOK,
233 : double *pdfMin, double *pdfMax,
234 : double *pdfMean, double *pdfStdDev,
235 : GDALProgressFunc pfn, void *pProgressData ),
236 : ( bApproxOK, pdfMin, pdfMax, pdfMean, pdfStdDev, pfn, pProgressData))
237 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetStatistics,
238 : ( double dfMin, double dfMax,
239 : double dfMean, double dfStdDev ),
240 : (dfMin, dfMax, dfMean, dfStdDev))
241 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, ComputeRasterMinMax,
242 : ( int arg1, double* arg2 ), (arg1, arg2))
243 :
244 0 : RB_PROXY_METHOD_WITH_RET(int, 0, HasArbitraryOverviews, (), ())
245 0 : RB_PROXY_METHOD_WITH_RET(int, 0, GetOverviewCount, (), ())
246 0 : RB_PROXY_METHOD_WITH_RET(GDALRasterBand*, NULL, GetOverview, (int arg1), (arg1))
247 0 : RB_PROXY_METHOD_WITH_RET(GDALRasterBand*, NULL, GetRasterSampleOverview,
248 : (int arg1), (arg1))
249 :
250 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, BuildOverviews,
251 : (const char * arg1, int arg2, int *arg3,
252 : GDALProgressFunc arg4, void * arg5),
253 : (arg1, arg2, arg3, arg4, arg5))
254 :
255 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, AdviseRead,
256 : ( int nXOff, int nYOff, int nXSize, int nYSize,
257 : int nBufXSize, int nBufYSize,
258 : GDALDataType eDT, char **papszOptions ),
259 : (nXOff, nYOff, nXSize, nYSize, nBufXSize, nBufYSize, eDT, papszOptions))
260 :
261 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, GetHistogram,
262 : ( double dfMin, double dfMax,
263 : int nBuckets, int * panHistogram,
264 : int bIncludeOutOfRange, int bApproxOK,
265 : GDALProgressFunc pfn, void *pProgressData ),
266 : (dfMin, dfMax, nBuckets, panHistogram, bIncludeOutOfRange,
267 : bApproxOK, pfn, pProgressData))
268 :
269 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, GetDefaultHistogram,
270 : (double *pdfMin, double *pdfMax,
271 : int *pnBuckets, int ** ppanHistogram,
272 : int bForce,
273 : GDALProgressFunc pfn, void *pProgressData ),
274 : (pdfMin, pdfMax, pnBuckets, ppanHistogram, bForce,
275 : pfn, pProgressData))
276 :
277 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetDefaultHistogram,
278 : ( double dfMin, double dfMax,
279 : int nBuckets, int * panHistogram ),
280 : (dfMin, dfMax, nBuckets, panHistogram))
281 :
282 0 : RB_PROXY_METHOD_WITH_RET(const GDALRasterAttributeTable *, NULL,
283 : GetDefaultRAT, (), ())
284 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, SetDefaultRAT,
285 : ( const GDALRasterAttributeTable * arg1), (arg1))
286 :
287 0 : RB_PROXY_METHOD_WITH_RET(GDALRasterBand*, NULL, GetMaskBand, (), ())
288 0 : RB_PROXY_METHOD_WITH_RET(int, 0, GetMaskFlags, (), ())
289 0 : RB_PROXY_METHOD_WITH_RET(CPLErr, CE_Failure, CreateMaskBand, ( int nFlags ), (nFlags))
290 :
291 : /************************************************************************/
292 : /* UnrefUnderlyingRasterBand() */
293 : /************************************************************************/
294 :
295 1664 : void GDALProxyRasterBand::UnrefUnderlyingRasterBand(GDALRasterBand* poUnderlyingRasterBand)
296 : {
297 1664 : }
|