71 myCopyrightNotices.push_back(
"Copyright (C) 2001-2017 German Aerospace Center (DLR) and others; http://sumo.dlr.de");
88 throw ProcessError(name +
" is an already used option name.");
103 KnownContType::iterator i1 =
myValues.find(name1);
104 KnownContType::iterator i2 =
myValues.find(name2);
106 throw ProcessError(
"Neither the option '" + name1 +
"' nor the option '" + name2 +
"' is known yet");
109 if ((*i1).second == (*i2).second) {
112 throw ProcessError(
"Both options '" + name1 +
"' and '" + name2 +
"' do exist and differ.");
143 KnownContType::const_iterator i =
myValues.find(name);
145 if (failOnNonExistant) {
146 throw ProcessError(
"Internal request for unknown option '" + name +
"'!");
151 return (*i).second->isSet();
157 KnownContType::const_iterator i =
myValues.find(name);
159 if (failOnNonExistant) {
160 throw ProcessError(
"Internal request for unknown option '" + name +
"'!");
165 (*i).second->unSet();
171 KnownContType::const_iterator i =
myValues.find(name);
175 return (*i).second->isDefault();
181 KnownContType::const_iterator k =
myValues.find(name);
183 throw ProcessError(
"No option with the name '" + name +
"' exists.");
187 std::string defaultName;
189 for (std::vector<std::string>::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
190 KnownContType::const_iterator l =
myValues.find(*j);
191 if (l !=
myValues.end() && l->second == k->second) {
196 if (defaultName !=
"") {
200 WRITE_WARNING(
"Please note that '" + name +
"' is deprecated.\n Use '" + defaultName +
"' instead.");
250 if (!o->
set(value)) {
254 WRITE_ERROR(
"While processing option '" + name +
"':\n " + e.what());
263 if (
set(name, value)) {
283 std::vector<std::string>
286 std::vector<std::string> v(0);
287 for (KnownContType::const_iterator i =
myValues.begin(); i !=
myValues.end(); i++) {
288 if ((*i).second == o && name != (*i).first) {
289 v.push_back((*i).first);
298 std::vector<std::string> done;
299 os <<
"Options set:" << std::endl;
300 for (OptionsCont::KnownContType::const_iterator i = oc.
myValues.begin();
302 std::vector<std::string>::iterator j = find(done.begin(), done.end(), (*i).first);
303 if (j == done.end()) {
304 std::vector<std::string> synonymes = oc.
getSynonymes((*i).first);
305 if (synonymes.size() != 0) {
306 os << (*i).first <<
" (";
307 for (j = synonymes.begin(); j != synonymes.end(); j++) {
308 if (j != synonymes.begin()) {
317 if ((*i).second->isSet()) {
318 os <<
": " << (*i).second->getValueString() << std::endl;
320 os <<
": <INVALID>" << std::endl;
322 done.push_back((*i).first);
323 copy(synonymes.begin(), synonymes.end(), back_inserter(done));
333 if ((*i)->isFileName() && (*i)->isSet()) {
336 while (st.hasNext()) {
337 std::string tmp = st.
next();
340 if (tmp.find_first_not_of(
"\t ") == std::string::npos) {
346 if (conv.length() != 0) {
351 if (conv != (*i)->getString()) {
352 const bool hadDefault = (*i)->isDefault();
355 (*i)->resetDefault();
374 if (files.size() == 0) {
375 WRITE_ERROR(
"The file list for '" + name +
"' is empty.");
378 for (std::vector<std::string>::const_iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt) {
381 WRITE_ERROR(
"File '" + *fileIt +
"' is not accessible (" + std::strerror(errno) +
").");
399 std::vector<std::string> seenSynonymes;
400 for (KnownContType::const_iterator i =
myValues.begin(); i !=
myValues.end(); i++) {
401 if (std::find(seenSynonymes.begin(), seenSynonymes.end(), (*i).first) != seenSynonymes.end()) {
404 if ((*i).second->isSet() && !(*i).second->isDefault() && (*i).first.find(prefix) == 0) {
405 WRITE_ERROR(
"Option '" + (*i).first +
"' needs option '" + name +
"'.");
406 std::vector<std::string> synonymes =
getSynonymes((*i).first);
407 std::copy(synonymes.begin(), synonymes.end(), std::back_inserter(seenSynonymes));
418 std::ostringstream s;
419 s <<
"A value for the option '" + arg +
"' was already set.\n Possible synonymes: ";
420 for (std::vector<std::string>::iterator i = synonymes.begin(); i != synonymes.end();) {
423 if (i != synonymes.end()) {
451 (*i)->resetWritable();
465 ItemAddressContType::iterator i;
478 const std::string& subtopic,
479 const std::string& description) {
490 const std::string& fullName) {
535 int offset,
int nextOffset) {
536 while (what.length() > 0) {
537 if ((
int)what.length() > 79 - offset) {
538 std::string::size_type splitPos = what.rfind(
';', 79 - offset);
539 if (splitPos == std::string::npos) {
540 splitPos = what.rfind(
' ', 79 - offset);
544 if (splitPos != std::string::npos) {
545 os << what.substr(0, splitPos) << std::endl;
546 what = what.substr(splitPos);
547 for (
int r = 0; r < nextOffset + 1; ++r) {
566 if (missingOptions) {
569 std::cout <<
" Build features: " <<
HAVE_ENABLED << std::endl;
570 for (std::vector<std::string>::const_iterator it =
572 std::cout <<
" " << *it << std::endl;
574 std::cout <<
" License EPLv2: Eclipse Public License Version 2 <https://eclipse.org/legal/epl-v20.html>\n";
575 std::cout <<
" Use --help to get the list of options." << std::endl;
582 for (std::vector<std::string>::const_iterator it =
584 std::cout <<
" " << *it << std::endl;
592 std::cout <<
" Build features: " <<
HAVE_ENABLED << std::endl;
593 for (std::vector<std::string>::const_iterator it =
595 std::cout <<
" " << *it << std::endl;
597 std::cout <<
"\n" <<
myFullName <<
" is part of SUMO.\n";
598 std::cout <<
"SUMO is free software: you can redistribute it and/or modify\n";
599 std::cout <<
"it under the terms of the GNU General Public License as published by\n";
600 std::cout <<
"the Free Software Foundation, either version 3 of the License, or\n";
601 std::cout <<
"(at your option) any later version.\n\n";
602 std::cout <<
"This program is distributed in the hope that it will be useful,\n";
603 std::cout <<
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n";
604 std::cout <<
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n";
605 std::cout <<
"GNU General Public License for more details.\n\n";
606 std::cout <<
"You should have received a copy of the GNU General Public License\n";
607 std::cout <<
"along with this program. If not, see http://www.gnu.org/licenses/gpl.html" << std::endl;
612 std::cout << (*this);
616 if (
isSet(
"save-configuration",
false)) {
617 if (
getString(
"save-configuration") ==
"-" ||
getString(
"save-configuration") ==
"stdout") {
621 std::ofstream out(
getString(
"save-configuration").c_str());
633 if (
isSet(
"save-template",
false)) {
638 std::ofstream out(
getString(
"save-template").c_str());
649 if (
isSet(
"save-schema",
false)) {
654 std::ofstream out(
getString(
"save-schema").c_str());
670 std::vector<std::string>::const_iterator i, j;
675 os <<
"Usage: " <<
myAppName <<
" [OPTION]*" << std::endl;
687 for (j = entries.begin(); j != entries.end(); ++j) {
690 int csize = (int)j->length() + 2 + 4;
692 const std::vector<std::string> synonymes =
getSynonymes(*j);
693 for (std::vector<std::string>::const_iterator s = synonymes.begin(); s != synonymes.end(); ++s) {
705 if (csize < tooLarge && maxSize < csize) {
712 os << *i <<
" Options:" << std::endl;
714 for (j = entries.begin(); j != entries.end(); ++j) {
716 int csize = (int)j->length() + 2;
721 for (std::vector<std::string>::const_iterator s = synonymes.begin(); s != synonymes.end(); ++s) {
723 os <<
'-' << *s <<
", ";
741 for (
int r = maxSize; r > csize; --r) {
744 int offset = csize > tooLarge ? csize : maxSize;
752 os <<
"Examples:" << std::endl;
754 os <<
" " <<
myAppName <<
' ' << e->first << std::endl;
755 os <<
" " << e->second << std::endl;
759 os <<
"Report bugs at <http://sumo.dlr.de/trac/>." << std::endl;
760 os <<
"Get in contact via <sumo@dlr.de>." << std::endl;
766 const bool complete,
const bool addComments,
767 const bool maskDoubleHyphen)
const {
769 os <<
"<configuration xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/";
777 os <<
"Configuration.xsd\">" << std::endl << std::endl;
779 std::string subtopic = *i;
780 if (subtopic ==
"Configuration" && !complete) {
783 std::replace(subtopic.begin(), subtopic.end(),
' ',
'_');
784 std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
787 for (std::vector<std::string>::const_iterator j = entries.begin(); j != entries.end(); ++j) {
789 bool write = complete || (filled && !o->
isDefault());
794 os <<
" <" << subtopic <<
">" << std::endl;
801 os <<
" <" << *j <<
" value=\"";
807 if (!synonymes.empty()) {
808 os <<
"\" synonymes=\"";
809 for (std::vector<std::string>::const_iterator s = synonymes.begin(); s != synonymes.end(); ++s) {
810 if (s != synonymes.begin()) {
821 os <<
"\"/>" << std::endl;
829 os <<
" </" << subtopic <<
">" << std::endl << std::endl;
832 os <<
"</configuration>" << std::endl;
839 os <<
"<xsd:schema elementFormDefault=\"qualified\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n\n";
840 os <<
" <xsd:include schemaLocation=\"baseTypes.xsd\"/>\n";
841 os <<
" <xsd:element name=\"configuration\" type=\"configurationType\"/>\n\n";
842 os <<
" <xsd:complexType name=\"configurationType\">\n";
843 os <<
" <xsd:all>\n";
845 std::string subtopic = *i;
846 if (subtopic ==
"Configuration") {
849 std::replace(subtopic.begin(), subtopic.end(),
' ',
'_');
850 std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
851 os <<
" <xsd:element name=\"" << subtopic <<
"\" type=\"" << subtopic <<
"Type\" minOccurs=\"0\"/>\n";
853 os <<
" </xsd:all>\n";
854 os <<
" </xsd:complexType>\n\n";
856 std::string subtopic = *i;
857 if (subtopic ==
"Configuration") {
860 std::replace(subtopic.begin(), subtopic.end(),
' ',
'_');
861 std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
862 os <<
" <xsd:complexType name=\"" << subtopic <<
"Type\">\n";
863 os <<
" <xsd:all>\n";
865 for (std::vector<std::string>::const_iterator j = entries.begin(); j != entries.end(); ++j) {
868 std::transform(type.begin(), type.end(), type.begin(), tolower);
869 if (type ==
"int[]") {
872 os <<
" <xsd:element name=\"" << *j <<
"\" type=\"" << type <<
"OptionType\" minOccurs=\"0\"/>\n";
874 os <<
" </xsd:all>\n";
875 os <<
" </xsd:complexType>\n\n";
877 os <<
"</xsd:schema>\n";
888 strftime(buffer, 80,
"<!-- generated on %c by ", localtime(&rawtime));
895 std::vector<std::string>
900 WRITE_WARNING(
"Please note that using ';' as list separator is deprecated.\n From 1.0 onwards, only ',' will be accepted.");
904 std::vector<std::string> ret = st.
getVector();
905 for (std::vector<std::string>::iterator i = ret.begin(); i != ret.end(); ++i) {
914 const std::string& itemName) {
915 if (
isSet(optionName)) {
917 return find(values.begin(), values.end(), itemName) != values.end();
virtual double getFloat() const
Returns the stored double value.
std::string myAppName
some information on the application
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
virtual const IntVector & getIntVector() const
Returns the stored integer vector.
std::vector< std::string > mySubTopics
lists of option subtopics and copyright notices
void reportDoubleSetting(const std::string &arg) const
Reports an error that the option has already been set.
static std::string getConfigurationRelative(const std::string &configPath, const std::string &path)
Returns the second path as a relative path to the first file.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
void resetWritable()
Resets all options to be writeable.
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.
virtual std::string getString() const
Returns the stored string value.
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
void clearCopyrightNotices()
Removes all copyright information.
void printHelp(std::ostream &os)
Prints the help.
bool myHaveInformedAboutDeprecatedDivider
Information whether a warning a deprecated divider.
void splitLines(std::ostream &os, std::string what, int offset, int nextOffset)
Writes the given string 'formatted'.
void setDescription(const std::string &desc)
Sets the description of what this option does.
static OptionsCont myOptions
The static options container used.
bool isWriteable() const
Returns the information whether the option may be set a further time.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
std::map< std::string, std::string > myXMLDefaults
A map from XML root element to option.
virtual int getInt() const
Returns the stored integer value.
#define WRITE_WARNING(msg)
static OptionsCont & getOptions()
Retrieves the options.
void resetDefault()
Resets the option to be on its default value.
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
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
bool setByRootElement(const std::string &name, const std::string &value)
Sets the given value for the option which can handle the given XML root.
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.
std::string myAdditionalMessage
std::vector< int > IntVector
Definition of a vector of ints.
bool isUsableFileList(const std::string &name) const
Checks whether the named option is usable as a file list (with at least a single file) ...
bool setDefault(const std::string &name, const std::string &value)
Sets the given value for the named option as new default value.
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.
static const std::string ENCODING
The encoding of parsed strings.
Option * getSecure(const std::string &name) const
Returns the named option.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
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) ...
bool isBool(const std::string &name) const
Returns the information whether the option is a boolean option.
~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.
virtual bool set(const std::string &v)=0
Stores the given value.
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
void relocateFiles(const std::string &configuration) const
Modifies file name options according to the configuration path.
virtual bool isBool() const
Returns the information whether the option is a bool option.
void writeSchema(std::ostream &os, bool addComments)
Writes the xml schema for the configuration.
std::vector< std::string > getVector()
A class representing a single program option.
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 getBool() const
Returns the stored boolean value.
std::vector< std::string > getSynonymes(const std::string &name) const
Returns the synonymes of an option name.
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
virtual bool isDefault() const
Returns the information whether the option holds the default value.
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.
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...
const std::string & getDescription() const
Returns the description of what this option does.
const IntVector & getIntVector(const std::string &name) const
Returns the list of integer-value of the named option (only for Option_IntVector) ...
void unSet(const std::string &name, bool failOnNonExistant=true) const
Marks the option as unset.
std::map< std::string, std::vector< std::string > > mySubTopicEntries
A map from subtopic to option.
bool isSet() const
returns the information whether this options holds a valid value
friend std::ostream & operator<<(std::ostream &os, const OptionsCont &oc)
Output operator.
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
static std::string urlDecode(const std::string &encoded)
A storage for options typed value containers)
std::vector< std::string > myCopyrightNotices
void writeConfiguration(std::ostream &os, const bool filled, const bool complete, const bool addComments, const bool maskDoubleHyphen=false) const
Writes the configuration.
std::string convertChar(char abbr) const
Converts an abbreviation into a name.
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
#define WRITE_MESSAGE(msg)
OptionsCont()
Constructor.
std::vector< std::pair< std::string, std::string > > myCallExamples
list of call examples
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.