1 : /******************************************************************************
2 : * $Id: ogrsfdriver.cpp 16319 2009-02-13 23:17:58Z 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 16319 2009-02-13 23:17:58Z rouault $");
35 :
36 : /************************************************************************/
37 : /* ~OGRSFDriver() */
38 : /************************************************************************/
39 :
40 1440 : OGRSFDriver::~OGRSFDriver()
41 :
42 : {
43 1440 : }
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 76 : OGRDataSourceH OGR_Dr_CreateDataSource( OGRSFDriverH hDriver,
63 : const char *pszName,
64 : char ** papszOptions )
65 :
66 : {
67 76 : VALIDATE_POINTER1( hDriver, "OGR_Dr_CreateDataSource", NULL );
68 :
69 76 : OGRSFDriver* poDriver = (OGRSFDriver *) hDriver;
70 : CPLAssert( NULL != poDriver );
71 :
72 76 : OGRDataSource* poDS = NULL;
73 76 : poDS = poDriver->CreateDataSource( pszName, papszOptions );
74 :
75 : /* This fix is explained in Ticket #1223 */
76 76 : if( NULL != poDS )
77 : {
78 76 : poDS->SetDriver( poDriver );
79 : CPLAssert( NULL != poDS->GetDriver() );
80 : }
81 : else
82 : {
83 0 : CPLDebug( "OGR", "CreateDataSource operation failed. NULL pointer returned." );
84 : }
85 :
86 76 : 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 52 : OGRErr OGR_Dr_DeleteDataSource( OGRSFDriverH hDriver,
108 : const char *pszDataSource )
109 :
110 : {
111 52 : VALIDATE_POINTER1( hDriver, "OGR_Dr_DeleteDataSource",
112 : OGRERR_INVALID_HANDLE );
113 :
114 52 : return ((OGRSFDriver *) hDriver)->DeleteDataSource( pszDataSource );
115 : }
116 :
117 : /************************************************************************/
118 : /* OGR_Dr_GetName() */
119 : /************************************************************************/
120 :
121 2 : const char *OGR_Dr_GetName( OGRSFDriverH hDriver )
122 :
123 : {
124 2 : VALIDATE_POINTER1( hDriver, "OGR_Dr_GetName", NULL );
125 :
126 2 : return ((OGRSFDriver *) hDriver)->GetName();
127 : }
128 :
129 : /************************************************************************/
130 : /* OGR_Dr_Open() */
131 : /************************************************************************/
132 :
133 49 : OGRDataSourceH OGR_Dr_Open( OGRSFDriverH hDriver, const char *pszName,
134 : int bUpdate )
135 :
136 : {
137 49 : VALIDATE_POINTER1( hDriver, "OGR_Dr_Open", NULL );
138 :
139 49 : OGRDataSource *poDS = ((OGRSFDriver *)hDriver)->Open( pszName, bUpdate );
140 :
141 49 : if( poDS != NULL && poDS->GetDriver() == NULL )
142 49 : poDS->SetDriver( (OGRSFDriver *)hDriver );
143 :
144 49 : return (OGRDataSourceH) poDS;
145 : }
146 :
147 : /************************************************************************/
148 : /* OGR_Dr_TestCapability() */
149 : /************************************************************************/
150 :
151 2 : int OGR_Dr_TestCapability( OGRSFDriverH hDriver, const char *pszCap )
152 :
153 : {
154 2 : VALIDATE_POINTER1( hDriver, "OGR_Dr_TestCapability", 0 );
155 2 : VALIDATE_POINTER1( pszCap, "OGR_Dr_TestCapability", 0 );
156 :
157 2 : return ((OGRSFDriver *) hDriver)->TestCapability( pszCap );
158 : }
159 :
160 : /************************************************************************/
161 : /* CopyDataSource() */
162 : /************************************************************************/
163 :
164 0 : OGRDataSource *OGRSFDriver::CopyDataSource( OGRDataSource *poSrcDS,
165 : const char *pszNewName,
166 : char **papszOptions )
167 :
168 : {
169 0 : 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 0 : poODS = CreateDataSource( pszNewName, papszOptions );
180 0 : if( poODS == NULL )
181 0 : return NULL;
182 :
183 : /* -------------------------------------------------------------------- */
184 : /* Process each data source layer. */
185 : /* -------------------------------------------------------------------- */
186 0 : for( int iLayer = 0; iLayer < poSrcDS->GetLayerCount(); iLayer++ )
187 : {
188 0 : OGRLayer *poLayer = poSrcDS->GetLayer(iLayer);
189 :
190 0 : if( poLayer == NULL )
191 0 : continue;
192 :
193 0 : poODS->CopyLayer( poLayer, poLayer->GetLayerDefn()->GetName(),
194 0 : papszOptions );
195 : }
196 :
197 0 : return poODS;
198 : }
199 :
200 : /************************************************************************/
201 : /* OGR_Dr_CopyDataSource() */
202 : /************************************************************************/
203 :
204 0 : OGRDataSourceH OGR_Dr_CopyDataSource( OGRSFDriverH hDriver,
205 : OGRDataSourceH hSrcDS,
206 : const char *pszNewName,
207 : char **papszOptions )
208 :
209 : {
210 0 : VALIDATE_POINTER1( hDriver, "OGR_Dr_CopyDataSource", NULL );
211 0 : VALIDATE_POINTER1( hSrcDS, "OGR_Dr_CopyDataSource", NULL );
212 :
213 : return (OGRDataSourceH)
214 : ((OGRSFDriver *) hDriver)->CopyDataSource(
215 0 : (OGRDataSource *) hSrcDS, pszNewName, papszOptions );
216 : }
217 :
|