1 : /******************************************************************************
2 : * $Id: ogrsqlitevirtualogr.h 24963 2012-09-24 19:51:15Z rouault $
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: SQLite Virtual Table module using OGR layers
6 : * Author: Even Rouault, even dot rouault at mines dash paris dot org
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2012, Even Rouault <even dot rouault at mines dash paris dot org>
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 : #ifndef _OGR_SQLITE_VIRTUAL_OGR_H_INCLUDED
31 : #define _OGR_SQLITE_VIRTUAL_OGR_H_INCLUDED
32 :
33 : #include "ogr_sqlite.h"
34 : #include <map>
35 : #include <vector>
36 :
37 : #ifdef HAVE_SQLITE_VFS
38 :
39 : /************************************************************************/
40 : /* OGR2SQLITEModule */
41 : /************************************************************************/
42 :
43 : class OGR2SQLITEModule
44 : {
45 : #ifdef DEBUG
46 : void* pDummy; /* to track memory leaks */
47 : #endif
48 : sqlite3* hDB; /* *NOT* to be freed */
49 :
50 : OGRDataSource* poDS; /* *NOT* to be freed */
51 : std::vector<OGRDataSource*> apoExtraDS; /* each datasource to be freed */
52 :
53 : OGRSQLiteDataSource* poSQLiteDS; /* *NOT* to be freed, might be NULL */
54 :
55 : std::map< std::pair<int,int>, OGRCoordinateTransformation*> oCachedTransformsMap;
56 :
57 : std::map< CPLString, OGRLayer* > oMapVTableToOGRLayer;
58 :
59 : void* hRegExpCache;
60 :
61 : public:
62 : OGR2SQLITEModule(OGRDataSource* poDS);
63 : ~OGR2SQLITEModule();
64 :
65 : int Setup(OGRSQLiteDataSource* poSQLiteDS);
66 : int Setup(sqlite3* hDB, int bAutoDestroy = FALSE);
67 : sqlite3* GetDBHandle() { return hDB; }
68 :
69 453 : OGRDataSource* GetDS() { return poDS; }
70 :
71 : OGRCoordinateTransformation* GetTransform(int nSrcSRSId, int nDstSRSId);
72 :
73 : int AddExtraDS(OGRDataSource* poDS);
74 : OGRDataSource *GetExtraDS(int nIndex);
75 :
76 : int FetchSRSId(OGRSpatialReference* poSRS);
77 :
78 : void RegisterVTable(const char* pszVTableName, OGRLayer* poLayer);
79 : void UnregisterVTable(const char* pszVTableName);
80 : OGRLayer* GetLayerForVTable(const char* pszVTableName);
81 :
82 15 : void SetRegExpCache(void* hRegExpCacheIn) { hRegExpCache = hRegExpCacheIn; }
83 : };
84 :
85 : void OGR2SQLITE_Register();
86 :
87 : CPLString OGR2SQLITE_GetNameForGeometryColumn(OGRLayer* poLayer);
88 :
89 : #endif // HAVE_SQLITE_VFS
90 :
91 : #endif // _OGR_SQLITE_VIRTUAL_OGR_H_INCLUDED
|