/****************************************************************************/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 OptionsIO.h14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @date Mon, 17 Dec 200117///18// Helper for parsing command line arguments and reading configuration files19/****************************************************************************/20#pragma once21#include <config.h>2223#include <vector>24#include <string>25#include <chrono>262728// ===========================================================================29// class declarations30// ===========================================================================31class OptionsCont;323334// ===========================================================================35// class definitions36// ===========================================================================37/**38* @class OptionsIO39*40* Helping methods for parsing of command line arguments and reading a41* configuration file.42* Any errors are reported by throwing a ProcessError exception which43* contains a description about the failure.44*/45class OptionsIO {46public:47/** @brief Stores the command line arguments for later parsing48*49* @param[in] argc number of arguments given at the command line50* @param[in] argv arguments given at the command line51*/52static void setArgs(int argc, char** argv);5354/** @brief Stores faked command line arguments for later parsing55*56* @param[in] args arguments given as substitute for the command line57*/58static void setArgs(const std::vector<std::string>& args);5960/** @brief Return the number of command line arguments61*/62static int getArgC() {63return (int)myArgs.size();64}656667/** @brief Parses the command line arguments and loads the configuration68*69* Command line arguments are parsed, first, throwing a ProcessError70* if something fails. Then options are reset to being writeable and the71* configuration is loaded using "loadConfiguration". After this,72* the options are reset again and the command line arguments are73* reparsed.74*75* This workflow allows to read the name of a configuration file from76* command line arguments, first, then to load values from this configuration77* file and reset them by other values from the command line.78*/79static void getOptions(const bool commandLineOnly = false);808182/** @brief Loads and parses the configuration83*84* The name of the configuration file is extracted from the global85* OptionsCont ("configuration-file" is used as the name of the option to get86* the name of the configuration).87*/88static void loadConfiguration();899091/** @brief Retrieves the XML root element of a supposed configuration or net92*93* @param[in] filename the XML file to parse94* @return the root element if any95*/96static std::string getRoot(const std::string& filename);9798/** @brief Return the time stamp of the last init99*/100static const std::chrono::time_point<std::chrono::system_clock>& getLoadTime() {101return myLoadTime;102}103104105private:106static std::vector<std::string> myArgs;107static std::chrono::time_point<std::chrono::system_clock> myLoadTime;108109};110111112