1 : /******************************************************************************
2 : * $Id: ogrsfdriver.cpp 23413 2011-11-22 21:53:32Z rouault $
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: The generic portions of the OGRSFDriver class.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 1999, Les Technologies SoftMap Inc.
10 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #include "ogrsf_frmts.h"
31 : #include "ogr_api.h"
32 : #include "ogr_p.h"
33 :
34 : CPL_CVSID("$Id: ogrsfdriver.cpp 23413 2011-11-22 21:53:32Z rouault $");
35 :
36 : /************************************************************************/
37 : /* ~OGRSFDriver() */
38 : /************************************************************************/
39 :
40 22509 : OGRSFDriver::~OGRSFDriver()
41 :
42 : {
43 22509 : }
44 :
45 : /************************************************************************/
46 : /* CreateDataSource() */
47 : /************************************************************************/
48 :
49 0 : OGRDataSource *OGRSFDriver::CreateDataSource( const char *, char ** )
50 :
51 : {
52 : CPLError( CE_Failure, CPLE_NotSupported,
53 0 : "CreateDataSource() not supported by this driver.\n" );
54 :
55 0 : return NULL;
56 : }
57 :
58 : /************************************************************************/
59 : /* OGR_Dr_CreateDataSource() */
60 : /************************************************************************/
61 :
62 436 : OGRDataSourceH OGR_Dr_CreateDataSource( OGRSFDriverH hDriver,
63 : const char *pszName,
64 : char ** papszOptions )
65 :
66 : {
67 436 : VALIDATE_POINTER1( hDriver, "OGR_Dr_CreateDataSource", NULL );
68 :
69 436 : OGRSFDriver* poDriver = (OGRSFDriver *) hDriver;
70 436 : CPLAssert( NULL != poDriver );
71 :
72 436 : OGRDataSource* poDS = NULL;
73 436 : poDS = poDriver->CreateDataSource( pszName, papszOptions );
74 :
75 : /* This fix is explained in Ticket #1223 */
76 436 : if( NULL != poDS )
77 : {
78 430 : poDS->SetDriver( poDriver );
79 430 : CPLAssert( NULL != poDS->GetDriver() );
80 : }
81 : else
82 : {
83 6 : CPLDebug( "OGR", "CreateDataSource operation failed. NULL pointer returned." );
84 : }
85 :
86 436 : return (OGRDataSourceH) poDS;
87 : }
88 :
89 : /************************************************************************/
90 : /* DeleteDataSource() */
91 : /************************************************************************/
92 :
93 0 : OGRErr OGRSFDriver::DeleteDataSource( const char *pszDataSource )
94 :
95 : {
96 : (void) pszDataSource;
97 : CPLError( CE_Failure, CPLE_NotSupported,
98 0 : "DeleteDataSource() not supported by this driver." );
99 :
100 0 : return OGRERR_UNSUPPORTED_OPERATION;
101 : }
102 :
103 : /************************************************************************/
104 : /* OGR_Dr_DeleteDataSource() */
105 : /************************************************************************/
106 :
107 302 : OGRErr OGR_Dr_DeleteDataSource( OGRSFDriverH hDriver,
108 : const char *pszDataSource )
109 :
110 : {
111 302 : VALIDATE_POINTER1( hDriver, "OGR_Dr_DeleteDataSource",
112 : OGRERR_INVALID_HANDLE );
113 :
114 302 : return ((OGRSFDriver *) hDriver)->DeleteDataSource( pszDataSource );
115 : }
116 :
117 : /************************************************************************/
118 : /* OGR_Dr_GetName() */
119 : /************************************************************************/
120 :
121 186 : const char *OGR_Dr_GetName( OGRSFDriverH hDriver )
122 :
123 : {
124 186 : VALIDATE_POINTER1( hDriver, "OGR_Dr_GetName", NULL );
125 :
126 186 : return ((OGRSFDriver *) hDriver)->GetName();
127 : }
128 :
129 : /************************************************************************/
130 : /* OGR_Dr_Open() */
131 : /************************************************************************/
132 :
133 112 : OGRDataSourceH OGR_Dr_Open( OGRSFDriverH hDriver, const char *pszName,
134 : int bUpdate )
135 :
136 : {
137 112 : VALIDATE_POINTER1( hDriver, "OGR_Dr_Open", NULL );
138 :
139 112 : OGRDataSource *poDS = ((OGRSFDriver *)hDriver)->Open( pszName, bUpdate );
140 :
141 112 : if( poDS != NULL && poDS->GetDriver() == NULL )
142 96 : poDS->SetDriver( (OGRSFDriver *)hDriver );
143 :
144 112 : return (OGRDataSourceH) poDS;
145 : }
146 :
147 : /************************************************************************/
148 : /* OGR_Dr_TestCapability() */
149 : /************************************************************************/
150 :
151 78 : int OGR_Dr_TestCapability( OGRSFDriverH hDriver, const char *pszCap )
152 :
153 : {
154 78 : VALIDATE_POINTER1( hDriver, "OGR_Dr_TestCapability", 0 );
155 78 : VALIDATE_POINTER1( pszCap, "OGR_Dr_TestCapability", 0 );
156 :
157 78 : return ((OGRSFDriver *) hDriver)->TestCapability( pszCap );
158 : }
159 :
160 : /************************************************************************/
161 : /* CopyDataSource() */
162 : /************************************************************************/
163 :
164 2 : OGRDataSource *OGRSFDriver::CopyDataSource( OGRDataSource *poSrcDS,
165 : const char *pszNewName,
166 : char **papszOptions )
167 :
168 : {
169 2 : if( !TestCapability( ODrCCreateDataSource ) )
170 : {
171 : CPLError( CE_Failure, CPLE_NotSupported,
172 : "%s driver does not support data source creation.",
173 0 : GetName() );
174 0 : return NULL;
175 : }
176 :
177 : OGRDataSource *poODS;
178 :
179 2 : poODS = CreateDataSource( pszNewName, papszOptions );
180 2 : if( poODS == NULL )
181 0 : return NULL;
182 :
183 : /* -------------------------------------------------------------------- */
184 : /* Process each data source layer. */
185 : /* -------------------------------------------------------------------- */
186 4 : for( int iLayer = 0; iLayer < poSrcDS->GetLayerCount(); iLayer++ )
187 : {
188 2 : OGRLayer *poLayer = poSrcDS->GetLayer(iLayer);
189 :
190 2 : if( poLayer == NULL )
191 0 : continue;
192 :
193 2 : poODS->CopyLayer( poLayer, poLayer->GetLayerDefn()->GetName(),
194 4 : papszOptions );
195 : }
196 :
197 : /* Make sure that the driver is attached to the created datasource */
198 : /* It is also done in OGR_Dr_CopyDataSource() C method, in case */
199 : /* another C++ implementation forgets to do it. Currently (Nov 2011), */
200 : /* this implementation is the only one in the OGR source tree */
201 2 : if( poODS != NULL && poODS->GetDriver() == NULL )
202 2 : poODS->SetDriver( this );
203 :
204 2 : return poODS;
205 : }
206 :
207 : /************************************************************************/
208 : /* OGR_Dr_CopyDataSource() */
209 : /************************************************************************/
210 :
211 2 : OGRDataSourceH OGR_Dr_CopyDataSource( OGRSFDriverH hDriver,
212 : OGRDataSourceH hSrcDS,
213 : const char *pszNewName,
214 : char **papszOptions )
215 :
216 : {
217 2 : VALIDATE_POINTER1( hDriver, "OGR_Dr_CopyDataSource", NULL );
218 2 : VALIDATE_POINTER1( hSrcDS, "OGR_Dr_CopyDataSource", NULL );
219 2 : VALIDATE_POINTER1( pszNewName, "OGR_Dr_CopyDataSource", NULL );
220 :
221 : OGRDataSource* poDS =
222 : ((OGRSFDriver *) hDriver)->CopyDataSource(
223 2 : (OGRDataSource *) hSrcDS, pszNewName, papszOptions );
224 :
225 : /* Make sure that the driver is attached to the created datasource */
226 : /* if not already done by the implementation of the CopyDataSource() */
227 : /* method */
228 2 : if( poDS != NULL && poDS->GetDriver() == NULL )
229 0 : poDS->SetDriver( (OGRSFDriver *)hDriver );
230 :
231 2 : return (OGRDataSourceH)poDS;
232 : }
233 :
|