/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file OptionsParser.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date Mon, 17 Dec 200118///19// Parses command line arguments20/****************************************************************************/21#pragma once22#include <config.h>232425// ===========================================================================26// class declarations27// ===========================================================================28class OptionsCont;293031// ===========================================================================32// class definitions33// ===========================================================================34/**35* @class OptionsParser36* @brief Parses command line arguments37*38* The only public method parses the given list of arguments. It returns false39* when something failed. This may happen if the syntax of the arguments is40* invalid, a value is tried to be set several times or an unknown option41* is tried to be set.42*43* The class assumes all options are unset or using default values only.44*/45class OptionsParser {46public:47/** @brief Parses the given command line arguments48*49* @param[in] oc The options container to fill50* @param[in] args The command line arguments51* @return Whether the parsing was successful52* @exception InvalidArgument If a performed setting of an option failed (see Option::set)53*/54static bool parse(const std::vector<std::string>& args, const bool ignoreAppenders = false);5556private:57/** @brief parses the previous arguments58*59* @param[in] arg1 The first token to parse60* @param[in] arg2 The second token to parse, 0 if there is none61* @param[in, out] ok Whether the parsing was successful62* @return Number of read tokens (1 or 2)63* @exception InvalidArgument If a performed setting of an option failed (see Option::set)64*/65static int check(const std::string& arg1, const std::string* const arg2, bool& ok, const bool ignoreAppenders);666768/** @brief Returns the whether the given token is an option69*70* The given token is assumed to be an option if it starts with a '-' or a '+'.71*72* @param[in] arg1 The token to check73* @return Whether the token is an option74*/75static bool checkParameter(const std::string& arg1);767778/** @brief Extracts the parameter directly attached to an option79*80* Parses single tokens which contain an option and the parameter81* (like -c=myconfig.cfg)82*83* @param[in] oc The container to store the result into84* @param[in] arg The token to parse85* @exception InvalidArgument If a performed setting of an option failed (see Option::set)86*/87static bool processNonBooleanSingleSwitch(OptionsCont& oc, const std::string& arg, const bool append);888990};919293