Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CmdLineArgs.h
Go to the documentation of this file.
1/* Copyright (C) 2022 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_CMDLINEARGS
19#define INCLUDED_CMDLINEARGS
20
21#include "lib/os_path.h"
22#include "ps/containers/Span.h"
23#include "ps/CStr.h"
24
25#include <utility>
26#include <vector>
27
29{
30public:
32
33 /**
34 * Parse the command-line options, for future processing.
35 * All arguments are required to be of the form <tt>-name</tt> or
36 * <tt>-name=value</tt> - anything else is ignored.
37 *
38 * @param argv span of arguments; argv[0] should be the program's name
39 */
41
42 /**
43 * Test whether the given name was specified, as either <tt>-name</tt> or
44 * <tt>-name=value</tt>
45 */
46 bool Has(const CStr& name) const;
47
48 /**
49 * Get the value of the named parameter. If it was not specified, returns
50 * the empty string. If it was specified multiple times, returns the value
51 * from the first occurrence.
52 */
53 CStr Get(const CStr& name) const;
54
55 /**
56 * Get all the values given to the named parameter. Returns values in the
57 * same order as they were given in argv.
58 */
59 std::vector<CStr> GetMultiple(const CStr& name) const;
60
61 /**
62 * Get the value of argv[0], which is typically meant to be the name/path of
63 * the program (but the actual value is up to whoever executed the program).
64 */
65 OsPath GetArg0() const;
66
67 /**
68 * Returns all arguments that don't have a name (string started with '-').
69 */
70 std::vector<CStr> GetArgsWithoutName() const;
71
72private:
73 typedef std::vector<std::pair<CStr, CStr> > ArgsT;
76 std::vector<CStr> m_ArgsWithoutName;
77};
78
80
81#endif // INCLUDED_CMDLINEARGS
CmdLineArgs g_CmdLineArgs
Definition: CmdLineArgs.cpp:27
Definition: CmdLineArgs.h:29
std::vector< CStr > GetMultiple(const CStr &name) const
Get all the values given to the named parameter.
Definition: CmdLineArgs.cpp:94
std::vector< CStr > GetArgsWithoutName() const
Returns all arguments that don't have a name (string started with '-').
Definition: CmdLineArgs.cpp:112
CStr Get(const CStr &name) const
Get the value of the named parameter.
Definition: CmdLineArgs.cpp:88
bool Has(const CStr &name) const
Test whether the given name was specified, as either -name or -name=value
Definition: CmdLineArgs.cpp:83
std::vector< std::pair< CStr, CStr > > ArgsT
Definition: CmdLineArgs.h:73
CmdLineArgs()
Definition: CmdLineArgs.h:31
std::vector< CStr > m_ArgsWithoutName
Definition: CmdLineArgs.h:76
OsPath GetArg0() const
Get the value of argv[0], which is typically meant to be the name/path of the program (but the actual...
Definition: CmdLineArgs.cpp:107
ArgsT m_Args
Definition: CmdLineArgs.h:74
OsPath m_Arg0
Definition: CmdLineArgs.h:75
Simplifed version of std::span (C++20) as we don't support the original one yet.
Definition: Span.h:37
Definition: path.h:80