 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
29 #include <xercesc/framework/XMLPScanToken.hpp>
30 #include <xercesc/parsers/SAXParser.hpp>
31 #include <xercesc/sax/HandlerBase.hpp>
32 #include <xercesc/sax/AttributeList.hpp>
33 #include <xercesc/util/PlatformUtils.hpp>
34 #include <xercesc/sax/SAXParseException.hpp>
35 #include <xercesc/sax/SAXException.hpp>
64 myArgC = (int)args.size() + 1;
65 char** argv =
new char* [
myArgC];
67 for (
int i = 1; i <
myArgC; i++) {
68 argv[i] =
new char[args[i - 1].size() + 1];
69 std::strcpy(argv[i], args[i - 1].c_str());
87 throw ProcessError(
"Could not parse commandline options.");
89 if (!commandLineOnly) {
104 if (!oc.
exists(
"configuration-file") || !oc.
isSet(
"configuration-file")) {
107 std::string path = oc.
getString(
"configuration-file");
113 XERCES_CPP_NAMESPACE::SAXParser parser;
114 parser.setValidationScheme(XERCES_CPP_NAMESPACE::SAXParser::Val_Auto);
115 parser.setDoNamespaces(
false);
116 parser.setDoSchema(
false);
120 parser.setDocumentHandler(&handler);
121 parser.setErrorHandler(&handler);
122 parser.parse(path.c_str());
124 throw ProcessError(
"Could not load configuration '" + path +
"'.");
126 }
catch (
const XERCES_CPP_NAMESPACE::XMLException& e) {
137 XERCES_CPP_NAMESPACE::SAXParser parser;
141 parser.setDocumentHandler(&handler);
142 parser.setErrorHandler(&handler);
143 XERCES_CPP_NAMESPACE::XMLPScanToken token;
144 if (!parser.parseFirst(filename.c_str(), token)) {
145 throw ProcessError(
"Can not read XML-file '" + filename +
"'.");
147 while (parser.parseNext(token) && handler.
getItem() ==
"");
149 throw ProcessError(
"Could not load '" + filename +
"'.");
151 }
catch (
const XERCES_CPP_NAMESPACE::XMLException& e) {
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
void relocateFiles(const std::string &configuration) const
Modifies file name options according to the configuration path.
void resetWritable()
Resets all options to be writeable.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool exists(const std::string &name) const
Returns the information whether the named option is known.
static OptionsCont & getOptions()
Retrieves the options.
static bool parse(int argc, char **argv)
Parses the given command line arguments.
bool errorOccurred() const
Returns the information whether an error occurred.
const std::string & getItem() const
Returns the last item read.
A storage for options typed value containers)
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
static std::string transcode(const XMLCh *const data)
converts a 0-terminated XMLCh* array (usually UTF-16, stemming from Xerces) into std::string in UTF-8
static void loadConfiguration()
Loads and parses the configuration.
#define PROGRESS_BEGIN_MESSAGE(msg)
A SAX-Handler for loading options.
#define PROGRESS_DONE_MESSAGE()
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
static std::string getRoot(const std::string &filename)
Retrieves the XML root element of a supposed configuration or net.
static bool isReadable(std::string path)
Checks whether the given file is readable.