Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/options/OptionsParser.h
169678 views
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
/****************************************************************************/
14
/// @file OptionsParser.h
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date Mon, 17 Dec 2001
19
///
20
// Parses command line arguments
21
/****************************************************************************/
22
#pragma once
23
#include <config.h>
24
25
26
// ===========================================================================
27
// class declarations
28
// ===========================================================================
29
class OptionsCont;
30
31
32
// ===========================================================================
33
// class definitions
34
// ===========================================================================
35
/**
36
* @class OptionsParser
37
* @brief Parses command line arguments
38
*
39
* The only public method parses the given list of arguments. It returns false
40
* when something failed. This may happen if the syntax of the arguments is
41
* invalid, a value is tried to be set several times or an unknown option
42
* is tried to be set.
43
*
44
* The class assumes all options are unset or using default values only.
45
*/
46
class OptionsParser {
47
public:
48
/** @brief Parses the given command line arguments
49
*
50
* @param[in] oc The options container to fill
51
* @param[in] args The command line arguments
52
* @return Whether the parsing was successful
53
* @exception InvalidArgument If a performed setting of an option failed (see Option::set)
54
*/
55
static bool parse(const std::vector<std::string>& args, const bool ignoreAppenders = false);
56
57
private:
58
/** @brief parses the previous arguments
59
*
60
* @param[in] arg1 The first token to parse
61
* @param[in] arg2 The second token to parse, 0 if there is none
62
* @param[in, out] ok Whether the parsing was successful
63
* @return Number of read tokens (1 or 2)
64
* @exception InvalidArgument If a performed setting of an option failed (see Option::set)
65
*/
66
static int check(const std::string& arg1, const std::string* const arg2, bool& ok, const bool ignoreAppenders);
67
68
69
/** @brief Returns the whether the given token is an option
70
*
71
* The given token is assumed to be an option if it starts with a '-' or a '+'.
72
*
73
* @param[in] arg1 The token to check
74
* @return Whether the token is an option
75
*/
76
static bool checkParameter(const std::string& arg1);
77
78
79
/** @brief Extracts the parameter directly attached to an option
80
*
81
* Parses single tokens which contain an option and the parameter
82
* (like -c=myconfig.cfg)
83
*
84
* @param[in] oc The container to store the result into
85
* @param[in] arg The token to parse
86
* @exception InvalidArgument If a performed setting of an option failed (see Option::set)
87
*/
88
static bool processNonBooleanSingleSwitch(OptionsCont& oc, const std::string& arg, const bool append);
89
90
91
};
92
93