54 #ifdef CHECK_MEMORY_LEAKS 56 #endif // CHECK_MEMORY_LEAKS 76 myCopyrightNotices.push_back(
"Copyright (C) 2001-2015 DLR and contributors; http://sumo.dlr.de");
93 throw ProcessError(name +
" is an already used option name.");
108 KnownContType::iterator i1 =
myValues.find(name1);
109 KnownContType::iterator i2 =
myValues.find(name2);
111 throw ProcessError(
"Neither the option '" + name1 +
"' nor the option '" + name2 +
"' is known yet");
114 if ((*i1).second == (*i2).second) {
117 throw ProcessError(
"Both options '" + name1 +
"' and '" + name2 +
"' do exist and differ.");
142 KnownContType::const_iterator i =
myValues.find(name);
144 if (failOnNonExistant) {
145 throw ProcessError(
"Internal request for unknown option '" + name +
"'!");
150 return (*i).second->isSet();
156 KnownContType::const_iterator i =
myValues.find(name);
158 if (failOnNonExistant) {
159 throw ProcessError(
"Internal request for unknown option '" + name +
"'!");
164 (*i).second->unSet();
170 KnownContType::const_iterator i =
myValues.find(name);
174 return (*i).second->isDefault();
180 KnownContType::const_iterator k =
myValues.find(name);
182 throw ProcessError(
"No option with the name '" + name +
"' exists.");
186 std::string defaultName;
188 for (std::vector<std::string>::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
189 KnownContType::const_iterator l =
myValues.find(*j);
190 if (l !=
myValues.end() && l->second == k->second) {
195 if (defaultName !=
"") {
199 WRITE_WARNING(
"Please note that '" + name +
"' is deprecated.\n Use '" + defaultName +
"' instead.");
249 if (!o->
set(value)) {
253 WRITE_ERROR(
"While processing option '" + name +
"':\n " + e.what());
260 std::vector<std::string>
263 std::vector<std::string> v(0);
264 for (KnownContType::const_iterator i =
myValues.begin(); i !=
myValues.end(); i++) {
265 if ((*i).second == o && name != (*i).first) {
266 v.push_back((*i).first);
275 std::vector<std::string> done;
276 os <<
"Options set:" << std::endl;
277 for (OptionsCont::KnownContType::const_iterator i = oc.
myValues.begin();
279 std::vector<std::string>::iterator j = find(done.begin(), done.end(), (*i).first);
280 if (j == done.end()) {
281 std::vector<std::string> synonymes = oc.
getSynonymes((*i).first);
282 if (synonymes.size() != 0) {
283 os << (*i).first <<
" (";
284 for (j = synonymes.begin(); j != synonymes.end(); j++) {
285 if (j != synonymes.begin()) {
294 if ((*i).second->isSet()) {
295 os <<
": " << (*i).second->getValueString() << std::endl;
297 os <<
": <INVALID>" << std::endl;
299 done.push_back((*i).first);
300 copy(synonymes.begin(), synonymes.end(), back_inserter(done));
310 if ((*i)->isFileName() && (*i)->isSet()) {
313 while (st.hasNext()) {
314 if (conv.length() != 0) {
317 std::string tmp = st.
next();
323 if (conv != (*i)->getString()) {
342 if (files.size() == 0) {
343 WRITE_ERROR(
"The file list for '" + name +
"' is empty.");
346 for (std::vector<std::string>::const_iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt) {
349 WRITE_ERROR(
"File '" + *fileIt +
"' is not accessible (" + std::strerror(errno) +
").");
367 std::vector<std::string> seenSynonymes;
368 for (KnownContType::const_iterator i =
myValues.begin(); i !=
myValues.end(); i++) {
369 if (std::find(seenSynonymes.begin(), seenSynonymes.end(), (*i).first) != seenSynonymes.end()) {
372 if ((*i).second->isSet() && !(*i).second->isDefault() && (*i).first.find(prefix) == 0) {
373 WRITE_ERROR(
"Option '" + (*i).first +
"' needs option '" + name +
"'.");
374 std::vector<std::string> synonymes =
getSynonymes((*i).first);
375 std::copy(synonymes.begin(), synonymes.end(), std::back_inserter(seenSynonymes));
386 std::ostringstream s;
387 s <<
"A value for the option '" + arg +
"' was already set.\n Possible synonymes: ";
388 for (std::vector<std::string>::iterator i = synonymes.begin(); i != synonymes.end();) {
391 if (i != synonymes.end()) {
419 (*i)->resetWritable();
433 ItemAddressContType::iterator i;
446 const std::string& subtopic,
447 const std::string& description) {
458 const std::string& fullName) {
503 size_t offset,
size_t nextOffset) {
504 while (what.length() > 0) {
505 if (what.length() > 79 - offset) {
506 size_t splitPos = what.rfind(
';', 79 - offset);
507 if (splitPos == std::string::npos) {
508 splitPos = what.rfind(
' ', 79 - offset);
512 if (splitPos != std::string::npos) {
513 os << what.substr(0, splitPos) << std::endl;
514 what = what.substr(splitPos);
515 for (
size_t r = 0; r < nextOffset + 1; ++r) {
534 if (missingOptions) {
537 for (std::vector<std::string>::const_iterator it =
539 std::cout <<
" " << *it << std::endl;
541 std::cout <<
" License GPLv3+: GNU GPL Version 3 or later <http://gnu.org/licenses/gpl.html>\n";
542 std::cout <<
" Use --help to get the list of options." << std::endl;
549 for (std::vector<std::string>::const_iterator it =
551 std::cout <<
" " << *it << std::endl;
559 for (std::vector<std::string>::const_iterator it =
561 std::cout <<
" " << *it << std::endl;
563 std::cout <<
"\n" <<
myFullName <<
" is part of SUMO.\n";
564 std::cout <<
"SUMO is free software: you can redistribute it and/or modify\n";
565 std::cout <<
"it under the terms of the GNU General Public License as published by\n";
566 std::cout <<
"the Free Software Foundation, either version 3 of the License, or\n";
567 std::cout <<
"(at your option) any later version.\n\n";
568 std::cout <<
"This program is distributed in the hope that it will be useful,\n";
569 std::cout <<
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n";
570 std::cout <<
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n";
571 std::cout <<
"GNU General Public License for more details.\n\n";
572 std::cout <<
"You should have received a copy of the GNU General Public License\n";
573 std::cout <<
"along with this program. If not, see http://www.gnu.org/licenses/gpl.html" << std::endl;
578 std::cout << (*this);
582 if (
isSet(
"save-configuration",
false)) {
583 if (
getString(
"save-configuration") ==
"-" ||
getString(
"save-configuration") ==
"stdout") {
587 std::ofstream out(
getString(
"save-configuration").c_str());
599 if (
isSet(
"save-template",
false)) {
604 std::ofstream out(
getString(
"save-template").c_str());
615 if (
isSet(
"save-schema",
false)) {
620 std::ofstream out(
getString(
"save-schema").c_str());
636 std::vector<std::string>::const_iterator i, j;
641 os <<
"Usage: " <<
myAppName <<
" [OPTION]*" << std::endl;
649 size_t tooLarge = 40;
653 for (j = entries.begin(); j != entries.end(); ++j) {
656 size_t csize = (*j).length() + 2 + 4;
659 if (find_if(synonymes.begin(), synonymes.end(),
abbreviation_finder()) != synonymes.end()) {
668 if (csize < tooLarge && maxSize < csize) {
675 os << *i <<
" Options:" << std::endl;
677 for (j = entries.begin(); j != entries.end(); ++j) {
679 size_t csize = (*j).length() + 2;
684 std::vector<std::string>::iterator a = find_if(synonymes.begin(), synonymes.end(),
abbreviation_finder());
685 if (a != synonymes.end()) {
686 os <<
'-' << (*a) <<
", ";
702 for (
size_t r = maxSize; r > csize; --r) {
705 size_t offset = csize > tooLarge ? csize : maxSize;
713 os <<
"Examples:" << std::endl;
715 os <<
" " <<
myAppName <<
' ' << e->first << std::endl;
716 os <<
" " << e->second << std::endl;
720 os <<
"Report bugs at <http://sumo.dlr.de/trac/>." << std::endl;
721 os <<
"Get in contact via <sumo@dlr.de>." << std::endl;
727 bool complete,
bool addComments)
const {
729 os <<
"<configuration xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/" <<
myAppName <<
"Configuration.xsd\">" << std::endl << std::endl;
731 std::string subtopic = *i;
732 if (subtopic ==
"Configuration" && !complete) {
735 std::replace(subtopic.begin(), subtopic.end(),
' ',
'_');
736 std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
739 for (std::vector<std::string>::const_iterator j = entries.begin(); j != entries.end(); ++j) {
741 bool write = complete || (filled && !o->
isDefault());
746 os <<
" <" << subtopic <<
">" << std::endl;
753 os <<
" <" << *j <<
" value=\"";
759 if (!synonymes.empty()) {
760 os <<
"\" synonymes=\"";
761 for (std::vector<std::string>::const_iterator s = synonymes.begin(); s != synonymes.end(); ++s) {
762 if (s != synonymes.begin()) {
773 os <<
"\"/>" << std::endl;
781 os <<
" </" << subtopic <<
">" << std::endl << std::endl;
784 os <<
"</configuration>" << std::endl;
791 os <<
"<xsd:schema elementFormDefault=\"qualified\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n\n";
792 os <<
" <xsd:include schemaLocation=\"baseTypes.xsd\"/>\n";
793 os <<
" <xsd:element name=\"configuration\" type=\"configurationType\"/>\n\n";
794 os <<
" <xsd:complexType name=\"configurationType\">\n";
795 os <<
" <xsd:all>\n";
797 std::string subtopic = *i;
798 if (subtopic ==
"Configuration") {
801 std::replace(subtopic.begin(), subtopic.end(),
' ',
'_');
802 std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
803 os <<
" <xsd:element name=\"" << subtopic <<
"\" type=\"" << subtopic <<
"Type\" minOccurs=\"0\"/>\n";
805 os <<
" </xsd:all>\n";
806 os <<
" </xsd:complexType>\n\n";
808 std::string subtopic = *i;
809 if (subtopic ==
"Configuration") {
812 std::replace(subtopic.begin(), subtopic.end(),
' ',
'_');
813 std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
814 os <<
" <xsd:complexType name=\"" << subtopic <<
"Type\">\n";
815 os <<
" <xsd:all>\n";
817 for (std::vector<std::string>::const_iterator j = entries.begin(); j != entries.end(); ++j) {
820 std::transform(type.begin(), type.end(), type.begin(), tolower);
821 if (type ==
"int[]") {
824 os <<
" <xsd:element name=\"" << *j <<
"\" type=\"" << type <<
"OptionType\" minOccurs=\"0\"/>\n";
826 os <<
" </xsd:all>\n";
827 os <<
" </xsd:complexType>\n\n";
829 os <<
"</xsd:schema>\n";
840 strftime(buffer, 80,
"<!-- generated on %c by ", localtime(&rawtime));
847 std::vector<std::string>
852 WRITE_WARNING(
"Please note that using ';' as list separator is deprecated.\n From 1.0 onwards, only ',' will be accepted.");
856 std::vector<std::string> ret = st.
getVector();
857 for (std::vector<std::string>::iterator i = ret.begin(); i != ret.end(); ++i) {
866 const std::string& itemName) {
867 if (
isSet(optionName)) {
869 return find(values.begin(), values.end(), itemName) != values.end();
std::string myAppName
some information on the application
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
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) ...
std::vector< std::string > getSynonymes(const std::string &name) const
Returns the synonymes of an option name.
std::vector< std::string > mySubTopics
lists of option subtopics and copyright notices
static std::string getConfigurationRelative(const std::string &configPath, const std::string &path)
Returns the second path as a relative path to the first file.
void resetWritable()
Resets all options to be writeable.
bool isSet() const
returns the information whether this options holds a valid value
void addCopyrightNotice(const std::string ©rightLine)
Adds a copyright notice to the help output.
bool isInStringVector(const std::string &optionName, const std::string &itemName)
Returns the named option is a list of string values containing the specified item.
static bool isReadable(std::string path)
Checks whether the given file is readable.
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. ...
virtual bool isBool() const
Returns the information whether the option is a bool option.
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
void unSet(const std::string &name, bool failOnNonExistant=true) const
Marks the option as unset.
void reportDoubleSetting(const std::string &arg) const
Reports an error that the option has already been set.
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
void clearCopyrightNotices()
Removes all copyright information.
void printHelp(std::ostream &os)
Prints the help.
const IntVector & getIntVector(const std::string &name) const
Returns the list of integer-value of the named option (only for Option_IntVector) ...
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static std::string escapeXML(const std::string &orig)
Replaces the standard escapes by their XML entities.
bool myHaveInformedAboutDeprecatedDivider
Information whether a warning a deprecated divider.
virtual bool getBool() const
Returns the stored boolean value.
std::string convertChar(char abbr) const
Converts an abbreviation into a name.
virtual const IntVector & getIntVector() const
Returns the stored integer vector.
void setDescription(const std::string &desc)
Sets the description of what this option does.
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
static OptionsCont myOptions
The static options container used.
virtual std::string getString() const
Returns the stored string value.
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
#define WRITE_WARNING(msg)
static OptionsCont & getOptions()
Retrieves the options.
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
std::string myAppDescription
ItemAddressContType myAddresses
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
std::map< std::string, bool > myDeprecatedSynonymes
A map from deprecated options to a bool indicating whether we warned about deprecation.
void clear()
Removes all information from the container.
void writeXMLHeader(std::ostream &os)
Writes a standard XML header, including the configuration.
bool isBool(const std::string &name) const
Returns the information whether the option is a boolean option.
std::string myAdditionalMessage
std::vector< int > IntVector
Definition of a vector of unsigned ints.
const std::string & getDescription() const
Returns the description of what this option does.
static bool isAbsolute(const std::string &path)
Returns the information whether the given path is absolute.
void setAdditionalHelpMessage(const std::string &add)
Sets an additional message to be printed at the begin of the help screen.
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 const std::string ENCODING
The encoding of parsed strings.
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
~OptionsCont()
Destructor.
bool isWriteable(const std::string &name)
Returns the information whether the named option may be set.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
bool isWriteable() const
Returns the information whether the option may be set a further time.
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, size_t offset, size_t nextOffset)
Writes the given string 'formatted'.
virtual bool set(const std::string &v)=0
Stores the given value (used for non-bool options)
void writeSchema(std::ostream &os, bool addComments)
Writes the xml schema for the configuration.
std::vector< std::string > getVector()
A class to find abbreviated option names (length=1)
A class representing a single program option.
void relocateFiles(const std::string &configuration) const
Modifies file name options according to the configuration path.
virtual bool isDefault() const
Returns the information whether the option holds the default value.
virtual int getInt() const
Returns the stored integer value.
virtual SUMOReal getFloat() const
Returns the stored SUMOReal value.
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
virtual std::string getValueString() const =0
Returns the string-representation of the value.
std::map< std::string, std::vector< std::string > > mySubTopicEntries
A map from subtopic to option.
friend std::ostream & operator<<(std::ostream &os, const OptionsCont &oc)
Output operator.
static std::string urlDecode(const std::string &encoded)
A storage for options typed value containers)
Option * getSecure(const std::string &name) const
Returns the named option.
std::vector< std::string > myCopyrightNotices
void writeConfiguration(std::ostream &os, bool filled, bool complete, bool addComments) const
Writes the configuration.
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
#define WRITE_MESSAGE(msg)
OptionsCont()
Constructor.
std::vector< std::pair< std::string, std::string > > myCallExamples
list of call examples
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.