1 /******************************************************************************
2 *
3 * Project: OpenGIS Simple Features Reference Implementation
4 * Purpose: Implements OGRLayerDecorator class
5 * Author: Even Rouault, even dot rouault at spatialys.com
6 *
7 ******************************************************************************
8 * Copyright (c) 2012-2013, Even Rouault <even dot rouault at spatialys.com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 ****************************************************************************/
28
29 #ifndef DOXYGEN_SKIP
30
31 #include "ogrlayerdecorator.h"
32
33 CPL_CVSID("$Id: ogrlayerdecorator.cpp 355b41831cd2685c85d1aabe5b95665a2c6e99b7 2019-06-19 17:07:04 +0200 Even Rouault $")
34
OGRLayerDecorator(OGRLayer * poDecoratedLayer,int bTakeOwnership)35 OGRLayerDecorator::OGRLayerDecorator( OGRLayer* poDecoratedLayer,
36 int bTakeOwnership ) :
37 m_poDecoratedLayer(poDecoratedLayer),
38 m_bHasOwnership(bTakeOwnership)
39 {
40 CPLAssert(poDecoratedLayer != nullptr);
41 SetDescription( poDecoratedLayer->GetDescription() );
42 }
43
~OGRLayerDecorator()44 OGRLayerDecorator::~OGRLayerDecorator()
45 {
46 if( m_bHasOwnership )
47 delete m_poDecoratedLayer;
48 }
49
GetSpatialFilter()50 OGRGeometry *OGRLayerDecorator::GetSpatialFilter()
51 {
52 if( !m_poDecoratedLayer ) return nullptr;
53 return m_poDecoratedLayer->GetSpatialFilter();
54 }
55
SetSpatialFilter(OGRGeometry * poGeom)56 void OGRLayerDecorator::SetSpatialFilter( OGRGeometry * poGeom )
57 {
58 if( !m_poDecoratedLayer ) return;
59 m_poDecoratedLayer->SetSpatialFilter(poGeom);
60 }
61
SetSpatialFilter(int iGeomField,OGRGeometry * poGeom)62 void OGRLayerDecorator::SetSpatialFilter( int iGeomField, OGRGeometry * poGeom )
63 {
64 if( !m_poDecoratedLayer ) return;
65 m_poDecoratedLayer->SetSpatialFilter(iGeomField, poGeom);
66 }
67
SetSpatialFilterRect(double dfMinX,double dfMinY,double dfMaxX,double dfMaxY)68 void OGRLayerDecorator::SetSpatialFilterRect( double dfMinX, double dfMinY,
69 double dfMaxX, double dfMaxY )
70 {
71 if( !m_poDecoratedLayer ) return;
72 m_poDecoratedLayer->SetSpatialFilterRect(dfMinX, dfMinY, dfMaxX, dfMaxY);
73 }
74
SetSpatialFilterRect(int iGeomField,double dfMinX,double dfMinY,double dfMaxX,double dfMaxY)75 void OGRLayerDecorator::SetSpatialFilterRect( int iGeomField, double dfMinX, double dfMinY,
76 double dfMaxX, double dfMaxY )
77 {
78 if( !m_poDecoratedLayer ) return;
79 m_poDecoratedLayer->SetSpatialFilterRect(iGeomField, dfMinX, dfMinY, dfMaxX, dfMaxY);
80 }
81
SetAttributeFilter(const char * poAttrFilter)82 OGRErr OGRLayerDecorator::SetAttributeFilter( const char * poAttrFilter )
83 {
84 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
85 return m_poDecoratedLayer->SetAttributeFilter(poAttrFilter);
86 }
87
ResetReading()88 void OGRLayerDecorator::ResetReading()
89 {
90 if( !m_poDecoratedLayer ) return;
91 m_poDecoratedLayer->ResetReading();
92 }
93
GetNextFeature()94 OGRFeature *OGRLayerDecorator::GetNextFeature()
95 {
96 if( !m_poDecoratedLayer ) return nullptr;
97 return m_poDecoratedLayer->GetNextFeature();
98 }
99
SetNextByIndex(GIntBig nIndex)100 OGRErr OGRLayerDecorator::SetNextByIndex( GIntBig nIndex )
101 {
102 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
103 return m_poDecoratedLayer->SetNextByIndex(nIndex);
104 }
105
GetFeature(GIntBig nFID)106 OGRFeature *OGRLayerDecorator::GetFeature( GIntBig nFID )
107 {
108 if( !m_poDecoratedLayer ) return nullptr;
109 return m_poDecoratedLayer->GetFeature(nFID);
110 }
111
ISetFeature(OGRFeature * poFeature)112 OGRErr OGRLayerDecorator::ISetFeature( OGRFeature *poFeature )
113 {
114 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
115 return m_poDecoratedLayer->SetFeature(poFeature);
116 }
117
ICreateFeature(OGRFeature * poFeature)118 OGRErr OGRLayerDecorator::ICreateFeature( OGRFeature *poFeature )
119 {
120 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
121 return m_poDecoratedLayer->CreateFeature(poFeature);
122 }
123
DeleteFeature(GIntBig nFID)124 OGRErr OGRLayerDecorator::DeleteFeature( GIntBig nFID )
125 {
126 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
127 return m_poDecoratedLayer->DeleteFeature(nFID);
128 }
129
GetName()130 const char* OGRLayerDecorator::GetName()
131 {
132 if( !m_poDecoratedLayer ) return GetDescription();
133 return m_poDecoratedLayer->GetName();
134 }
135
GetGeomType()136 OGRwkbGeometryType OGRLayerDecorator::GetGeomType()
137 {
138 if( !m_poDecoratedLayer ) return wkbNone;
139 return m_poDecoratedLayer->GetGeomType();
140 }
141
GetLayerDefn()142 OGRFeatureDefn *OGRLayerDecorator::GetLayerDefn()
143 {
144 if( !m_poDecoratedLayer ) return nullptr;
145 return m_poDecoratedLayer->GetLayerDefn();
146 }
147
GetSpatialRef()148 OGRSpatialReference *OGRLayerDecorator::GetSpatialRef()
149 {
150 if( !m_poDecoratedLayer ) return nullptr;
151 return m_poDecoratedLayer->GetSpatialRef();
152 }
153
GetFeatureCount(int bForce)154 GIntBig OGRLayerDecorator::GetFeatureCount( int bForce )
155 {
156 if( !m_poDecoratedLayer ) return 0;
157 return m_poDecoratedLayer->GetFeatureCount(bForce);
158 }
159
GetExtent(OGREnvelope * psExtent,int bForce)160 OGRErr OGRLayerDecorator::GetExtent(OGREnvelope *psExtent, int bForce)
161 {
162 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
163 return m_poDecoratedLayer->GetExtent(psExtent, bForce);
164 }
165
GetExtent(int iGeomField,OGREnvelope * psExtent,int bForce)166 OGRErr OGRLayerDecorator::GetExtent(int iGeomField, OGREnvelope *psExtent, int bForce)
167 {
168 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
169 return m_poDecoratedLayer->GetExtent(iGeomField, psExtent, bForce);
170 }
171
TestCapability(const char * pszCapability)172 int OGRLayerDecorator::TestCapability( const char * pszCapability )
173 {
174 if( !m_poDecoratedLayer ) return FALSE;
175 return m_poDecoratedLayer->TestCapability(pszCapability);
176 }
177
CreateField(OGRFieldDefn * poField,int bApproxOK)178 OGRErr OGRLayerDecorator::CreateField( OGRFieldDefn *poField,
179 int bApproxOK )
180 {
181 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
182 return m_poDecoratedLayer->CreateField(poField, bApproxOK);
183 }
184
DeleteField(int iField)185 OGRErr OGRLayerDecorator::DeleteField( int iField )
186 {
187 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
188 return m_poDecoratedLayer->DeleteField(iField);
189 }
190
ReorderFields(int * panMap)191 OGRErr OGRLayerDecorator::ReorderFields( int* panMap )
192 {
193 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
194 return m_poDecoratedLayer->ReorderFields(panMap);
195 }
196
AlterFieldDefn(int iField,OGRFieldDefn * poNewFieldDefn,int nFlagsIn)197 OGRErr OGRLayerDecorator::AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn, int nFlagsIn )
198 {
199 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
200 return m_poDecoratedLayer->AlterFieldDefn(iField, poNewFieldDefn, nFlagsIn);
201 }
202
CreateGeomField(OGRGeomFieldDefn * poField,int bApproxOK)203 OGRErr OGRLayerDecorator::CreateGeomField( OGRGeomFieldDefn *poField,
204 int bApproxOK )
205 {
206 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
207 return m_poDecoratedLayer->CreateGeomField(poField, bApproxOK);
208 }
209
SyncToDisk()210 OGRErr OGRLayerDecorator::SyncToDisk()
211 {
212 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
213 return m_poDecoratedLayer->SyncToDisk();
214 }
215
GetStyleTable()216 OGRStyleTable *OGRLayerDecorator::GetStyleTable()
217 {
218 if( !m_poDecoratedLayer ) return nullptr;
219 return m_poDecoratedLayer->GetStyleTable();
220 }
221
SetStyleTableDirectly(OGRStyleTable * poStyleTable)222 void OGRLayerDecorator::SetStyleTableDirectly( OGRStyleTable *poStyleTable )
223 {
224 if( !m_poDecoratedLayer ) return;
225 m_poDecoratedLayer->SetStyleTableDirectly(poStyleTable);
226 }
227
SetStyleTable(OGRStyleTable * poStyleTable)228 void OGRLayerDecorator::SetStyleTable(OGRStyleTable *poStyleTable)
229 {
230 if( !m_poDecoratedLayer ) return;
231 m_poDecoratedLayer->SetStyleTable(poStyleTable);
232 }
233
StartTransaction()234 OGRErr OGRLayerDecorator::StartTransaction()
235 {
236 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
237 return m_poDecoratedLayer->StartTransaction();
238 }
239
CommitTransaction()240 OGRErr OGRLayerDecorator::CommitTransaction()
241 {
242 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
243 return m_poDecoratedLayer->CommitTransaction();
244 }
245
RollbackTransaction()246 OGRErr OGRLayerDecorator::RollbackTransaction()
247 {
248 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
249 return m_poDecoratedLayer->RollbackTransaction();
250 }
251
GetFIDColumn()252 const char *OGRLayerDecorator::GetFIDColumn()
253 {
254 if( !m_poDecoratedLayer ) return "";
255 return m_poDecoratedLayer->GetFIDColumn();
256 }
257
GetGeometryColumn()258 const char *OGRLayerDecorator::GetGeometryColumn()
259 {
260 if( !m_poDecoratedLayer ) return "";
261 return m_poDecoratedLayer->GetGeometryColumn();
262 }
263
SetIgnoredFields(const char ** papszFields)264 OGRErr OGRLayerDecorator::SetIgnoredFields( const char **papszFields )
265 {
266 if( !m_poDecoratedLayer ) return OGRERR_FAILURE;
267 return m_poDecoratedLayer->SetIgnoredFields(papszFields);
268 }
269
GetMetadata(const char * pszDomain)270 char **OGRLayerDecorator::GetMetadata( const char * pszDomain )
271 {
272 if( !m_poDecoratedLayer ) return nullptr;
273 return m_poDecoratedLayer->GetMetadata(pszDomain);
274 }
275
SetMetadata(char ** papszMetadata,const char * pszDomain)276 CPLErr OGRLayerDecorator::SetMetadata( char ** papszMetadata,
277 const char * pszDomain )
278 {
279 if( !m_poDecoratedLayer ) return CE_Failure;
280 return m_poDecoratedLayer->SetMetadata(papszMetadata, pszDomain);
281 }
282
GetMetadataItem(const char * pszName,const char * pszDomain)283 const char *OGRLayerDecorator::GetMetadataItem( const char * pszName,
284 const char * pszDomain )
285 {
286 if( !m_poDecoratedLayer ) return nullptr;
287 return m_poDecoratedLayer->GetMetadataItem(pszName, pszDomain);
288 }
289
SetMetadataItem(const char * pszName,const char * pszValue,const char * pszDomain)290 CPLErr OGRLayerDecorator::SetMetadataItem( const char * pszName,
291 const char * pszValue,
292 const char * pszDomain )
293 {
294 if( !m_poDecoratedLayer ) return CE_Failure;
295 return m_poDecoratedLayer->SetMetadataItem(pszName, pszValue, pszDomain);
296 }
297
298 #endif /* #ifndef DOXYGEN_SKIP */
299