 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
64 : myAddresses(), myValues(), myDeprecatedSynonymes(), myHaveInformedAboutDeprecatedDivider(false) {
65 myCopyrightNotices.push_back(
"Copyright (C) 2001-2019 German Aerospace Center (DLR) and others; https://sumo.dlr.de");
82 throw ProcessError(name +
" is an already used option name.");
97 KnownContType::iterator i1 =
myValues.find(name1);
98 KnownContType::iterator i2 =
myValues.find(name2);
100 throw ProcessError(
"Neither the option '" + name1 +
"' nor the option '" + name2 +
"' is known yet");
103 if ((*i1).second == (*i2).second) {
106 throw ProcessError(
"Both options '" + name1 +
"' and '" + name2 +
"' do exist and differ.");
137 KnownContType::const_iterator i =
myValues.find(name);
139 if (failOnNonExistant) {
140 throw ProcessError(
"Internal request for unknown option '" + name +
"'!");
145 return (*i).second->isSet();
151 KnownContType::const_iterator i =
myValues.find(name);
153 if (failOnNonExistant) {
154 throw ProcessError(
"Internal request for unknown option '" + name +
"'!");
159 (*i).second->unSet();
165 KnownContType::const_iterator i =
myValues.find(name);
169 return (*i).second->isDefault();
175 KnownContType::const_iterator k =
myValues.find(name);
177 throw ProcessError(
"No option with the name '" + name +
"' exists.");
181 std::string defaultName;
183 for (std::vector<std::string>::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
184 KnownContType::const_iterator l =
myValues.find(*j);
185 if (l !=
myValues.end() && l->second == k->second) {
190 if (defaultName !=
"") {
194 WRITE_WARNING(
"Please note that '" + name +
"' is deprecated.\n Use '" + defaultName +
"' instead.");
251 if (!o->
set(value)) {
255 WRITE_ERROR(
"While processing option '" + name +
"':\n " + e.what());
264 if (
set(name, value)) {
284 std::vector<std::string>
287 std::vector<std::string> v(0);
288 for (KnownContType::const_iterator i =
myValues.begin(); i !=
myValues.end(); i++) {
289 if ((*i).second == o && name != (*i).first) {
290 v.push_back((*i).first);
305 std::vector<std::string> done;
306 os <<
"Options set:" << std::endl;
307 for (OptionsCont::KnownContType::const_iterator i = oc.
myValues.begin();
309 std::vector<std::string>::iterator j = std::find(done.begin(), done.end(), (*i).first);
310 if (j == done.end()) {
311 std::vector<std::string> synonymes = oc.
getSynonymes((*i).first);
312 if (synonymes.size() != 0) {
313 os << (*i).first <<
" (";
314 for (j = synonymes.begin(); j != synonymes.end(); j++) {
315 if (j != synonymes.begin()) {
324 if ((*i).second->isSet()) {
325 os <<
": " << (*i).second->getValueString() << std::endl;
327 os <<
": <INVALID>" << std::endl;
329 done.push_back((*i).first);
330 copy(synonymes.begin(), synonymes.end(), back_inserter(done));
340 if (option->isFileName() && option->isSet()) {
341 std::vector<std::string> fileList =
StringTokenizer(option->getString(),
",").getVector();
342 for (std::string& f : fileList) {
347 if (conv != option->getString()) {
348 const bool hadDefault = option->isDefault();
351 option->resetDefault();
370 if (files.size() == 0) {
371 WRITE_ERROR(
"The file list for '" + name +
"' is empty.");
374 for (std::vector<std::string>::const_iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt) {
395 std::vector<std::string> seenSynonymes;
396 for (KnownContType::const_iterator i =
myValues.begin(); i !=
myValues.end(); i++) {
397 if (std::find(seenSynonymes.begin(), seenSynonymes.end(), (*i).first) != seenSynonymes.end()) {
400 if ((*i).second->isSet() && !(*i).second->isDefault() && (*i).first.find(prefix) == 0) {
401 WRITE_ERROR(
"Option '" + (*i).first +
"' needs option '" + name +
"'.");
402 std::vector<std::string> synonymes =
getSynonymes((*i).first);
403 std::copy(synonymes.begin(), synonymes.end(), std::back_inserter(seenSynonymes));
414 std::ostringstream s;
415 s <<
"A value for the option '" + arg +
"' was already set.\n Possible synonymes: ";
416 for (std::vector<std::string>::iterator i = synonymes.begin(); i != synonymes.end();) {
419 if (i != synonymes.end()) {
447 (*i)->resetWritable();
461 ItemAddressContType::iterator i;
474 const std::string& subtopic,
475 const std::string& description) {
486 const std::string& fullName) {
531 int offset,
int nextOffset) {
532 while (what.length() > 0) {
533 if ((
int)what.length() > 79 - offset) {
534 std::string::size_type splitPos = what.rfind(
';', 79 - offset);
535 if (splitPos == std::string::npos) {
536 splitPos = what.rfind(
' ', 79 - offset);
540 if (splitPos != std::string::npos) {
541 os << what.substr(0, splitPos) << std::endl;
542 what = what.substr(splitPos);
543 for (
int r = 0; r < nextOffset + 1; ++r) {
562 if (missingOptions) {
565 std::cout <<
" Build features: " <<
HAVE_ENABLED << std::endl;
566 for (std::vector<std::string>::const_iterator it =
568 std::cout <<
" " << *it << std::endl;
570 std::cout <<
" License EPL-2.0: Eclipse Public License Version 2 <https://eclipse.org/legal/epl-v20.html>\n";
571 std::cout <<
" Use --help to get the list of options." << std::endl;
579 for (std::vector<std::string>::const_iterator it =
581 std::cout <<
" " << *it << std::endl;
589 std::cout <<
" Build features: " <<
HAVE_ENABLED << std::endl;
590 for (std::vector<std::string>::const_iterator it =
592 std::cout <<
" " << *it << std::endl;
594 std::cout <<
"\n" <<
myFullName <<
" is part of SUMO.\n";
595 std::cout <<
"This program and the accompanying materials\n";
596 std::cout <<
"are made available under the terms of the Eclipse Public License v2.0\n";
597 std::cout <<
"which accompanies this distribution, and is available at\n";
598 std::cout <<
"http://www.eclipse.org/legal/epl-v20.html\n";
599 std::cout <<
"SPDX-License-Identifier: EPL-2.0" << std::endl;
604 std::cout << (*this);
608 if (
isSet(
"save-configuration",
false)) {
609 if (
getString(
"save-configuration") ==
"-" ||
getString(
"save-configuration") ==
"stdout") {
613 std::ofstream out(
getString(
"save-configuration").c_str());
625 if (
isSet(
"save-template",
false)) {
630 std::ofstream out(
getString(
"save-template").c_str());
641 if (
isSet(
"save-schema",
false)) {
646 std::ofstream out(
getString(
"save-schema").c_str());
662 std::vector<std::string>::const_iterator i, j;
673 for (j = entries.begin(); j != entries.end(); ++j) {
676 int csize = (int)j->length() + 2 + 4;
678 const std::vector<std::string> synonymes =
getSynonymes(*j);
679 for (std::vector<std::string>::const_iterator s = synonymes.begin(); s != synonymes.end(); ++s) {
691 if (csize < tooLarge && maxSize < csize) {
698 if (helpTopic !=
"") {
699 bool foundTopic =
false;
708 os <<
"Help Topics:" << std::endl;
710 os <<
" " << t << std::endl;
716 os <<
"Usage: " <<
myAppName <<
" [OPTION]*" << std::endl;
728 os <<
"Examples:" << std::endl;
730 os <<
" " <<
myAppName <<
' ' << e->first << std::endl;
731 os <<
" " << e->second << std::endl;
735 os <<
"Report bugs at <https://github.com/eclipse/sumo/issues>." << std::endl;
736 os <<
"Get in contact via <sumo@dlr.de>." << std::endl;
741 os << topic <<
" Options:" << std::endl;
744 int csize = (int)entry.length() + 2;
748 std::vector<std::string> synonymes =
getSynonymes(entry);
749 for (std::vector<std::string>::const_iterator s = synonymes.begin(); s != synonymes.end(); ++s) {
751 os <<
'-' << *s <<
", ";
769 for (
int r = maxSize; r > csize; --r) {
772 int offset = csize > tooLarge ? csize : maxSize;
780 const bool complete,
const bool addComments,
781 const bool inComment)
const {
785 os <<
"<configuration xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/";
793 os <<
"Configuration.xsd\">" << std::endl << std::endl;
795 std::string subtopic = *i;
796 if (subtopic ==
"Configuration" && !complete) {
799 std::replace(subtopic.begin(), subtopic.end(),
' ',
'_');
800 std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
803 for (std::vector<std::string>::const_iterator j = entries.begin(); j != entries.end(); ++j) {
805 bool write = complete || (filled && !o->
isDefault());
810 os <<
" <" << subtopic <<
">" << std::endl;
817 os <<
" <" << *j <<
" value=\"";
823 if (!synonymes.empty()) {
824 os <<
"\" synonymes=\"";
825 for (std::vector<std::string>::const_iterator s = synonymes.begin(); s != synonymes.end(); ++s) {
826 if (s != synonymes.begin()) {
837 os <<
"\"/>" << std::endl;
845 os <<
" </" << subtopic <<
">" << std::endl << std::endl;
848 os <<
"</configuration>" << std::endl;
855 os <<
"<xsd:schema elementFormDefault=\"qualified\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n\n";
856 os <<
" <xsd:include schemaLocation=\"baseTypes.xsd\"/>\n";
857 os <<
" <xsd:element name=\"configuration\" type=\"configurationType\"/>\n\n";
858 os <<
" <xsd:complexType name=\"configurationType\">\n";
859 os <<
" <xsd:all>\n";
861 std::string subtopic = *i;
862 if (subtopic ==
"Configuration") {
865 std::replace(subtopic.begin(), subtopic.end(),
' ',
'_');
866 std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
867 os <<
" <xsd:element name=\"" << subtopic <<
"\" type=\"" << subtopic <<
"TopicType\" minOccurs=\"0\"/>\n";
869 os <<
" </xsd:all>\n";
870 os <<
" </xsd:complexType>\n\n";
872 std::string subtopic = *i;
873 if (subtopic ==
"Configuration") {
876 std::replace(subtopic.begin(), subtopic.end(),
' ',
'_');
877 std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
878 os <<
" <xsd:complexType name=\"" << subtopic <<
"TopicType\">\n";
879 os <<
" <xsd:all>\n";
881 for (std::vector<std::string>::const_iterator j = entries.begin(); j != entries.end(); ++j) {
884 std::transform(type.begin(), type.end(), type.begin(), tolower);
885 if (type ==
"int[]") {
888 os <<
" <xsd:element name=\"" << *j <<
"\" type=\"" << type <<
"OptionType\" minOccurs=\"0\"/>\n";
890 os <<
" </xsd:all>\n";
891 os <<
" </xsd:complexType>\n\n";
893 os <<
"</xsd:schema>\n";
904 strftime(buffer, 80,
"<!-- generated on %c by ", localtime(&rawtime));
907 os <<
"This data file and the accompanying materials\n";
908 os <<
"are made available under the terms of the Eclipse Public License v2.0\n";
909 os <<
"which accompanies this distribution, and is available at\n";
910 os <<
"http://www.eclipse.org/legal/epl-v20.html\n";
911 os <<
"SPDX-License-Identifier: EPL-2.0\n";
920 std::vector<std::string>
925 WRITE_WARNING(
"Please note that using ';' as list separator is deprecated.\n From 1.0 onwards, only ',' will be accepted.");
929 std::vector<std::string> ret = st.
getVector();
930 for (std::vector<std::string>::iterator i = ret.begin(); i != ret.end(); ++i) {
939 const std::string& itemName) {
940 if (
isSet(optionName)) {
942 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.
bool myHaveInformedAboutDeprecatedDivider
Information whether a warning a deprecated divider.
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)
const FloatVector & getFloatVector(const std::string &name) const
Returns the list of double-value of the named option (only for Option_FloatVector)
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.
virtual const FloatVector & getFloatVector() const
Returns the stored float vector.
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.
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)
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
bool isInStringVector(const std::string &optionName, const std::string &itemName)
Returns the named option is a list of string values containing the specified item.
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 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.
std::vector< std::string > getVector()
return vector of strings
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.
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)
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String)
virtual std::string getValueString() const =0
Returns the string-representation of the value.
std::vector< double > FloatVector
Definition of a vector of doubles.
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