25#include <xercesc/sax/HandlerBase.hpp>
26#include <xercesc/sax/AttributeList.hpp>
27#include <xercesc/sax/SAXParseException.hpp>
28#include <xercesc/sax/SAXException.hpp>
36#include <xercesc/parsers/SAXParser.hpp>
37#include <xercesc/sax2/XMLReaderFactory.hpp>
38#include <xercesc/framework/LocalFileInputSource.hpp>
39#include <xercesc/framework/MemBufInputSource.hpp>
54 XERCES_CPP_NAMESPACE::SAXParser parser;
56 parser.setValidationScheme(XERCES_CPP_NAMESPACE::SAXParser::Val_Never);
57 parser.setDisableDefaultEntityResolution(
true);
62 parser.setDocumentHandler(&handler);
63 parser.setErrorHandler(&handler);
64 XERCES_CPP_NAMESPACE::MemBufInputSource memBufIS((
const XMLByte*)templateString.c_str(), templateString.size(),
"template");
65 parser.parse(memBufIS);
67 throw ProcessError(
TLF(
"Could not load template '%'.", templateString));
69 }
catch (
const XERCES_CPP_NAMESPACE::XMLException& e) {
94 if (attributes.getLength() == 0) {
100 std::string synonymes;
103 bool required =
false;
104 bool positional =
false;
105 std::string listSep =
"";
107 for (
int i = 0; i < (int)attributes.getLength(); i++) {
111 if (attributeName ==
"value") {
112 value = attributeValue;
113 }
else if (attributeName ==
"synonymes") {
114 synonymes = attributeValue;
115 }
else if (attributeName ==
"type") {
116 type = attributeValue;
117 }
else if (attributeName ==
"help") {
118 help = attributeValue;
119 }
else if (attributeName ==
"category") {
123 if (std::find(topics.begin(), topics.end(), attributeValue) == topics.end()) {
126 }
else if (attributeName ==
"required") {
128 }
else if (attributeName ==
"positional") {
130 }
else if (attributeName ==
"listSeparator") {
131 listSep = attributeValue;
135 addOption(value, synonymes, type, help, required, positional, listSep);
142 const std::string& help,
bool required,
bool positional,
const std::string& listSep)
const {
150 if (value ==
"None") {
154 if ((type ==
"STR") || (type ==
"string")) {
156 }
else if ((type ==
"TIME") || (type ==
"time")) {
158 }
else if ((type ==
"INT") || (type ==
"int")) {
163 option->
set(value, value,
true);
165 }
else if ((type ==
"FLOAT") || (type ==
"float")) {
170 option->
set(value, value,
true);
172 }
else if ((type ==
"BOOL") || (type ==
"bool")) {
175 option->
set(
"false",
"",
true);
177 option->
set(value, value,
true);
179 }
else if (type ==
"INT[]") {
181 }
else if (type ==
"STR[]") {
183 }
else if ((type ==
"FILE") || (type ==
"file")) {
185 }
else if ((type ==
"NETWORK") || (type ==
"net_file")) {
187 }
else if ((type ==
"ADDITIONAL") || (type ==
"additional_file")) {
189 }
else if ((type ==
"ROUTE") || (type ==
"route_file")) {
191 }
else if ((type ==
"DATA") || (type ==
"data_file") || (type ==
"edgedata_file")) {
193 }
else if ((type ==
"SUMOCONFIG") || (type ==
"sumoconfig_file")) {
195 }
else if ((type ==
"EDGE") || (type ==
"edge")) {
196 if (listSep.empty()) {
201 }
else if (type.size() > 0) {
207 if (!option->
isSet()) {
208 option->
set(value,
"",
false);
212 if (synonymes.size() > 0) {
216 if (help.size() > 0) {
242 +
toString(exception.getLineNumber() + 1) +
'/' \
243 +
toString(exception.getColumnNumber()) +
").");
252 +
toString(exception.getLineNumber() + 1) +
'/'
253 +
toString(exception.getColumnNumber()) +
").");
262 +
toString(exception.getLineNumber() + 1) +
'/'
263 +
toString(exception.getColumnNumber()) +
").");
#define WRITE_WARNING(msg)
const double INVALID_DOUBLE
invalid double
const int INVALID_INT
invalid int
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
A class representing a single program option.
bool isSet() const
returns the information whether this options holds a valid value
virtual bool set(const std::string &v, const std::string &orig, const bool append)=0
Stores the given value.
A storage for options typed value containers)
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
void resetDefault()
Resets all options to default.
void setFurtherAttributes(const std::string &name, const std::string &subtopic, bool required, bool positional, const std::string &listSep)
mark option as required
const std::vector< std::string > & getSubTopics() const
return the list of subtopics
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
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 bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter
A SAX-Handler for loading options.
void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Called on an XML-fatal error.
static const std::string INVALID_DOUBLE_STR
invalid double in string format
TemplateHandler(OptionsCont &options)
Constructor.
void endElement(const XMLCh *const name)
Called on the end of an element.
bool myError
The information whether an error occurred.
int myLevel
The nesting level of parsed elements.
std::string mySubTopic
current subtopic
std::string myOptionName
The name of the current option.
void startElement(const XMLCh *const name, XERCES_CPP_NAMESPACE::AttributeList &attributes)
Called on the occurrence of the beginning of a tag.
OptionsCont & myOptions
The options to fill.
~TemplateHandler()
destructor
void error(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Called on an XML-error.
static void parseTemplate(OptionsCont &options, const std::string &templateString)
run parser
static const std::string INVALID_INT_STR
invalid int in string format
bool addOption(std::string value, const std::string &synonymes, const std::string &type, const std::string &help, bool required, bool positional, const std::string &listSep) const
add option
void warning(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Called on an XML-warning.