1 /******************************************************************************
2  * $Id: ogrogdi.h 8e5eeb35bf76390e3134a4ea7076dab7d478ea0e 2018-11-14 22:55:13 +0100 Even Rouault $
3  *
4  * Project:  OGDI Bridge
5  * Purpose:  Private definitions within the OGDI driver to implement
6  *           integration with OGR.
7  * Author:   Daniel Morissette, danmo@videotron.ca
8  *           (Based on some code contributed by Frank Warmerdam :)
9  *
10  ******************************************************************************
11  * Copyright (c) 2000,  Daniel Morissette
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included
21  * in all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29  * DEALINGS IN THE SOFTWARE.
30  ****************************************************************************/
31 
32 #ifndef OGDOGDI_H_INCLUDED
33 #define OGDOGDI_H_INCLUDED
34 
35 #include <math.h>
36 extern "C" {
37 /* Older versions of OGDI have register keywords as qualifier for arguments
38  * of functions, which is illegal in C++17 */
39 #define register
40 #include "ecs.h"
41 #undef register
42 }
43 #include "ogrsf_frmts.h"
44 
45 /************************************************************************/
46 /*                             OGROGDILayer                             */
47 /************************************************************************/
48 class OGROGDIDataSource;
49 
50 class OGROGDILayer final: public OGRLayer
51 {
52     OGROGDIDataSource  *m_poODS;
53     int                 m_nClientID;
54     char               *m_pszOGDILayerName;
55     ecs_Family          m_eFamily;
56 
57     OGRFeatureDefn     *m_poFeatureDefn;
58     OGRSpatialReference *m_poSpatialRef;
59     ecs_Region          m_sFilterBounds;
60 
61     int                 m_iNextShapeId;
62     int                 m_nTotalShapeCount;
63     int                 m_nFilteredOutShapes;
64 
65     OGRFeature *        GetNextRawFeature();
66 
67   public:
68                         OGROGDILayer(OGROGDIDataSource *, const char *,
69                                      ecs_Family);
70                         virtual ~OGROGDILayer();
71 
72     virtual void        SetSpatialFilter( OGRGeometry * ) override;
SetSpatialFilter(int iGeomField,OGRGeometry * poGeom)73     virtual void        SetSpatialFilter( int iGeomField, OGRGeometry *poGeom ) override
74                 { OGRLayer::SetSpatialFilter(iGeomField, poGeom); }
75     virtual OGRErr      SetAttributeFilter( const char *pszQuery ) override;
76 
77     void                ResetReading() override;
78     OGRFeature *        GetNextFeature() override;
79 
80     OGRFeature         *GetFeature( GIntBig nFeatureId ) override;
81 
GetLayerDefn()82     OGRFeatureDefn *    GetLayerDefn() override { return m_poFeatureDefn; }
83 
84     GIntBig             GetFeatureCount( int ) override;
85 
86     int                 TestCapability( const char * ) override;
87 
88   private:
89     void                BuildFeatureDefn();
90 };
91 
92 /************************************************************************/
93 /*                          OGROGDIDataSource                           */
94 /************************************************************************/
95 
96 class OGROGDIDataSource final: public OGRDataSource
97 {
98     OGROGDILayer      **m_papoLayers;
99     int                 m_nLayers;
100 
101     int                 m_nClientID;
102 
103     ecs_Region          m_sGlobalBounds;
104     OGRSpatialReference *m_poSpatialRef;
105 
106     OGROGDILayer        *m_poCurrentLayer;
107 
108     char                *m_pszFullName;
109 
110     int                 m_bLaunderLayerNames;
111 
112     void                IAddLayer( const char *pszLayerName,
113                                    ecs_Family eFamily );
114 
115   public:
116                         OGROGDIDataSource();
117                         ~OGROGDIDataSource();
118 
119     int                 Open( const char * );
120 
GetName()121     const char          *GetName() override { return m_pszFullName; }
GetLayerCount()122     int                 GetLayerCount() override { return m_nLayers; }
123     OGRLayer            *GetLayer( int ) override;
124 
125     int                 TestCapability( const char * ) override;
126 
GetGlobalBounds()127     ecs_Region         *GetGlobalBounds() { return &m_sGlobalBounds; }
DSGetSpatialRef()128     OGRSpatialReference*DSGetSpatialRef() { return m_poSpatialRef; }
GetClientID()129     int                 GetClientID() { return m_nClientID; }
130 
GetCurrentLayer()131     OGROGDILayer       *GetCurrentLayer() { return m_poCurrentLayer; }
SetCurrentLayer(OGROGDILayer * poLayer)132     void                SetCurrentLayer(OGROGDILayer* poLayer) { m_poCurrentLayer = poLayer ; }
133 
LaunderLayerNames()134     int                 LaunderLayerNames() { return m_bLaunderLayerNames; }
135 };
136 
137 /************************************************************************/
138 /*                            OGROGDIDriver                             */
139 /************************************************************************/
140 
141 class OGROGDIDriver final: public OGRSFDriver
142 {
143   public:
144                 ~OGROGDIDriver();
145 
146     const char *GetName() override;
147     OGRDataSource *Open( const char *, int ) override;
148 
149     int         TestCapability( const char * ) override;
150 };
151 
152 #endif /* OGDOGDI_H_INCLUDED */
153