Coverage Report

Created: 2026-08-14 09:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/ogr/ogrsf_frmts/nas/nasreaderp.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  NAS Reader
4
 * Purpose:  Private Declarations for OGR NAS Reader code.
5
 * Author:   Frank Warmerdam, warmerdam@pobox.com
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2008, Frank Warmerdam
9
 * Copyright (c) 2010-2013, Even Rouault <even dot rouault at spatialys.com>
10
 *
11
 * SPDX-License-Identifier: MIT
12
 ****************************************************************************/
13
14
#ifndef CPL_NASREADERP_H_INCLUDED
15
#define CPL_NASREADERP_H_INCLUDED
16
17
#include "xercesc_headers.h"
18
#include "ogr_xerces.h"
19
20
#include "gmlreader.h"
21
#include "gmlreaderp.h"
22
#include "ogr_api.h"
23
#include "ogr_geometry.h"
24
#include "cpl_string.h"
25
#include <list>
26
27
IGMLReader *CreateNASReader();
28
29
class NASReader;
30
31
CPL_C_START
32
OGRGeometryH OGR_G_CreateFromGML3(const char *pszGML);
33
CPL_C_END
34
35
/************************************************************************/
36
/*                              NASHandler                              */
37
/************************************************************************/
38
class NASHandler final : public DefaultHandler
39
{
40
    NASReader *m_poReader;
41
42
    char *m_pszCurField;
43
44
    char *m_pszGeometry;
45
    int m_nGeomAlloc;
46
    int m_nGeomLen;
47
48
    int m_nGeometryDepth;
49
    int m_nGeometryPropertyIndex;
50
    bool IsGeometryElement(const char *);
51
52
    int m_nDepth;
53
    int m_nDepthFeature;
54
    bool m_bIgnoreFeature;
55
56
    CPLString m_osDeleteContext;
57
    CPLString m_osTypeName;
58
    CPLString m_osReplacingFID;
59
    CPLString m_osSafeToIgnore;
60
    CPLString m_osUpdatePropertyName;
61
    CPLString m_osUpdateEnds;
62
    CPLString m_osFeatureId;
63
    std::list<CPLString> m_UpdateOccasions;
64
65
    CPLString m_osElementName;
66
    CPLString m_osCharacters;
67
68
    const Locator *m_Locator;
69
70
    int m_nEntityCounter = 0;
71
72
  public:
73
    explicit NASHandler(NASReader *poReader);
74
    ~NASHandler() override;
75
76
    void startElement(const XMLCh *const uri, const XMLCh *const localname,
77
                      const XMLCh *const qname,
78
                      const Attributes &attrs) override;
79
    void endElement(const XMLCh *const uri, const XMLCh *const localname,
80
                    const XMLCh *const qname) override;
81
#if XERCES_VERSION_MAJOR >= 3
82
    void characters(const XMLCh *const chars, const XMLSize_t length) override;
83
#else
84
    void characters(const XMLCh *const chars, const unsigned int length);
85
#endif
86
87
    void fatalError(const SAXParseException &) override;
88
89
    void startEntity(const XMLCh *const name) override;
90
91
    void setDocumentLocator(const Locator *locator) override;
92
93
    static CPLString GetAttributes(const Attributes *attr);
94
};
95
96
/************************************************************************/
97
/*                             GMLReadState                             */
98
/************************************************************************/
99
100
// for now, use existing gmlreadstate.
101
#ifdef notdef
102
class GMLReadState
103
{
104
    void RebuildPath();
105
106
  public:
107
    GMLReadState();
108
    ~GMLReadState();
109
110
    void PushPath(const char *pszElement);
111
    void PopPath();
112
113
    int MatchPath(const char *pszPathInput);
114
115
    const char *GetPath() const
116
    {
117
        return m_pszPath;
118
    }
119
120
    const char *GetLastComponent() const;
121
122
    GMLFeature *m_poFeature;
123
    GMLReadState *m_poParentState;
124
125
    char *m_pszPath;  // element path ... | as separator.
126
127
    int m_nPathLength;
128
    char **m_papszPathComponents;
129
};
130
#endif
131
132
/************************************************************************/
133
/*                              NASReader                               */
134
/************************************************************************/
135
136
class NASReader final : public IGMLReader
137
{
138
  private:
139
    bool m_bClassListLocked;
140
141
    int m_nClassCount;
142
    GMLFeatureClass **m_papoClass;
143
144
    char *m_pszFilename;
145
146
    NASHandler *m_poNASHandler;
147
    SAX2XMLReader *m_poSAXReader;
148
    bool m_bReadStarted;
149
    bool m_bXercesInitialized;
150
    XMLPScanToken m_oToFill;
151
152
    GMLReadState *m_poState;
153
154
    GMLFeature *m_poCompleteFeature;
155
    VSILFILE *m_fp;
156
    InputSource *m_GMLInputSource;
157
158
    bool SetupParser();
159
    void CleanupParser();
160
161
    char *m_pszFilteredClassName;
162
    bool m_bStopParsing = false;
163
164
  public:
165
    NASReader();
166
    ~NASReader() override;
167
168
    bool IsClassListLocked() const override
169
0
    {
170
0
        return m_bClassListLocked;
171
0
    }
172
173
    void SetClassListLocked(bool bFlag) override
174
0
    {
175
0
        m_bClassListLocked = bFlag;
176
0
    }
177
178
    void SetSourceFile(const char *pszFilename) override;
179
    const char *GetSourceFileName() override;
180
181
    int GetClassCount() const override
182
0
    {
183
0
        return m_nClassCount;
184
0
    }
185
186
    GMLFeatureClass *GetClass(int i) const override;
187
    GMLFeatureClass *GetClass(const char *pszName) const override;
188
189
    int AddClass(GMLFeatureClass *poClass) override;
190
    void ClearClasses() override;
191
192
    GMLFeature *NextFeature() override;
193
194
    bool LoadClasses(const char *pszFile = nullptr) override;
195
    bool SaveClasses(const char *pszFile = nullptr) override;
196
197
    bool PrescanForSchema(bool bGetExtents = true,
198
                          bool bOnlyDetectSRS = false) override;
199
    bool PrescanForTemplate() override;
200
    void ResetReading() override;
201
202
    bool ParseXSD(const char * /* pszFile */)
203
0
    {
204
0
        return false;
205
0
    }
206
207
    bool ResolveXlinks(const char *pszFile, bool *pbOutIsTempFile,
208
                       char **papszSkip = nullptr,
209
                       const bool bStrict = false) override;
210
211
    bool HugeFileResolver(const char *pszFile, bool bSqliteIsTempFile,
212
                          int iSqliteCacheMB) override;
213
214
    // ---
215
216
    GMLReadState *GetState() const
217
0
    {
218
0
        return m_poState;
219
0
    }
220
221
    void PopState();
222
    void PushState(GMLReadState *);
223
224
    bool IsFeatureElement(const char *pszElement);
225
    bool IsAttributeElement(const char *pszElement, const Attributes &attrs);
226
227
    void PushFeature(const char *pszElement, const Attributes &attrs);
228
229
    void SetFeaturePropertyDirectly(const char *pszElement, char *pszValue);
230
231
    void StopParsing()
232
0
    {
233
0
        m_bStopParsing = true;
234
0
    }
235
236
    bool HasStoppedParsing() override
237
0
    {
238
0
        return m_bStopParsing;
239
0
    }
240
241
    int GetAttributeElementIndex(const char *pszElement, int nLen,
242
                                 const char *pszAttrKey);
243
    void DealWithAttributes(const char *pszElement, int nLenName,
244
                            const Attributes &attrs);
245
246
    const char *GetGlobalSRSName() override
247
0
    {
248
0
        return nullptr;
249
0
    }
250
251
    bool CanUseGlobalSRSName() override
252
0
    {
253
0
        return false;
254
0
    }
255
256
    bool SetFilteredClassName(const char *pszClassName) override;
257
258
    const char *GetFilteredClassName() override
259
0
    {
260
0
        return m_pszFilteredClassName;
261
0
    }
262
263
    static std::unique_ptr<OGRGeometry>
264
        ConvertGeometry(std::unique_ptr<OGRGeometry>);
265
};
266
267
#endif /* CPL_NASREADERP_H_INCLUDED */