Pyrogenesis  trunk
CmdLineArgs.h
Go to the documentation of this file.
1 /* Copyright (C) 2009 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 "ps/CStr.h"
22 #include "lib/os_path.h"
23 
25 {
26 public:
28 
29  /**
30  * Parse the command-line options, for future processing.
31  * All arguments are required to be of the form <tt>-name</tt> or
32  * <tt>-name=value</tt> - anything else is ignored.
33  *
34  * @param argc size of argv array
35  * @param argv array of arguments; argv[0] should be the program's name
36  */
37  CmdLineArgs(int argc, const char* argv[]);
38 
39  /**
40  * Test whether the given name was specified, as either <tt>-name</tt> or
41  * <tt>-name=value</tt>
42  */
43  bool Has(const char* name) const;
44 
45  /**
46  * Get the value of the named parameter. If it was not specified, returns
47  * the empty string. If it was specified multiple times, returns the value
48  * from the first occurrence.
49  */
50  CStr Get(const char* name) const;
51 
52  /**
53  * Get all the values given to the named parameter. Returns values in the
54  * same order as they were given in argv.
55  */
56  std::vector<CStr> GetMultiple(const char* name) const;
57 
58  /**
59  * Get the value of argv[0], which is typically meant to be the name/path of
60  * the program (but the actual value is up to whoever executed the program).
61  */
62  OsPath GetArg0() const;
63 
64 private:
65  typedef std::vector<std::pair<CStr, CStr> > ArgsT;
66  ArgsT m_Args;
68 };
69 
70 #endif // INCLUDED_CMDLINEARGS
CStr Get(const char *name) const
Get the value of the named parameter.
Definition: CmdLineArgs.cpp:64
CmdLineArgs()
Definition: CmdLineArgs.h:27
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:90
std::vector< CStr > GetMultiple(const char *name) const
Get all the values given to the named parameter.
Definition: CmdLineArgs.cpp:74
bool Has(const char *name) const
Test whether the given name was specified, as either -name or -name=value
Definition: CmdLineArgs.cpp:58
Definition: path.h:77
ArgsT m_Args
Definition: CmdLineArgs.h:66
std::vector< std::pair< CStr, CStr > > ArgsT
Definition: CmdLineArgs.h:65
Definition: CmdLineArgs.h:24
OsPath m_Arg0
Definition: CmdLineArgs.h:67