1 : /******************************************************************************
2 : * $Id: ogrs57driver.cpp 10645 2007-01-18 02:22:39Z warmerdam $
3 : *
4 : * Project: S-57 Translator
5 : * Purpose: Implements OGRS57Driver
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 1999, Frank Warmerdam
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 "ogr_s57.h"
31 : #include "cpl_conv.h"
32 :
33 : CPL_CVSID("$Id: ogrs57driver.cpp 10645 2007-01-18 02:22:39Z warmerdam $");
34 :
35 : S57ClassRegistrar *OGRS57Driver::poRegistrar = NULL;
36 :
37 : /************************************************************************/
38 : /* OGRS57Driver() */
39 : /************************************************************************/
40 :
41 389 : OGRS57Driver::OGRS57Driver()
42 :
43 : {
44 389 : }
45 :
46 : /************************************************************************/
47 : /* ~OGRS57Driver() */
48 : /************************************************************************/
49 :
50 369 : OGRS57Driver::~OGRS57Driver()
51 :
52 : {
53 369 : if( poRegistrar != NULL )
54 : {
55 2 : delete poRegistrar;
56 2 : poRegistrar = NULL;
57 : }
58 369 : }
59 :
60 : /************************************************************************/
61 : /* GetName() */
62 : /************************************************************************/
63 :
64 23865 : const char *OGRS57Driver::GetName()
65 :
66 : {
67 23865 : return "S57";
68 : }
69 :
70 : /************************************************************************/
71 : /* Open() */
72 : /************************************************************************/
73 :
74 1482 : OGRDataSource *OGRS57Driver::Open( const char * pszFilename, int bUpdate )
75 :
76 : {
77 : OGRS57DataSource *poDS;
78 :
79 1482 : poDS = new OGRS57DataSource;
80 1482 : if( !poDS->Open( pszFilename, TRUE ) )
81 : {
82 1470 : delete poDS;
83 1470 : poDS = NULL;
84 : }
85 :
86 1482 : if( poDS && bUpdate )
87 : {
88 0 : delete poDS;
89 : CPLError( CE_Failure, CPLE_OpenFailed,
90 0 : "S57 Driver doesn't support update." );
91 0 : return NULL;
92 : }
93 :
94 1482 : return poDS;
95 : }
96 :
97 : /************************************************************************/
98 : /* CreateDataSource() */
99 : /************************************************************************/
100 :
101 0 : OGRDataSource *OGRS57Driver::CreateDataSource( const char *pszName,
102 : char **papszOptions )
103 :
104 : {
105 0 : OGRS57DataSource *poDS = new OGRS57DataSource();
106 :
107 0 : if( poDS->Create( pszName, papszOptions ) )
108 0 : return poDS;
109 : else
110 : {
111 0 : delete poDS;
112 0 : return NULL;
113 : }
114 : }
115 :
116 : /************************************************************************/
117 : /* TestCapability() */
118 : /************************************************************************/
119 :
120 0 : int OGRS57Driver::TestCapability( const char * pszCap )
121 :
122 : {
123 0 : if( EQUAL(pszCap,ODrCCreateDataSource) )
124 0 : return TRUE;
125 : else
126 0 : return FALSE;
127 : }
128 :
129 : /************************************************************************/
130 : /* GetS57Registrar() */
131 : /************************************************************************/
132 :
133 390 : S57ClassRegistrar *OGRS57Driver::GetS57Registrar()
134 :
135 : {
136 : /* -------------------------------------------------------------------- */
137 : /* Instantiate the class registrar if possible. */
138 : /* -------------------------------------------------------------------- */
139 390 : if( poRegistrar == NULL )
140 : {
141 2 : poRegistrar = new S57ClassRegistrar();
142 :
143 2 : if( !poRegistrar->LoadInfo( NULL, NULL, FALSE ) )
144 : {
145 0 : delete poRegistrar;
146 0 : poRegistrar = NULL;
147 : }
148 : }
149 :
150 390 : return poRegistrar;
151 : }
152 :
153 : /************************************************************************/
154 : /* RegisterOGRS57() */
155 : /************************************************************************/
156 :
157 389 : void RegisterOGRS57()
158 :
159 : {
160 389 : OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( new OGRS57Driver );
161 389 : }
162 :
163 :
|