1 : /******************************************************************************
2 : * $Id: nasreaderp.h 24105 2012-03-10 12:08:04Z 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 :
67 : CPLString m_osLastTypeName;
68 : CPLString m_osLastReplacingFID;
69 : CPLString m_osLastSafeToIgnore;
70 :
71 : public:
72 : NASHandler( NASReader *poReader );
73 : virtual ~NASHandler();
74 :
75 : void startElement(
76 : const XMLCh* const uri,
77 : const XMLCh* const localname,
78 : const XMLCh* const qname,
79 : const Attributes& attrs
80 : );
81 : void endElement(
82 : const XMLCh* const uri,
83 : const XMLCh* const localname,
84 : const XMLCh* const qname
85 : );
86 : #if XERCES_VERSION_MAJOR >= 3
87 : void characters( const XMLCh *const chars,
88 : const XMLSize_t length );
89 : #else
90 : void characters( const XMLCh *const chars,
91 : const unsigned int length );
92 : #endif
93 :
94 : void fatalError(const SAXParseException&);
95 :
96 : CPLString GetAttributes( const Attributes* attr );
97 : };
98 :
99 : /************************************************************************/
100 : /* GMLReadState */
101 : /************************************************************************/
102 :
103 : // for now, use existing gmlreadstate.
104 : #ifdef notdef
105 : class GMLReadState
106 : {
107 : void RebuildPath();
108 :
109 : public:
110 : GMLReadState();
111 : ~GMLReadState();
112 :
113 : void PushPath( const char *pszElement );
114 : void PopPath();
115 :
116 : int MatchPath( const char *pszPathInput );
117 : const char *GetPath() const { return m_pszPath; }
118 : const char *GetLastComponent() const;
119 :
120 : GMLFeature *m_poFeature;
121 : GMLReadState *m_poParentState;
122 :
123 : char *m_pszPath; // element path ... | as separator.
124 :
125 : int m_nPathLength;
126 : char **m_papszPathComponents;
127 : };
128 : #endif
129 :
130 : /************************************************************************/
131 : /* NASReader */
132 : /************************************************************************/
133 :
134 : class NASReader : public IGMLReader
135 : {
136 : private:
137 : int m_bClassListLocked;
138 :
139 : int m_nClassCount;
140 : GMLFeatureClass **m_papoClass;
141 :
142 : char *m_pszFilename;
143 :
144 : NASHandler *m_poNASHandler;
145 : SAX2XMLReader *m_poSAXReader;
146 : int m_bReadStarted;
147 : XMLPScanToken m_oToFill;
148 :
149 : GMLReadState *m_poState;
150 :
151 : GMLFeature *m_poCompleteFeature;
152 :
153 : int SetupParser();
154 : void CleanupParser();
155 :
156 : char *m_pszFilteredClassName;
157 :
158 : public:
159 : NASReader();
160 : virtual ~NASReader();
161 :
162 139298 : int IsClassListLocked() const { return m_bClassListLocked; }
163 10 : void SetClassListLocked( int bFlag )
164 10 : { m_bClassListLocked = bFlag; }
165 :
166 : void SetSourceFile( const char *pszFilename );
167 : const char *GetSourceFileName();
168 :
169 2499440 : int GetClassCount() const { return m_nClassCount; }
170 : GMLFeatureClass *GetClass( int i ) const;
171 : GMLFeatureClass *GetClass( const char *pszName ) const;
172 :
173 : int AddClass( GMLFeatureClass *poClass );
174 : void ClearClasses();
175 :
176 : GMLFeature *NextFeature();
177 :
178 : int LoadClasses( const char *pszFile = NULL );
179 : int SaveClasses( const char *pszFile = NULL );
180 :
181 : int PrescanForSchema(int bGetExtents = TRUE );
182 : int PrescanForTemplate( void );
183 : void ResetReading();
184 :
185 : int ParseXSD( const char *pszFile ) { return FALSE; }
186 :
187 : int ResolveXlinks( const char *pszFile,
188 : int* pbOutIsTempFile,
189 : char **papszSkip = NULL,
190 : const int bStrict = FALSE );
191 :
192 : int HugeFileResolver( const char *pszFile,
193 : int bSqliteIsTempFile,
194 : int iSqliteCacheMB );
195 :
196 : // ---
197 :
198 9252222 : GMLReadState *GetState() const { return m_poState; }
199 : void PopState();
200 : void PushState( GMLReadState * );
201 :
202 : int IsFeatureElement( const char *pszElement );
203 : int IsAttributeElement( const char *pszElement );
204 :
205 : void PushFeature( const char *pszElement,
206 : const Attributes &attrs );
207 :
208 : void SetFeaturePropertyDirectly( const char *pszElement,
209 : char *pszValue );
210 :
211 0 : int HasStoppedParsing() { return FALSE; }
212 :
213 : void CheckForFID( const Attributes &attrs, char **ppszCurField );
214 : void CheckForRelations( const char *pszElement,
215 : const Attributes &attrs );
216 :
217 0 : virtual const char* GetGlobalSRSName() { return NULL; }
218 :
219 0 : virtual int CanUseGlobalSRSName() { return FALSE; }
220 :
221 : int SetFilteredClassName(const char* pszClassName);
222 139304 : const char* GetFilteredClassName() { return m_pszFilteredClassName; }
223 : };
224 :
225 : #endif /* _CPL_NASREADERP_H_INCLUDED */
|