52 #ifdef CHECK_MEMORY_LEAKS
54 #endif // CHECK_MEMORY_LEAKS
73 : myAddresses(), myValues(), myDeprecatedSynonymes(), myHaveInformedAboutDeprecatedDivider(false) {
74 myCopyrightNotices.push_back(
"Copyright (C) 2001-2012 DLR and contributors; http://sumo.sourceforge.net");
91 throw ProcessError(name +
" is an already used option name.");
106 KnownContType::iterator i1 =
myValues.find(name1);
107 KnownContType::iterator i2 =
myValues.find(name2);
109 throw ProcessError(
"Neither the option '" + name1 +
"' nor the option '" + name2 +
"' is known yet");
112 if ((*i1).second == (*i2).second) {
115 throw ProcessError(
"Both options '" + name1 +
"' and '" + name2 +
"' do exist and differ.");
140 KnownContType::const_iterator i =
myValues.find(name);
142 if (failOnNonExistant) {
143 throw ProcessError(
"Internal request for unknown option '" + name +
"'!");
148 return (*i).second->isSet();
154 KnownContType::const_iterator i =
myValues.find(name);
158 return (*i).second->isDefault();
164 KnownContType::const_iterator k =
myValues.find(name);
166 throw ProcessError(
"No option with the name '" + name +
"' exists.");
170 std::string defaultName;
172 for (std::vector<std::string>::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
173 KnownContType::const_iterator l =
myValues.find(*j);
174 if (l !=
myValues.end() && l->second == k->second) {
179 if (defaultName !=
"") {
183 WRITE_WARNING(
"Please note that '" + name +
"' is deprecated.\n Use '" + defaultName +
"' instead.");
233 if (!o->
set(value)) {
237 WRITE_ERROR(
"While processing option '" + name +
"':\n " + e.what());
244 std::vector<std::string>
247 std::vector<std::string> v(0);
248 for (KnownContType::const_iterator i =
myValues.begin(); i !=
myValues.end(); i++) {
249 if ((*i).second == o && name != (*i).first) {
250 v.push_back((*i).first);
259 std::vector<std::string> done;
260 os <<
"Options set:" << std::endl;
261 for (OptionsCont::KnownContType::const_iterator i = oc.
myValues.begin();
263 std::vector<std::string>::iterator j = find(done.begin(), done.end(), (*i).first);
264 if (j == done.end()) {
265 std::vector<std::string> synonymes = oc.
getSynonymes((*i).first);
266 if (synonymes.size() != 0) {
267 os << (*i).first <<
" (";
268 for (j = synonymes.begin(); j != synonymes.end(); j++) {
269 if (j != synonymes.begin()) {
278 if ((*i).second->isSet()) {
279 os <<
": " << (*i).second->getValueString() << std::endl;
281 os <<
": <INVALID>" << std::endl;
283 done.push_back((*i).first);
284 copy(synonymes.begin(), synonymes.end(), back_inserter(done));
294 if ((*i)->isFileName() && (*i)->isSet()) {
297 while (st.hasNext()) {
298 if (conv.length() != 0) {
301 std::string tmp = st.
next();
324 if (files.size() == 0) {
325 WRITE_ERROR(
"The file list for '" + name +
"' is empty.");
328 for (std::vector<std::string>::const_iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt) {
331 WRITE_ERROR(
"File '" + *fileIt +
"' does not exist.");
349 std::vector<std::string> seenSynonymes;
350 for (KnownContType::const_iterator i =
myValues.begin(); i !=
myValues.end(); i++) {
351 if (std::find(seenSynonymes.begin(), seenSynonymes.end(), (*i).first) != seenSynonymes.end()) {
354 if ((*i).second->isSet() && !(*i).second->isDefault() && (*i).first.find(prefix) == 0) {
355 WRITE_ERROR(
"Option '" + (*i).first +
"' needs option '" + name +
"'.");
356 std::vector<std::string> synonymes =
getSynonymes((*i).first);
357 std::copy(synonymes.begin(), synonymes.end(), std::back_inserter(seenSynonymes));
368 std::ostringstream s;
369 s <<
"A value for the option '" + arg +
"' was already set.\n Possible synonymes: ";
370 for (std::vector<std::string>::iterator i = synonymes.begin(); i != synonymes.end();) {
373 if (i != synonymes.end()) {
401 (*i)->resetWritable();
415 ItemAddressContType::iterator i;
428 const std::string& subtopic,
429 const std::string& description) {
440 const std::string& fullName) {
485 size_t offset,
size_t nextOffset) {
486 while (what.length() > 0) {
487 if (what.length() > 79 - offset) {
488 size_t splitPos = what.rfind(
';', 79 - offset);
489 if (splitPos == std::string::npos) {
490 splitPos = what.rfind(
' ', 79 - offset);
494 if (splitPos != std::string::npos) {
495 os << what.substr(0, splitPos) << std::endl;
496 what = what.substr(splitPos);
497 for (
size_t r = 0; r < nextOffset + 1; ++r) {
516 if (missingOptions) {
519 for (std::vector<std::string>::const_iterator it =
521 std::cout <<
" " << *it << std::endl;
523 std::cout <<
" License GPLv3+: GNU GPL Version 3 or later <http://gnu.org/licenses/gpl.html>\n";
524 std::cout <<
" Use --help to get the list of options." << std::endl;
531 for (std::vector<std::string>::const_iterator it =
533 std::cout <<
" " << *it << std::endl;
541 for (std::vector<std::string>::const_iterator it =
543 std::cout <<
" " << *it << std::endl;
545 std::cout <<
"\n" <<
myFullName <<
" is part of SUMO.\n";
546 std::cout <<
"SUMO is free software: you can redistribute it and/or modify\n";
547 std::cout <<
"it under the terms of the GNU General Public License as published by\n";
548 std::cout <<
"the Free Software Foundation, either version 3 of the License, or\n";
549 std::cout <<
"(at your option) any later version.\n\n";
550 std::cout <<
"This program is distributed in the hope that it will be useful,\n";
551 std::cout <<
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n";
552 std::cout <<
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n";
553 std::cout <<
"GNU General Public License for more details.\n\n";
554 std::cout <<
"You should have received a copy of the GNU General Public License\n";
555 std::cout <<
"along with this program. If not, see http://www.gnu.org/licenses/gpl.html" << std::endl;
560 std::cout << (*this);
564 if (
isSet(
"save-configuration",
false)) {
565 if (
getString(
"save-configuration") ==
"-" ||
getString(
"save-configuration") ==
"stdout") {
569 std::ofstream out(
getString(
"save-configuration").c_str());
581 if (
isSet(
"save-template",
false)) {
586 std::ofstream out(
getString(
"save-template").c_str());
597 if (
isSet(
"save-schema",
false)) {
602 std::ofstream out(
getString(
"save-schema").c_str());
618 std::vector<std::string>::const_iterator i, j;
623 os <<
"Usage: " <<
myAppName <<
" [OPTION]*" << std::endl;
631 size_t tooLarge = 40;
635 for (j = entries.begin(); j != entries.end(); ++j) {
638 size_t csize = (*j).length() + 2 + 4;
641 if (find_if(synonymes.begin(), synonymes.end(),
abbreviation_finder()) != synonymes.end()) {
650 if (csize < tooLarge && maxSize < csize) {
657 os << *i <<
" Options:" << std::endl;
659 for (j = entries.begin(); j != entries.end(); ++j) {
661 size_t csize = (*j).length() + 2;
666 std::vector<std::string>::iterator a = find_if(synonymes.begin(), synonymes.end(),
abbreviation_finder());
667 if (a != synonymes.end()) {
668 os <<
'-' << (*a) <<
", ";
684 for (
size_t r = maxSize; r > csize; --r) {
687 size_t offset = csize > tooLarge ? csize : maxSize;
695 os <<
"Examples:" << std::endl;
697 os <<
" " <<
myAppName <<
' ' << e->first << std::endl;
698 os <<
" " << e->second << std::endl;
702 os <<
"Report bugs at <http://sourceforge.net/apps/trac/sumo/>." << std::endl;
703 os <<
"Get in contact via <sumo-user@lists.sourceforge.net>." << std::endl;
709 bool complete,
bool addComments) {
711 os <<
"<configuration xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.sf.net/xsd/" <<
myAppName <<
"Configuration.xsd\">" << std::endl << std::endl;
713 std::string subtopic = *i;
714 if (subtopic ==
"Configuration" && !complete) {
717 std::replace(subtopic.begin(), subtopic.end(),
' ',
'_');
718 std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
721 for (std::vector<std::string>::const_iterator j = entries.begin(); j != entries.end(); ++j) {
723 bool write = complete || (filled && !o->
isDefault());
728 os <<
" <" << subtopic <<
">" << std::endl;
735 os <<
" <" << *j <<
" value=\"";
741 if (!synonymes.empty()) {
742 os <<
"\" synonymes=\"";
743 for (std::vector<std::string>::const_iterator s = synonymes.begin(); s != synonymes.end(); ++s) {
744 if (s != synonymes.begin()) {
755 os <<
"\"/>" << std::endl;
763 os <<
" </" << subtopic <<
">" << std::endl << std::endl;
766 os <<
"</configuration>" << std::endl;
773 os <<
"<xsd:schema elementFormDefault=\"qualified\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n\n";
774 os <<
" <xsd:element name=\"configuration\" type=\"configurationType\"/>\n\n";
775 os <<
" <xsd:complexType name=\"configurationType\">\n";
776 os <<
" <xsd:sequence>\n";
778 std::string subtopic = *i;
779 if (subtopic ==
"Configuration") {
782 std::replace(subtopic.begin(), subtopic.end(),
' ',
'_');
783 std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
784 os <<
" <xsd:element name=\"" << subtopic <<
"\" type=\"" << subtopic <<
"Type\" minOccurs=\"0\" maxOccurs=\"1\"/>\n";
786 os <<
" </xsd:sequence>\n";
787 os <<
" </xsd:complexType>\n\n";
789 std::string subtopic = *i;
790 if (subtopic ==
"Configuration") {
793 std::replace(subtopic.begin(), subtopic.end(),
' ',
'_');
794 std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
795 os <<
" <xsd:complexType name=\"" << subtopic <<
"Type\">\n";
796 os <<
" <xsd:sequence>\n";
798 for (std::vector<std::string>::const_iterator j = entries.begin(); j != entries.end(); ++j) {
799 os <<
" <xsd:element name=\"" << *j <<
"\" type=\"" << *j <<
"Type\" minOccurs=\"0\" maxOccurs=\"1\"/>\n";
801 os <<
" </xsd:sequence>\n";
802 os <<
" </xsd:complexType>\n\n";
803 for (std::vector<std::string>::const_iterator j = entries.begin(); j != entries.end(); ++j) {
806 std::transform(type.begin(), type.end(), type.begin(), tolower);
807 if (type ==
"bool") {
810 if (type !=
"int" && type !=
"float") {
814 os <<
" <xsd:complexType name=\"" << *j <<
"Type\">\n";
818 os <<
" <xsd:attribute name=\"value\" type=\"xsd:" << type <<
"\" use=\"required\"/>\n";
819 os <<
" <xsd:attribute name=\"synonymes\" type=\"xsd:string\" use=\"optional\"/>\n";
820 os <<
" <xsd:attribute name=\"type\" type=\"xsd:string\" use=\"optional\"/>\n";
821 os <<
" <xsd:attribute name=\"help\" type=\"xsd:string\" use=\"optional\"/>\n";
822 os <<
" </xsd:complexType>\n\n";
825 os <<
"</xsd:schema>\n";
834 os <<
"<?xml version=\"1.0\"" << xmlParams <<
"?>\n\n";
836 strftime(buffer, 80,
"<!-- generated on %c by ", localtime(&rawtime));
843 std::vector<std::string>
848 WRITE_WARNING(
"Please note that using ';' as list separator is deprecated.\n From 1.0 onwards, only ',' will be accepted.");
852 std::vector<std::string> ret = st.
getVector();
853 for (std::vector<std::string>::iterator i = ret.begin(); i != ret.end(); ++i) {
862 const std::string& itemName) {
863 if (
isSet(optionName)) {
865 return find(values.begin(), values.end(), itemName) != values.end();