Eclipse SUMO - Simulation of Urban MObility
OptionsCont.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
21// A storage for options (typed value containers)
22/****************************************************************************/
23#pragma once
24#include <config.h>
25
26#include <map>
27#include <string>
28#include <vector>
29#include <iostream>
30#include "Option.h"
31
32
33// ===========================================================================
34// class definitions
35// ===========================================================================
90public:
92 static OptionsCont& getOptions();
93
94
97
98
100 ~OptionsCont();
101
102
103
106
112 void setApplicationName(const std::string& appName, const std::string& fullName);
113
114
119 void setApplicationDescription(const std::string& appDesc);
120
121
127 void addCallExample(const std::string& example, const std::string& desc);
128
129
134 void setAdditionalHelpMessage(const std::string& add);
135
136
141 void addCopyrightNotice(const std::string& copyrightLine);
142
143
147
148
157 void addOptionSubTopic(const std::string& topic);
158
159
164 void printHelp(std::ostream& os);
165
171 void printHelpOnTopic(const std::string& topic, int tooLarge, int maxSize, std::ostream& os);
172
184 void writeConfiguration(std::ostream& os, const bool filled,
185 const bool complete, const bool addComments, const std::string& relativeTo = "",
186 const bool forceRelative = false, const bool inComment = false) const;
187
188
196 void writeSchema(std::ostream& os);
197
198
207 void writeXMLHeader(std::ostream& os, const bool includeConfig = true) const;
209
210
211
212
215
221 void doRegister(const std::string& name, Option* v);
222
223
233 void doRegister(const std::string& name, char abbr, Option* v);
234
235
252 void addSynonyme(const std::string& name1, const std::string& name2, bool isDeprecated = false);
253
254
260 void addXMLDefault(const std::string& name, const std::string& xmlRoot = "");
261
262
276 void addDescription(const std::string& name, const std::string& subtopic,
277 const std::string& description);
279
280
281
282
285
289 bool exists(const std::string& name) const;
290
291
307 bool isSet(const std::string& name, bool failOnNonExistant = true) const;
308
309
323 bool isDefault(const std::string& name) const;
324
325
335 bool isBool(const std::string& name) const;
336
337
355 bool isUsableFileList(const std::string& name) const;
356
357
368 bool checkDependingSuboptions(const std::string& name, const std::string& prefix) const;
369
370
378 void relocateFiles(const std::string& configuration) const;
379
380
390 std::vector<std::string> getSynonymes(const std::string& name) const;
391
398 const std::string& getDescription(const std::string& name) const;
399
400
412 bool isWriteable(const std::string& name);
414
415
416
417
420
430 std::string getValueString(const std::string& name) const;
431
442 std::string getString(const std::string& name) const;
443
444
455 double getFloat(const std::string& name) const;
456
457
468 int getInt(const std::string& name) const;
469
470
481 bool getBool(const std::string& name) const;
482
483
494 const IntVector& getIntVector(const std::string& name) const;
495
511 const StringVector& getStringVector(const std::string& name) const;
512
530 bool isInStringVector(const std::string& optionName,
531 const std::string& itemName) const;
533
534
535
536
539
559 bool set(const std::string& name, const std::string& value, const bool append = false);
560
580 bool setDefault(const std::string& name, const std::string& value);
581
594 bool setByRootElement(const std::string& name, const std::string& value);
596
597
604 void resetWritable();
605
614 friend std::ostream& operator<<(std::ostream& os, const OptionsCont& oc);
615
616
618 void clear();
619
620
637 bool processMetaOptions(bool missingOptions);
638
639
641 const std::vector<std::string>& getSubTopics() const {
642 return mySubTopics;
643 }
644
645
647 std::vector<std::string> getSubTopicsEntries(const std::string& subtopic) const {
648 if (mySubTopicEntries.count(subtopic) > 0) {
649 return mySubTopicEntries.find(subtopic)->second;
650 } else {
651 return std::vector<std::string>();
652 }
653 }
654
655
657 std::string getTypeName(const std::string name) {
658 return getSecure(name)->getTypeName();
659 }
660
661
662 inline const std::string& getFullName() const {
663 return myFullName;
664 }
665
666private:
674 Option* getSecure(const std::string& name) const;
675
676
684 void reportDoubleSetting(const std::string& arg) const;
685
686
694 std::string convertChar(char abbr) const;
695
696
708 void splitLines(std::ostream& os, std::string what,
709 int offset, int nextOffset);
710
711
712private:
715
717 typedef std::vector<Option*> ItemAddressContType;
718
720 typedef std::map<std::string, Option*> KnownContType;
721
724
727
730
732 std::vector< std::pair<std::string, std::string> > myCallExamples;
733
735 std::vector<std::string> mySubTopics, myCopyrightNotices;
736
738 std::map<std::string, std::vector<std::string> > mySubTopicEntries;
739
741 std::map<std::string, std::string> myXMLDefaults;
742
744 mutable std::map<std::string, bool> myDeprecatedSynonymes;
745
748
749
750private:
753
756
757};
std::vector< std::string > StringVector
Definition of a vector of strings.
Definition: Option.h:43
std::vector< int > IntVector
Definition of a vector of ints.
Definition: Option.h:38
A class representing a single program option.
Definition: Option.h:73
virtual const std::string & getTypeName() const
Returns the mml-type name of this option.
Definition: Option.cpp:151
A storage for options typed value containers)
Definition: OptionsCont.h:89
void setAdditionalHelpMessage(const std::string &add)
Sets an additional message to be printed at the begin of the help screen.
~OptionsCont()
Destructor.
Definition: OptionsCont.cpp:70
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:76
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
std::vector< std::pair< std::string, std::string > > myCallExamples
list of call examples
Definition: OptionsCont.h:732
bool isWriteable(const std::string &name)
Returns the information whether the named option may be set.
std::map< std::string, std::vector< std::string > > mySubTopicEntries
A map from subtopic to option.
Definition: OptionsCont.h:738
void writeXMLHeader(std::ostream &os, const bool includeConfig=true) const
Writes a standard XML header, including the configuration.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
OptionsCont(const OptionsCont &s)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
friend std::ostream & operator<<(std::ostream &os, const OptionsCont &oc)
Output operator.
void splitLines(std::ostream &os, std::string what, int offset, int nextOffset)
Writes the given string 'formatted'.
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
std::vector< Option * > ItemAddressContType
Definition: OptionsCont.h:717
void printHelpOnTopic(const std::string &topic, int tooLarge, int maxSize, std::ostream &os)
Prints help on the given topic.
std::string myAdditionalMessage
Definition: OptionsCont.h:729
std::vector< std::string > myCopyrightNotices
Definition: OptionsCont.h:735
const std::vector< std::string > & getSubTopics() const
return the list of subtopics
Definition: OptionsCont.h:641
const IntVector & getIntVector(const std::string &name) const
Returns the list of integer-value of the named option (only for Option_IntVector)
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.
std::vector< std::string > mySubTopics
lists of option subtopics and copyright notices
Definition: OptionsCont.h:735
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool myWriteLicense
Information whether we should always include license information in file headers.
Definition: OptionsCont.h:747
ItemAddressContType myAddresses
Definition: OptionsCont.h:723
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
Definition: OptionsCont.cpp:97
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
bool setDefault(const std::string &name, const std::string &value)
Sets the given value for the named option as new default value.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
KnownContType myValues
Definition: OptionsCont.h:726
const std::string & getFullName() const
Definition: OptionsCont.h:662
bool isBool(const std::string &name) const
Returns the information whether the option is a boolean option.
void addCopyrightNotice(const std::string &copyrightLine)
Adds a copyright notice to the help output.
std::string getTypeName(const std::string name)
return the type name for the given option
Definition: OptionsCont.h:657
void writeSchema(std::ostream &os)
Writes the xml schema for the configuration.
void clear()
Removes all information from the container.
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
bool set(const std::string &name, const std::string &value, const bool append=false)
Sets the given value for the named option.
void writeConfiguration(std::ostream &os, const bool filled, const bool complete, const bool addComments, const std::string &relativeTo="", const bool forceRelative=false, const bool inComment=false) const
Writes the configuration.
void clearCopyrightNotices()
Removes all copyright information.
std::string convertChar(char abbr) const
Converts an abbreviation into a name.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
OptionsCont()
Constructor.
Definition: OptionsCont.cpp:64
void printHelp(std::ostream &os)
Prints the help.
OptionsCont & operator=(const OptionsCont &s)
std::string getValueString(const std::string &name) const
Returns the string-value of the named option (all options)
std::string myAppDescription
Definition: OptionsCont.h:729
std::map< std::string, Option * > KnownContType
Definition: OptionsCont.h:720
const std::string & getDescription(const std::string &name) const
Returns the option description.
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.
Definition: OptionsCont.h:744
static OptionsCont myOptions
The static options container used.
Definition: OptionsCont.h:714
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.
std::map< std::string, std::string > myXMLDefaults
A map from XML root element to option.
Definition: OptionsCont.h:741
std::string myAppName
some information on the application
Definition: OptionsCont.h:729
void resetWritable()
Resets all options to be writeable.
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.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:59
std::string myFullName
Definition: OptionsCont.h:729
std::vector< std::string > getSubTopicsEntries(const std::string &subtopic) const
return the list of entries for the given subtopic
Definition: OptionsCont.h:647
Option * getSecure(const std::string &name) const
Returns the named option.
void relocateFiles(const std::string &configuration) const
Modifies file name options according to the configuration path.
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 processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
bool isUsableFileList(const std::string &name) const
Checks whether the named option is usable as a file list (with at least a single file)
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.