Line data Source code
1 : /******************************************************************************
2 : * Project: Selafin importer
3 : * Purpose: Definition of classes for OGR driver for Selafin files.
4 : * Author: François Hissel, francois.hissel@gmail.com
5 : *
6 : ******************************************************************************
7 : * Copyright (c) 2014, François Hissel <francois.hissel@gmail.com>
8 : *
9 : * Permission is hereby granted, free of charge, to any person obtaining a
10 : * copy of this software and associated documentation files (the "Software"),
11 : * to deal in the Software without restriction, including without limitation
12 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 : * and/or sell copies of the Software, and to permit persons to whom the
14 : * Software is furnished to do so, subject to the following conditions:
15 : *
16 : * The above copyright notice and this permission notice shall be included
17 : * in all copies or substantial portions of the Software.
18 : *
19 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 : * DEALINGS IN THE SOFTWARE.
26 : ****************************************************************************/
27 :
28 : #ifndef OGR_SELAFIN_H_INCLUDED
29 : #define OGR_SELAFIN_H_INCLUDED
30 :
31 : #include "io_selafin.h"
32 : #include "ogrsf_frmts.h"
33 :
34 : class OGRSelafinDataSource;
35 :
36 : typedef enum
37 : {
38 : POINTS,
39 : ELEMENTS,
40 : ALL
41 : } SelafinTypeDef;
42 :
43 : /************************************************************************/
44 : /* Range */
45 : /************************************************************************/
46 : class Range
47 : {
48 : private:
49 : typedef struct List
50 : {
51 : SelafinTypeDef eType;
52 : int nMin, nMax;
53 : List *poNext;
54 :
55 : List() : eType(POINTS), nMin(0), nMax(0), poNext(nullptr)
56 : {
57 : }
58 :
59 0 : List(SelafinTypeDef eTypeP, int nMinP, int nMaxP, List *poNextP)
60 0 : : eType(eTypeP), nMin(nMinP), nMax(nMaxP), poNext(poNextP)
61 : {
62 0 : }
63 : } List;
64 :
65 : List *poVals, *poActual;
66 : int nMaxValue;
67 : static void sortList(List *&poList, List *poEnd = nullptr);
68 : static void deleteList(List *poList);
69 :
70 : public:
71 20060 : Range() : poVals(nullptr), poActual(nullptr), nMaxValue(0)
72 : {
73 20060 : }
74 :
75 : void setRange(const char *pszStr);
76 : ~Range();
77 : void setMaxValue(int nMaxValueP);
78 : bool contains(SelafinTypeDef eType, int nValue) const;
79 : size_t getSize() const;
80 : };
81 :
82 : /************************************************************************/
83 : /* OGRSelafinLayer */
84 : /************************************************************************/
85 :
86 : class OGRSelafinLayer final : public OGRLayer
87 : {
88 : private:
89 : GDALDataset *m_poDS = nullptr;
90 : SelafinTypeDef eType;
91 : bool bUpdate;
92 : int nStepNumber;
93 : Selafin::Header *poHeader;
94 : OGRFeatureDefn *poFeatureDefn;
95 : OGRSpatialReference *poSpatialRef;
96 : GIntBig nCurrentId;
97 :
98 : public:
99 : OGRSelafinLayer(GDALDataset *poDS, const char *pszLayerNameP, int bUpdateP,
100 : const OGRSpatialReference *poSpatialRefP,
101 : Selafin::Header *poHeaderP, int nStepNumberP,
102 : SelafinTypeDef eTypeP);
103 : ~OGRSelafinLayer();
104 :
105 0 : OGRSpatialReference *GetSpatialRef() override
106 : {
107 0 : return poSpatialRef;
108 : }
109 :
110 5 : int GetStepNumber()
111 : {
112 5 : return nStepNumber;
113 : }
114 :
115 : OGRFeature *GetNextFeature() override;
116 : OGRFeature *GetFeature(GIntBig nFID) override;
117 : void ResetReading() override;
118 : OGRErr SetNextByIndex(GIntBig nIndex) override;
119 :
120 133 : OGRFeatureDefn *GetLayerDefn() override
121 : {
122 133 : return poFeatureDefn;
123 : }
124 :
125 : int TestCapability(const char *pszCap) override;
126 : GIntBig GetFeatureCount(int bForce = TRUE) override;
127 : OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE) override;
128 :
129 0 : virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent,
130 : int bForce) override
131 : {
132 0 : return OGRLayer::GetExtent(iGeomField, psExtent, bForce);
133 : }
134 :
135 : OGRErr ISetFeature(OGRFeature *poFeature) override;
136 : OGRErr ICreateFeature(OGRFeature *poFeature) override;
137 : OGRErr CreateField(const OGRFieldDefn *poField,
138 : int bApproxOK = TRUE) override;
139 : OGRErr DeleteField(int iField) override;
140 : OGRErr ReorderFields(int *panMap) override;
141 : OGRErr AlterFieldDefn(int iField, OGRFieldDefn *poNewFieldDefn,
142 : int nFlags) override;
143 : OGRErr DeleteFeature(GIntBig nFID) override;
144 :
145 2 : GDALDataset *GetDataset() override
146 : {
147 2 : return m_poDS;
148 : }
149 : };
150 :
151 : /************************************************************************/
152 : /* OGRSelafinDataSource */
153 : /************************************************************************/
154 :
155 : class OGRSelafinDataSource final : public OGRDataSource
156 : {
157 : private:
158 : char *pszName;
159 : OGRSelafinLayer **papoLayers;
160 : Range poRange;
161 : int nLayers;
162 : bool bUpdate;
163 : Selafin::Header *poHeader;
164 : CPLString osDefaultSelafinName;
165 : OGRSpatialReference *poSpatialRef;
166 :
167 : public:
168 : OGRSelafinDataSource();
169 : virtual ~OGRSelafinDataSource();
170 : int Open(const char *pszFilename, int bUpdate, int bCreate);
171 : int OpenTable(const char *pszFilename);
172 :
173 0 : const char *GetName() override
174 : {
175 0 : return pszName;
176 : }
177 :
178 18 : int GetLayerCount() override
179 : {
180 18 : return nLayers;
181 : }
182 :
183 : OGRLayer *GetLayer(int) override;
184 :
185 : OGRLayer *ICreateLayer(const char *pszName,
186 : const OGRGeomFieldDefn *poGeomFieldDefn,
187 : CSLConstList papszOptions) override;
188 :
189 : virtual OGRErr DeleteLayer(int) override;
190 : int TestCapability(const char *) override;
191 :
192 : void SetDefaultSelafinName(const char *pszNameIn)
193 : {
194 : osDefaultSelafinName = pszNameIn;
195 : }
196 : };
197 :
198 : #endif /* ndef OGR_SELAFIN_H_INCLUDED */
|