Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
SUMOSAXReader.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2012-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// SAX-reader encapsulation containing binary reader
21/****************************************************************************/
22#pragma once
23#include <config.h>
24
25#include <string>
26#include <memory>
27#include <vector>
28#include <xercesc/sax2/SAX2XMLReader.hpp>
29#include <xercesc/sax/EntityResolver.hpp>
30#include <xercesc/sax/InputSource.hpp>
31#include "SUMOXMLDefinitions.h"
32
33
34// ===========================================================================
35// class declarations
36// ===========================================================================
37
41
42// ===========================================================================
43// class definitions
44// ===========================================================================
54
55public:
61 SUMOSAXReader(GenericSAXHandler& handler, const std::string& validationScheme, XERCES_CPP_NAMESPACE::XMLGrammarPool* grammarPool);
62
65
71 void setHandler(GenericSAXHandler& handler);
72
80 void setValidation(std::string validationScheme = "");
81
89 void parse(std::string systemID);
90
96 void parseString(std::string content);
97
104 bool parseFirst(std::string systemID);
105
111 bool parseNext();
112
120 bool parseSection(SumoXMLTag element);
121
122private:
124 class LocalSchemaResolver : public XERCES_CPP_NAMESPACE::EntityResolver {
125
126 public:
128 LocalSchemaResolver(const bool haveFallback, const bool noOp);
129
131 XERCES_CPP_NAMESPACE::InputSource* resolveEntity(const XMLCh* const publicId, const XMLCh* const systemId);
132
133 private:
135 const bool myHaveFallback;
136
138 const bool myNoOp;
139 };
140
150 void ensureSAXReader();
151
154
157
159 XERCES_CPP_NAMESPACE::XMLGrammarPool* myGrammarPool;
160
162 XERCES_CPP_NAMESPACE::XMLPScanToken myToken;
163
165 XERCES_CPP_NAMESPACE::SAX2XMLReader* myXMLReader;
166
168 std::unique_ptr<std::istream> myIStream;
169
171 std::unique_ptr<IStreamInputSource> myInputStream;
172
174 std::vector<SumoXMLTag> myXMLStack;
175
178
181
184
186 std::pair<int, SUMOSAXAttributes*> myNextSection;
187
189 SUMOSAXReader(const SUMOSAXReader& s) = delete;
190
192 const SUMOSAXReader& operator=(const SUMOSAXReader& s) = delete;
193};
SumoXMLTag
Numbers representing SUMO-XML - element names.
A handler which converts occurring elements and attributes into enums.
Xerces InputSource reading from arbitrary std::istream.
Encapsulated SAX-Attributes.
const bool myHaveFallback
flag for check if we have fallback
const bool myNoOp
flag for check if there is an operation
XERCES_CPP_NAMESPACE::InputSource * resolveEntity(const XMLCh *const publicId, const XMLCh *const systemId)
resolve entity
SAX-reader encapsulation containing binary reader.
std::unique_ptr< IStreamInputSource > myInputStream
input stream
const SUMOSAXReader & operator=(const SUMOSAXReader &s)=delete
invalidated assignment operator
std::string myValidationScheme
Information whether built reader/parser shall validate XML-documents against schemata.
std::pair< int, SUMOSAXAttributes * > myNextSection
next section
void setHandler(GenericSAXHandler &handler)
Sets the given handler as content and error handler for the reader.
void parseString(std::string content)
Parse XML from the given string.
LocalSchemaResolver myLocalResolver
local resolver
bool parseFirst(std::string systemID)
Start parsing the given file using parseFirst of myXMLReader.
SUMOSAXReader(const SUMOSAXReader &s)=delete
invalidated copy constructor
std::unique_ptr< std::istream > myIStream
istream
LocalSchemaResolver mySchemaResolver
schema resolver
bool parseSection(SumoXMLTag element)
Continue a progressive parse started by parseFirst until the given element is encountered.
void setValidation(std::string validationScheme="")
Sets a new validation scheme and applies the validation settings to the XML reader.
~SUMOSAXReader()
Destructor.
std::vector< SumoXMLTag > myXMLStack
The stack of begun xml elements.
GenericSAXHandler * myHandler
generic SAX Handler
void parse(std::string systemID)
Parse the given file completely by calling parse of myXMLReader.
XERCES_CPP_NAMESPACE::SAX2XMLReader * myXMLReader
XML reader.
LocalSchemaResolver myNoOpResolver
no operation resolver
XERCES_CPP_NAMESPACE::XMLGrammarPool * myGrammarPool
Schema cache to be used for grammars which are not declared.
XERCES_CPP_NAMESPACE::XMLPScanToken myToken
token
void ensureSAXReader()
Builds a reader, if needed.
bool parseNext()
Continue a progressive parse started by parseFirst.