 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
63 : myAddresses(), myValues(), myDeprecatedSynonymes() {
64 myCopyrightNotices.push_back(
"Copyright (C) 2001-2019 German Aerospace Center (DLR) and others; https://sumo.dlr.de");
81 throw ProcessError(name +
" is an already used option name.");
96 KnownContType::iterator i1 =
myValues.find(name1);
97 KnownContType::iterator i2 =
myValues.find(name2);
99 throw ProcessError(
"Neither the option '" + name1 +
"' nor the option '" + name2 +
"' is known yet");
102 if ((*i1).second == (*i2).second) {
105 throw ProcessError(
"Both options '" + name1 +
"' and '" + name2 +
"' do exist and differ.");
136 KnownContType::const_iterator i =
myValues.find(name);
138 if (failOnNonExistant) {
139 throw ProcessError(
"Internal request for unknown option '" + name +
"'!");
144 return (*i).second->isSet();
150 KnownContType::const_iterator i =
myValues.find(name);
152 if (failOnNonExistant) {
153 throw ProcessError(
"Internal request for unknown option '" + name +
"'!");
158 (*i).second->unSet();
164 KnownContType::const_iterator i =
myValues.find(name);
168 return (*i).second->isDefault();
174 KnownContType::const_iterator k =
myValues.find(name);
176 throw ProcessError(
"No option with the name '" + name +
"' exists.");
180 std::string defaultName;
182 for (std::vector<std::string>::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
183 KnownContType::const_iterator l =
myValues.find(*j);
184 if (l !=
myValues.end() && l->second == k->second) {
189 if (defaultName !=
"") {
193 WRITE_WARNING(
"Please note that '" + name +
"' is deprecated.\n Use '" + defaultName +
"' instead.");
248 if (!o->
set(value)) {
252 WRITE_ERROR(
"While processing option '" + name +
"':\n " + e.what());
261 if (
set(name, value)) {
281 std::vector<std::string>
284 std::vector<std::string> v(0);
285 for (KnownContType::const_iterator i =
myValues.begin(); i !=
myValues.end(); i++) {
286 if ((*i).second == o && name != (*i).first) {
287 v.push_back((*i).first);
302 std::vector<std::string> done;
303 os <<
"Options set:" << std::endl;
304 for (OptionsCont::KnownContType::const_iterator i = oc.
myValues.begin();
306 std::vector<std::string>::iterator j = std::find(done.begin(), done.end(), (*i).first);
307 if (j == done.end()) {
308 std::vector<std::string> synonymes = oc.
getSynonymes((*i).first);
309 if (synonymes.size() != 0) {
310 os << (*i).first <<
" (";
311 for (j = synonymes.begin(); j != synonymes.end(); j++) {
312 if (j != synonymes.begin()) {
321 if ((*i).second->isSet()) {
322 os <<
": " << (*i).second->getValueString() << std::endl;
324 os <<
": <INVALID>" << std::endl;
326 done.push_back((*i).first);
327 copy(synonymes.begin(), synonymes.end(), back_inserter(done));
337 if (option->isFileName() && option->isSet()) {
339 for (std::string& f : fileList) {
343 if (conv !=
joinToString(option->getStringVector(),
',')) {
344 const bool hadDefault = option->isDefault();
347 option->resetDefault();
366 if (files.size() == 0) {
367 WRITE_ERROR(
"The file list for '" + name +
"' is empty.");
370 for (std::vector<std::string>::const_iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt) {
391 std::vector<std::string> seenSynonymes;
392 for (KnownContType::const_iterator i =
myValues.begin(); i !=
myValues.end(); i++) {
393 if (std::find(seenSynonymes.begin(), seenSynonymes.end(), (*i).first) != seenSynonymes.end()) {
396 if ((*i).second->isSet() && !(*i).second->isDefault() && (*i).first.find(prefix) == 0) {
397 WRITE_ERROR(
"Option '" + (*i).first +
"' needs option '" + name +
"'.");
398 std::vector<std::string> synonymes =
getSynonymes((*i).first);
399 std::copy(synonymes.begin(), synonymes.end(), std::back_inserter(seenSynonymes));
410 std::ostringstream s;
411 s <<
"A value for the option '" + arg +
"' was already set.\n Possible synonymes: ";
412 for (std::vector<std::string>::iterator i = synonymes.begin(); i != synonymes.end();) {
415 if (i != synonymes.end()) {
443 (*i)->resetWritable();
457 ItemAddressContType::iterator i;
470 const std::string& subtopic,
471 const std::string& description) {
482 const std::string& fullName) {
527 int offset,
int nextOffset) {
528 while (what.length() > 0) {
529 if ((
int)what.length() > 79 - offset) {
530 std::string::size_type splitPos = what.rfind(
';', 79 - offset);
531 if (splitPos == std::string::npos) {
532 splitPos = what.rfind(
' ', 79 - offset);
536 if (splitPos != std::string::npos) {
537 os << what.substr(0, splitPos) << std::endl;
538 what = what.substr(splitPos);
539 for (
int r = 0; r < nextOffset + 1; ++r) {
558 if (missingOptions) {
561 std::cout <<
" Build features: " <<
HAVE_ENABLED << std::endl;
562 for (std::vector<std::string>::const_iterator it =
564 std::cout <<
" " << *it << std::endl;
566 std::cout <<
" License EPL-2.0: Eclipse Public License Version 2 <https://eclipse.org/legal/epl-v20.html>\n";
567 std::cout <<
" Use --help to get the list of options." << std::endl;
575 for (std::vector<std::string>::const_iterator it =
577 std::cout <<
" " << *it << std::endl;
585 std::cout <<
" Build features: " <<
HAVE_ENABLED << std::endl;
586 for (std::vector<std::string>::const_iterator it =
588 std::cout <<
" " << *it << std::endl;
590 std::cout <<
"\n" <<
myFullName <<
" is part of SUMO.\n";
591 std::cout <<
"This program and the accompanying materials\n";
592 std::cout <<
"are made available under the terms of the Eclipse Public License v2.0\n";
593 std::cout <<
"which accompanies this distribution, and is available at\n";
594 std::cout <<
"http://www.eclipse.org/legal/epl-v20.html\n";
595 std::cout <<
"SPDX-License-Identifier: EPL-2.0" << std::endl;
600 std::cout << (*this);
604 if (
isSet(
"save-configuration",
false)) {
605 if (
getString(
"save-configuration") ==
"-" ||
getString(
"save-configuration") ==
"stdout") {
609 std::ofstream out(
getString(
"save-configuration").c_str());
621 if (
isSet(
"save-template",
false)) {
626 std::ofstream out(
getString(
"save-template").c_str());
637 if (
isSet(
"save-schema",
false)) {
642 std::ofstream out(
getString(
"save-schema").c_str());
658 std::vector<std::string>::const_iterator i, j;
669 for (j = entries.begin(); j != entries.end(); ++j) {
672 int csize = (int)j->length() + 2 + 4;
674 const std::vector<std::string> synonymes =
getSynonymes(*j);
675 for (std::vector<std::string>::const_iterator s = synonymes.begin(); s != synonymes.end(); ++s) {
687 if (csize < tooLarge && maxSize < csize) {
694 if (helpTopic !=
"") {
695 bool foundTopic =
false;
704 os <<
"Help Topics:" << std::endl;
706 os <<
" " << t << std::endl;
712 os <<
"Usage: " <<
myAppName <<
" [OPTION]*" << std::endl;
724 os <<
"Examples:" << std::endl;
726 os <<
" " <<
myAppName <<
' ' << e->first << std::endl;
727 os <<
" " << e->second << std::endl;
731 os <<
"Report bugs at <https://github.com/eclipse/sumo/issues>." << std::endl;
732 os <<
"Get in contact via <sumo@dlr.de>." << std::endl;
737 os << topic <<
" Options:" << std::endl;
740 int csize = (int)entry.length() + 2;
744 std::vector<std::string> synonymes =
getSynonymes(entry);
745 for (std::vector<std::string>::const_iterator s = synonymes.begin(); s != synonymes.end(); ++s) {
747 os <<
'-' << *s <<
", ";
765 for (
int r = maxSize; r > csize; --r) {
768 int offset = csize > tooLarge ? csize : maxSize;
776 const bool complete,
const bool addComments,
777 const bool inComment)
const {
781 os <<
"<configuration xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/";
789 os <<
"Configuration.xsd\">" << std::endl << std::endl;
791 std::string subtopic = *i;
792 if (subtopic ==
"Configuration" && !complete) {
795 std::replace(subtopic.begin(), subtopic.end(),
' ',
'_');
796 std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
799 for (std::vector<std::string>::const_iterator j = entries.begin(); j != entries.end(); ++j) {
801 bool write = complete || (filled && !o->
isDefault());
806 os <<
" <" << subtopic <<
">" << std::endl;
813 os <<
" <" << *j <<
" value=\"";
819 if (!synonymes.empty()) {
820 os <<
"\" synonymes=\"";
821 for (std::vector<std::string>::const_iterator s = synonymes.begin(); s != synonymes.end(); ++s) {
822 if (s != synonymes.begin()) {
833 os <<
"\"/>" << std::endl;
841 os <<
" </" << subtopic <<
">" << std::endl << std::endl;
844 os <<
"</configuration>" << std::endl;
851 os <<
"<xsd:schema elementFormDefault=\"qualified\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n\n";
852 os <<
" <xsd:include schemaLocation=\"baseTypes.xsd\"/>\n";
853 os <<
" <xsd:element name=\"configuration\" type=\"configurationType\"/>\n\n";
854 os <<
" <xsd:complexType name=\"configurationType\">\n";
855 os <<
" <xsd:all>\n";
857 std::string subtopic = *i;
858 if (subtopic ==
"Configuration") {
861 std::replace(subtopic.begin(), subtopic.end(),
' ',
'_');
862 std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
863 os <<
" <xsd:element name=\"" << subtopic <<
"\" type=\"" << subtopic <<
"TopicType\" minOccurs=\"0\"/>\n";
865 os <<
" </xsd:all>\n";
866 os <<
" </xsd:complexType>\n\n";
868 std::string subtopic = *i;
869 if (subtopic ==
"Configuration") {
872 std::replace(subtopic.begin(), subtopic.end(),
' ',
'_');
873 std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
874 os <<
" <xsd:complexType name=\"" << subtopic <<
"TopicType\">\n";
875 os <<
" <xsd:all>\n";
877 for (std::vector<std::string>::const_iterator j = entries.begin(); j != entries.end(); ++j) {
880 std::transform(type.begin(), type.end(), type.begin(), tolower);
881 if (type ==
"int[]") {
884 if (type ==
"str[]") {
887 os <<
" <xsd:element name=\"" << *j <<
"\" type=\"" << type <<
"OptionType\" minOccurs=\"0\"/>\n";
889 os <<
" </xsd:all>\n";
890 os <<
" </xsd:complexType>\n\n";
892 os <<
"</xsd:schema>\n";
903 strftime(buffer, 80,
"<!-- generated on %c by ", localtime(&rawtime));
906 os <<
"This data file and the accompanying materials\n";
907 os <<
"are made available under the terms of the Eclipse Public License v2.0\n";
908 os <<
"which accompanies this distribution, and is available at\n";
909 os <<
"http://www.eclipse.org/legal/epl-v20.html\n";
910 os <<
"SPDX-License-Identifier: EPL-2.0\n";
921 const std::string& itemName)
const {
922 if (
isSet(optionName)) {
924 return std::find(values.begin(), values.end(), itemName) != values.end();
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
std::vector< std::string > myCopyrightNotices
std::map< std::string, bool > myDeprecatedSynonymes
A map from deprecated options to a bool indicating whether we warned about deprecation.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
static std::string urlDecode(const std::string &encoded)
const IntVector & getIntVector(const std::string &name) const
Returns the list of integer-value of the named option (only for Option_IntVector)
bool checkDependingSuboptions(const std::string &name, const std::string &prefix) const
Checks whether an option is set, which has options with a prefix depending on it.
#define WRITE_WARNING(msg)
bool setByRootElement(const std::string &name, const std::string &value)
Sets the given value for the option which can handle the given XML root.
void writeXMLHeader(std::ostream &os, const bool includeConfig=true) const
Writes a standard XML header, including the configuration.
A class representing a single program option.
std::vector< std::string > getSynonymes(const std::string &name) const
Returns the synonymes of an option name.
void reportDoubleSetting(const std::string &arg) const
Reports an error that the option has already been set.
bool isWriteable() const
Returns the information whether the option may be set a further time.
void relocateFiles(const std::string &configuration) const
Modifies file name options according to the configuration path.
void resetDefault()
Resets the option to be on its default value.
void resetWritable()
Resets all options to be writeable.
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
std::vector< std::string > mySubTopics
lists of option subtopics and copyright notices
static std::string strerror()
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static std::string to_lower_case(std::string str)
Transfers the content to lower case.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
std::string myAdditionalMessage
static std::string checkForRelativity(const std::string &filename, const std::string &basePath)
Returns the path from a configuration so that it is accessable from the current working directory.
void unSet(const std::string &name, bool failOnNonExistant=true) const
Marks the option as unset.
virtual bool isBool() const
Returns the information whether the option is a bool option.
const std::string & getDescription(const std::string &name) const
Returns the option description.
void setDescription(const std::string &desc)
Sets the description of what this option does.
virtual bool isDefault() const
Returns the information whether the option holds the default value.
void printHelp(std::ostream &os)
Prints the help.
void addCopyrightNotice(const std::string ©rightLine)
Adds a copyright notice to the help output.
std::map< std::string, std::vector< std::string > > mySubTopicEntries
A map from subtopic to option.
ItemAddressContType myAddresses
std::vector< int > IntVector
Definition of a vector of ints.
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
std::string convertChar(char abbr) const
Converts an abbreviation into a name.
std::vector< std::pair< std::string, std::string > > myCallExamples
list of call examples
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
bool isUsableFileList(const std::string &name) const
Checks whether the named option is usable as a file list (with at least a single file)
std::vector< std::string > StringVector
Definition of a vector of strings.
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
std::ostream & operator<<(std::ostream &os, const OptionsCont &oc)
bool myWriteLicense
Information whether we should always include license information in file headers.
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
const std::string & getDescription() const
Returns the description of what this option does.
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
bool isInStringVector(const std::string &optionName, const std::string &itemName) const
Returns the named option is a list of string values containing the specified item.
bool isSet() const
returns the information whether this options holds a valid value
void setAdditionalHelpMessage(const std::string &add)
Sets an additional message to be printed at the begin of the help screen.
A storage for options typed value containers)
virtual bool set(const std::string &v)=0
Stores the given value.
virtual double getFloat() const
Returns the stored double value.
void addXMLDefault(const std::string &name, const std::string &xmlRoot="")
Adds an XML root element to handle by default. The special root "" denotes the default handler.
bool isBool(const std::string &name) const
Returns the information whether the option is a boolean option.
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
void splitLines(std::ostream &os, std::string what, int offset, int nextOffset)
Writes the given string 'formatted'.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
std::string myAppName
some information on the application
static OptionsCont myOptions
The static options container used.
void writeSchema(std::ostream &os)
Writes the xml schema for the configuration.
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
Option * getSecure(const std::string &name) const
Returns the named option.
void printHelpOnTopic(const std::string &topic, int tooLarge, int maxSize, std::ostream &os)
Prints help on the given topic.
static const std::string ENCODING
The encoding of parsed strings.
virtual std::string getString() const
Returns the stored string value.
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
~OptionsCont()
Destructor.
void clearCopyrightNotices()
Removes all copyright information.
static bool isReadable(std::string path)
Checks whether the given file is readable.
virtual const IntVector & getIntVector() const
Returns the stored integer vector.
OptionsCont()
Constructor.
virtual bool getBool() const
Returns the stored boolean value.
void writeConfiguration(std::ostream &os, const bool filled, const bool complete, const bool addComments, const bool inComment=false) const
Writes the configuration.
virtual const StringVector & getStringVector() const
Returns the stored string vector.
bool isWriteable(const std::string &name)
Returns the information whether the named option may be set.
std::map< std::string, std::string > myXMLDefaults
A map from XML root element to option.
virtual int getInt() const
Returns the stored integer value.
void clear()
Removes all information from the container.
#define WRITE_MESSAGE(msg)
virtual std::string getValueString() const =0
Returns the string-representation of the value.
bool setDefault(const std::string &name, const std::string &value)
Sets the given value for the named option as new default value.
std::string myAppDescription