1 : /******************************************************************************
2 : * $Id: nasreaderp.h 25120 2012-10-13 22:38:57Z rouault $
3 : *
4 : * Project: NAS Reader
5 : * Purpose: Private Declarations for OGR NAS Reader code.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2008, Frank Warmerdam
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 OR
22 : * 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 _CPL_NASREADERP_H_INCLUDED
31 : #define _CPL_NASREADERP_H_INCLUDED
32 :
33 : #include "gmlreader.h"
34 : #include "gmlreaderp.h"
35 : #include "ogr_api.h"
36 : #include "cpl_string.h"
37 :
38 : IGMLReader *CreateNASReader();
39 :
40 : class NASReader;
41 : class OGRNASRelationLayer;
42 :
43 : CPL_C_START
44 : OGRGeometryH OGR_G_CreateFromGML3( const char *pszGML );
45 : CPL_C_END
46 :
47 : /************************************************************************/
48 : /* NASHandler */
49 : /************************************************************************/
50 : class NASHandler : public DefaultHandler
51 : {
52 : NASReader *m_poReader;
53 :
54 : char *m_pszCurField;
55 :
56 : char *m_pszGeometry;
57 : int m_nGeomAlloc;
58 : int m_nGeomLen;
59 :
60 : int m_nGeometryDepth;
61 : int IsGeometryElement( const char * );
62 :
63 : int m_nDepth;
64 : int m_nDepthFeature;
65 : int m_bIgnoreFeature;
66 : int m_nDepthElement;
67 : CPLString m_osIgnoredElement;
68 :
69 : CPLString m_osLastTypeName;
70 : CPLString m_osLastReplacingFID;
71 : CPLString m_osLastSafeToIgnore;
72 :
73 : public:
74 : NASHandler( NASReader *poReader );
75 : virtual ~NASHandler();
76 :
77 : void startElement(
78 : const XMLCh* const uri,
79 : const XMLCh* const localname,
80 : const XMLCh* const qname,
81 : const Attributes& attrs
82 : );
83 : void endElement(
84 : const XMLCh* const uri,
85 : const XMLCh* const localname,
86 : const XMLCh* const qname
87 : );
88 : #if XERCES_VERSION_MAJOR >= 3
89 : void characters( const XMLCh *const chars,
90 : const XMLSize_t length );
91 : #else
92 : void characters( const XMLCh *const chars,
93 : const unsigned int length );
94 : #endif
95 :
96 : void fatalError(const SAXParseException&);
97 :
98 : CPLString GetAttributes( const Attributes* attr );
99 : };
100 :
101 : /************************************************************************/
102 : /* GMLReadState */
103 : /************************************************************************/
104 :
105 : // for now, use existing gmlreadstate.
106 : #ifdef notdef
107 : class GMLReadState
108 : {
109 : void RebuildPath();
110 :
111 : public:
112 : GMLReadState();
113 : ~GMLReadState();
114 :
115 : void PushPath( const char *pszElement );
116 : void PopPath();
117 :
118 : int MatchPath( const char *pszPathInput );
119 : const char *GetPath() const { return m_pszPath; }
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 : public IGMLReader
137 : {
138 : private:
139 : int 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 : int m_bReadStarted;
149 : XMLPScanToken m_oToFill;
150 :
151 : GMLReadState *m_poState;
152 :
153 : GMLFeature *m_poCompleteFeature;
154 :
155 : int SetupParser();
156 : void CleanupParser();
157 :
158 : char *m_pszFilteredClassName;
159 :
160 : public:
161 : NASReader();
162 : virtual ~NASReader();
163 :
164 69649 : int IsClassListLocked() const { return m_bClassListLocked; }
165 5 : void SetClassListLocked( int bFlag )
166 5 : { m_bClassListLocked = bFlag; }
167 :
168 : void SetSourceFile( const char *pszFilename );
169 : const char *GetSourceFileName();
170 :
171 1249720 : int GetClassCount() const { return m_nClassCount; }
172 : GMLFeatureClass *GetClass( int i ) const;
173 : GMLFeatureClass *GetClass( const char *pszName ) const;
174 :
175 : int AddClass( GMLFeatureClass *poClass );
176 : void ClearClasses();
177 :
178 : GMLFeature *NextFeature();
179 :
180 : int LoadClasses( const char *pszFile = NULL );
181 : int SaveClasses( const char *pszFile = NULL );
182 :
183 : int PrescanForSchema(int bGetExtents = TRUE );
184 : int PrescanForTemplate( void );
185 : void ResetReading();
186 :
187 : int ParseXSD( const char *pszFile ) { return FALSE; }
188 :
189 : int ResolveXlinks( const char *pszFile,
190 : int* pbOutIsTempFile,
191 : char **papszSkip = NULL,
192 : const int bStrict = FALSE );
193 :
194 : int HugeFileResolver( const char *pszFile,
195 : int bSqliteIsTempFile,
196 : int iSqliteCacheMB );
197 :
198 : // ---
199 :
200 4624731 : GMLReadState *GetState() const { return m_poState; }
201 : void PopState();
202 : void PushState( GMLReadState * );
203 :
204 : int IsFeatureElement( const char *pszElement );
205 : int IsAttributeElement( const char *pszElement );
206 :
207 : void PushFeature( const char *pszElement,
208 : const Attributes &attrs );
209 :
210 : void SetFeaturePropertyDirectly( const char *pszElement,
211 : char *pszValue );
212 :
213 0 : int HasStoppedParsing() { return FALSE; }
214 :
215 : void CheckForFID( const Attributes &attrs, char **ppszCurField );
216 : void CheckForRelations( const char *pszElement,
217 : const Attributes &attrs );
218 :
219 0 : virtual const char* GetGlobalSRSName() { return NULL; }
220 :
221 0 : virtual int CanUseGlobalSRSName() { return FALSE; }
222 :
223 : int SetFilteredClassName(const char* pszClassName);
224 69652 : const char* GetFilteredClassName() { return m_pszFilteredClassName; }
225 : };
226 :
227 : #endif /* _CPL_NASREADERP_H_INCLUDED */
|