1 : /******************************************************************************
2 : * $Id: ogrvrtdatasource.cpp 23575 2011-12-14 20:24:08Z rouault $
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: Implements OGRVRTDataSource class.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2003, Frank Warmerdam <warmerdam@pobox.com>
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_vrt.h"
31 : #include "cpl_conv.h"
32 : #include "cpl_string.h"
33 :
34 : CPL_CVSID("$Id: ogrvrtdatasource.cpp 23575 2011-12-14 20:24:08Z rouault $");
35 :
36 : /************************************************************************/
37 : /* OGRVRTDataSource() */
38 : /************************************************************************/
39 :
40 111 : OGRVRTDataSource::OGRVRTDataSource()
41 :
42 : {
43 111 : pszName = NULL;
44 111 : papoLayers = NULL;
45 111 : nLayers = 0;
46 111 : psTree = NULL;
47 111 : nCallLevel = 0;
48 111 : }
49 :
50 : /************************************************************************/
51 : /* ~OGRVRTDataSource() */
52 : /************************************************************************/
53 :
54 111 : OGRVRTDataSource::~OGRVRTDataSource()
55 :
56 : {
57 : int i;
58 :
59 111 : CPLFree( pszName );
60 :
61 327 : for( i = 0; i < nLayers; i++ )
62 216 : delete papoLayers[i];
63 :
64 111 : CPLFree( papoLayers );
65 :
66 111 : if( psTree != NULL)
67 111 : CPLDestroyXMLNode( psTree );
68 111 : }
69 :
70 : /************************************************************************/
71 : /* Initialize() */
72 : /************************************************************************/
73 :
74 111 : int OGRVRTDataSource::Initialize( CPLXMLNode *psTree, const char *pszNewName,
75 : int bUpdate )
76 :
77 : {
78 111 : CPLAssert( nLayers == 0 );
79 :
80 111 : this->psTree = psTree;
81 :
82 : /* -------------------------------------------------------------------- */
83 : /* Set name, and capture the directory path so we can use it */
84 : /* for relative datasources. */
85 : /* -------------------------------------------------------------------- */
86 111 : char *pszVRTDirectory = CPLStrdup( CPLGetPath( pszNewName ) );
87 :
88 111 : pszName = CPLStrdup( pszNewName );
89 :
90 : /* -------------------------------------------------------------------- */
91 : /* Look for layers. */
92 : /* -------------------------------------------------------------------- */
93 : CPLXMLNode *psLTree;
94 :
95 327 : for( psLTree=psTree->psChild; psLTree != NULL; psLTree=psLTree->psNext )
96 : {
97 216 : if( psLTree->eType != CXT_Element
98 : || !EQUAL(psLTree->pszValue,"OGRVRTLayer") )
99 0 : continue;
100 :
101 : /* -------------------------------------------------------------------- */
102 : /* Create the layer object. */
103 : /* -------------------------------------------------------------------- */
104 : OGRVRTLayer *poLayer;
105 :
106 216 : poLayer = new OGRVRTLayer(this);
107 :
108 216 : if( !poLayer->FastInitialize( psLTree, pszVRTDirectory, bUpdate ) )
109 : {
110 0 : CPLFree( pszVRTDirectory );
111 0 : delete poLayer;
112 0 : return FALSE;
113 : }
114 :
115 : /* -------------------------------------------------------------------- */
116 : /* Add layer to data source layer list. */
117 : /* -------------------------------------------------------------------- */
118 : papoLayers = (OGRVRTLayer **)
119 216 : CPLRealloc( papoLayers, sizeof(OGRVRTLayer *) * (nLayers+1) );
120 216 : papoLayers[nLayers++] = poLayer;
121 : }
122 :
123 111 : CPLFree( pszVRTDirectory );
124 111 : return TRUE;
125 : }
126 :
127 : /************************************************************************/
128 : /* TestCapability() */
129 : /************************************************************************/
130 :
131 0 : int OGRVRTDataSource::TestCapability( const char * pszCap )
132 :
133 : {
134 0 : return FALSE;
135 : }
136 :
137 : /************************************************************************/
138 : /* GetLayer() */
139 : /************************************************************************/
140 :
141 208 : OGRLayer *OGRVRTDataSource::GetLayer( int iLayer )
142 :
143 : {
144 208 : if( iLayer < 0 || iLayer >= nLayers )
145 0 : return NULL;
146 : else
147 208 : return papoLayers[iLayer];
148 : }
149 :
150 : /************************************************************************/
151 : /* AddForbiddenNames() */
152 : /************************************************************************/
153 :
154 1 : void OGRVRTDataSource::AddForbiddenNames(const char* pszOtherDSName)
155 : {
156 1 : aosOtherDSNameSet.insert(pszOtherDSName);
157 1 : }
158 :
159 : /************************************************************************/
160 : /* IsInForbiddenNames() */
161 : /************************************************************************/
162 :
163 19 : int OGRVRTDataSource::IsInForbiddenNames(const char* pszOtherDSName)
164 : {
165 19 : return aosOtherDSNameSet.find(pszOtherDSName) != aosOtherDSNameSet.end();
166 : }
|