Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
OptionsCont.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 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// ===========================================================================
90
91public:
93 static OptionsCont& getOptions();
94
97
100
102 ~OptionsCont();
103
106
112 void setApplicationName(const std::string& appName, const std::string& fullName);
113
118 void setApplicationDescription(const std::string& appDesc);
119
125 void addCallExample(const std::string& example, const std::string& desc);
126
131 void setAdditionalHelpMessage(const std::string& add);
132
137 void addCopyrightNotice(const std::string& copyrightLine);
138
142
151 void addOptionSubTopic(const std::string& topic);
152
157 void printHelp(std::ostream& os);
158
164 void printHelpOnTopic(const std::string& topic, int tooLarge, int maxSize, std::ostream& os);
165
177 void writeConfiguration(std::ostream& os, const bool filled,
178 const bool complete, const bool addComments, const std::string& relativeTo = "",
179 const bool forceRelative = false, const bool inComment = false, const std::string& indent = "") const;
180
188 void writeSchema(std::ostream& os);
189
198 void writeXMLHeader(std::ostream& os, const bool includeConfig = true) const;
199
201
204
210 void doRegister(const std::string& name, Option* o);
211
221 void doRegister(const std::string& name, char abbr, Option* o);
222
239 void addSynonyme(const std::string& name1, const std::string& name2, bool isDeprecated = false);
240
246 void addXMLDefault(const std::string& name, const std::string& xmlRoot = "");
247
261 void addDescription(const std::string& name, const std::string& subtopic, const std::string& description);
262
274 void setFurtherAttributes(const std::string& name, const std::string& subtopic, bool required, bool positional, const std::string& listSep);
275
286 void setOptionEditable(const std::string& name, const bool value);
287
289
292
296 bool exists(const std::string& name) const;
297
313 bool isSet(const std::string& name, bool failOnNonExistant = true) const;
314
328 bool isDefault(const std::string& name) const;
329
339 bool isBool(const std::string& name) const;
340
358 bool isUsableFileList(const std::string& name) const;
359
370 bool checkDependingSuboptions(const std::string& name, const std::string& prefix) const;
371
379 void relocateFiles(const std::string& configuration) const;
380
390 std::vector<std::string> getSynonymes(const std::string& name) const;
391
398 const std::string& getDescription(const std::string& name) const;
399
406 const std::string& getSubTopic(const std::string& name) const;
407
419 bool isWriteable(const std::string& name);
420
427 bool isEditable(const std::string& name);
428
430
433
444 std::string getValueString(const std::string& name) const;
445
456 std::string getString(const std::string& name) const;
457
468 double getFloat(const std::string& name) const;
469
480 int getInt(const std::string& name) const;
481
492 bool getBool(const std::string& name) const;
493
504 const IntVector& getIntVector(const std::string& name) const;
505
521 const StringVector& getStringVector(const std::string& name) const;
522
540 bool isInStringVector(const std::string& optionName, const std::string& itemName) const;
541
543
546
566 bool set(const std::string& name, const std::string& value, const bool append = false);
567
587 bool setDefault(const std::string& name, const std::string& value);
588
601 bool setByRootElement(const std::string& name, const std::string& value);
602
604
611 void resetWritable();
612
614 void resetDefault();
615
617 void resetDefault(const std::string& name);
618
627 friend std::ostream& operator<<(std::ostream& os, const OptionsCont& oc);
628
630 void clear();
631
648 bool processMetaOptions(bool missingOptions);
649
651
653 const std::vector<std::string>& getSubTopics() const;
654
656 std::vector<std::string> getSubTopicsEntries(const std::string& subtopic) const;
657
659 std::string getTypeName(const std::string name);
660
662 const std::string& getFullName() const;
663
665 bool isEmpty() const;
666
668 std::vector<std::pair<std::string, Option*> >::const_iterator begin() const;
669
671 std::vector<std::pair<std::string, Option*> >::const_iterator end() const;
672
674 OptionsCont* clone() const;
675
676private:
684 Option* getSecure(const std::string& name) const;
685
693 void reportDoubleSetting(const std::string& arg) const;
694
702 std::string convertChar(char abbr) const;
703
715 void splitLines(std::ostream& os, std::string what, int offset, int nextOffset);
716
718 bool myAmLocalized = false;
719
722
724 std::vector<std::pair<std::string, Option*> > myAddresses;
725
727 std::map<std::string, Option*> myValues;
728
731
733 std::vector< std::pair<std::string, std::string> > myCallExamples;
734
736 std::vector<std::string> mySubTopics, myCopyrightNotices;
737
739 std::map<std::string, std::vector<std::string> > mySubTopicEntries;
740
742 std::map<std::string, std::string> myXMLDefaults;
743
745 mutable std::map<std::string, bool> myDeprecatedSynonymes;
746
748 OptionsCont(const OptionsCont& s) = default;
749
751 OptionsCont& operator=(const OptionsCont& s) = delete;
752};
std::vector< std::string > StringVector
Definition of a vector of strings.
Definition Option.h:42
std::vector< int > IntVector
Definition of a vector of ints.
Definition Option.h:37
A class representing a single program option.
Definition Option.h:74
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.
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an 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 std::string &indent="") const
Writes the configuration.
void resetDefault()
Resets all options to default.
void setFurtherAttributes(const std::string &name, const std::string &subtopic, bool required, bool positional, const std::string &listSep)
mark option as required
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
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.
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)
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.
OptionsCont * clone() const
make a copy of this OptionsCont instance
void printHelpOnTopic(const std::string &topic, int tooLarge, int maxSize, std::ostream &os)
Prints help on the given topic.
const std::string & getSubTopic(const std::string &name) const
Returns the option category.
std::map< std::string, Option * > myValues
option maps sorted by name (for addresses AND their synonyms)
bool isEmpty() const
check if options container is empty
std::string myAdditionalMessage
std::vector< std::string > myCopyrightNotices
const std::vector< std::string > & getSubTopics() const
return the list of subtopics
void setOptionEditable(const std::string &name, const bool value)
set option editable
bool myAmLocalized
Whether the descriptino has already been translated to the locale language.
std::vector< std::pair< std::string, Option * > > myAddresses
option-addresses
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
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static OptionsCont EMPTY_OPTIONS
empty option container
Definition OptionsCont.h:96
void localizeDescriptions()
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
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.
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
const std::string & getFullName() const
get options full name
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
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.
std::vector< std::pair< std::string, Option * > >::const_iterator begin() const
get begin addresses iterator
bool set(const std::string &name, const std::string &value, const bool append=false)
Sets the given value for the named option.
bool isEditable(const std::string &name)
Returns the information whether the named option is editable.
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.
void printHelp(std::ostream &os)
Prints the help.
std::vector< std::pair< std::string, Option * > >::const_iterator end() const
get begin addresses iterator
std::string getValueString(const std::string &name) const
Returns the string-value of the named option (all options)
std::string myAppDescription
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.
OptionsCont & operator=(const OptionsCont &s)=delete
invalid assignment operator
static OptionsCont myOptions
The static options container used.
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.
std::string myAppName
some information on the application
void resetWritable()
Resets all options to be writeable.
OptionsCont(const OptionsCont &s)=default
default copy constructor, but private
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.
std::string myFullName
std::vector< std::string > getSubTopicsEntries(const std::string &subtopic) const
return the list of entries for the given subtopic
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.