root/spike/sfcom_oledb/client/sfcenumerator.cpp

Revision 12207, 4.3 kB (checked in by warmerdam, 1 year ago)

segregate sfc/oledb client stuff into client directory for move to spike

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /******************************************************************************
2  * $Id$
3  *
4  * Project: OpenGIS Simple Features Reference Implementation
5  * Purpose: Simple Features Provider Enumerator (SFCEnumerator) implementation.
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 "sfcenumerator.h"
31 #include "sfcdatasource.h"
32 #include <stdio.h>
33
34 /************************************************************************/
35 /*                           IsOGISProvider()                           */
36 /************************************************************************/
37
38 /**
39  * Establish if the current provider (record) is OGIS complaint.
40  *
41  * The classid of the current provider record is looked up in the
42  * registry to see if OGISDataProvider is an implemented category for
43  * the provider.
44  */
45
46 int SFCEnumerator::IsOGISProvider()
47
48 {
49     long      lResult;
50     char      szRegPath[512];
51     HKEY      hKey;
52
53     sprintf( szRegPath,
54              "CLSID\\%S\\Implemented Categories\\"
55              "{A0690A28-FAF5-11D1-BAF5-080036DB0B03}", //CATID_OGISDataProvider
56              m_szParseName );
57
58     lResult = RegOpenKeyEx( HKEY_CLASSES_ROOT, szRegPath, 0L, KEY_READ,
59                             &hKey );
60
61     if( lResult == ERROR_SUCCESS )
62     {
63         RegCloseKey( hKey );
64         return TRUE;
65     }
66     else
67     {
68         return FALSE;
69     }
70 }
71
72 /************************************************************************/
73 /*                              OpenAny()                               */
74 /************************************************************************/
75
76 /**
77  * Try to open a datasource with any of the available providers till it
78  * works.
79  *
80  * @param pszDataSource the name of the data source to try and open.
81  *
82  * @return the data source opened, or NULL on failure. 
83  */
84
85 SFCDataSource * SFCEnumerator::OpenAny( const char * pszDataSource )
86
87 {
88 /* -------------------------------------------------------------------- */
89 /*      Reset to the beginning, and make a pass trying OpenGIS          */
90 /*      providers.                                                      */
91 /* -------------------------------------------------------------------- */
92     Close();
93     Open();
94
95     while( MoveNext() == S_OK )
96     {
97         SFCDataSource      *poDS;
98
99         if( !IsOGISProvider() )
100             continue;
101
102         poDS = new SFCDataSource();
103         if( !FAILED(poDS->Open( *this, pszDataSource )) )
104             return poDS;
105
106         delete poDS;
107     }
108    
109 /* -------------------------------------------------------------------- */
110 /*      Reset to the beginning, and make a pass trying non OpenGIS      */
111 /*      providers.                                                      */
112 /* -------------------------------------------------------------------- */
113     Close();
114     Open();
115
116     while( MoveNext() == S_OK )
117     {
118         SFCDataSource      *poDS;
119
120         if( IsOGISProvider() )
121             continue;
122
123         poDS = new SFCDataSource();
124         if( !FAILED(poDS->Open( *this, pszDataSource )) )
125             return poDS;
126
127         delete poDS;
128     }
129    
130     return NULL;
131 }
Note: See TracBrowser for help on using the browser.