1 : /******************************************************************************
2 : * $Id: ogrvrtdatasource.cpp 17506 2009-08-02 17:09:10Z 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 17506 2009-08-02 17:09:10Z rouault $");
35 : /************************************************************************/
36 : /* OGRVRTDataSource() */
37 : /************************************************************************/
38 :
39 16 : OGRVRTDataSource::OGRVRTDataSource()
40 :
41 : {
42 16 : pszName = NULL;
43 16 : papoLayers = NULL;
44 16 : nLayers = 0;
45 16 : }
46 :
47 : /************************************************************************/
48 : /* ~OGRVRTDataSource() */
49 : /************************************************************************/
50 :
51 32 : OGRVRTDataSource::~OGRVRTDataSource()
52 :
53 : {
54 : int i;
55 :
56 16 : CPLFree( pszName );
57 :
58 34 : for( i = 0; i < nLayers; i++ )
59 18 : delete papoLayers[i];
60 :
61 16 : CPLFree( papoLayers );
62 32 : }
63 :
64 : /************************************************************************/
65 : /* Initialize() */
66 : /************************************************************************/
67 :
68 16 : int OGRVRTDataSource::Initialize( CPLXMLNode *psTree, const char *pszNewName,
69 : int bUpdate )
70 :
71 : {
72 : CPLAssert( nLayers == 0 );
73 :
74 : /* -------------------------------------------------------------------- */
75 : /* Set name, and capture the directory path so we can use it */
76 : /* for relative datasources. */
77 : /* -------------------------------------------------------------------- */
78 16 : char *pszVRTDirectory = CPLStrdup( CPLGetPath( pszNewName ) );
79 :
80 16 : pszName = CPLStrdup( pszNewName );
81 :
82 : /* -------------------------------------------------------------------- */
83 : /* Look for layers. */
84 : /* -------------------------------------------------------------------- */
85 : CPLXMLNode *psLTree;
86 :
87 34 : for( psLTree=psTree->psChild; psLTree != NULL; psLTree=psLTree->psNext )
88 : {
89 18 : if( psLTree->eType != CXT_Element
90 : || !EQUAL(psLTree->pszValue,"OGRVRTLayer") )
91 0 : continue;
92 :
93 : /* -------------------------------------------------------------------- */
94 : /* Create the layer object. */
95 : /* -------------------------------------------------------------------- */
96 : OGRVRTLayer *poLayer;
97 :
98 18 : poLayer = new OGRVRTLayer();
99 :
100 18 : if( !poLayer->Initialize( psLTree, pszVRTDirectory, bUpdate ) )
101 : {
102 0 : CPLFree( pszVRTDirectory );
103 0 : delete poLayer;
104 0 : return FALSE;
105 : }
106 :
107 : /* -------------------------------------------------------------------- */
108 : /* Add layer to data source layer list. */
109 : /* -------------------------------------------------------------------- */
110 : papoLayers = (OGRVRTLayer **)
111 18 : CPLRealloc( papoLayers, sizeof(OGRVRTLayer *) * (nLayers+1) );
112 18 : papoLayers[nLayers++] = poLayer;
113 : }
114 :
115 16 : CPLFree( pszVRTDirectory );
116 16 : return TRUE;
117 : }
118 :
119 : /************************************************************************/
120 : /* TestCapability() */
121 : /************************************************************************/
122 :
123 0 : int OGRVRTDataSource::TestCapability( const char * pszCap )
124 :
125 : {
126 0 : return FALSE;
127 : }
128 :
129 : /************************************************************************/
130 : /* GetLayer() */
131 : /************************************************************************/
132 :
133 34 : OGRLayer *OGRVRTDataSource::GetLayer( int iLayer )
134 :
135 : {
136 34 : if( iLayer < 0 || iLayer >= nLayers )
137 0 : return NULL;
138 : else
139 34 : return papoLayers[iLayer];
140 : }
|