libyui
3.4.2
|
Utility class to access /proc/<pid>/cmdline to retrieve argc and argv. More...
#include <YCommandLine.h>
Public Member Functions | |
YCommandLine () | |
Constructor. More... | |
~YCommandLine () | |
Destructor. | |
int | argc () const |
Return the number of arguments in the command line. More... | |
char ** | argv () const |
Return the arguments in a C compatible fashion: An array of pointers to characters. More... | |
int | size () const |
Alias for argc() for those who like a more C++ -like syntax. | |
std::string | arg (int index) const |
Return command line argument no. More... | |
std::string | operator[] (int index) const |
Return command line argument no. More... | |
void | add (const std::string &arg) |
Add a command line argument (at the end of the existing ones). | |
void | remove (int index) |
Remove command line argument no. More... | |
void | replace (int index, const std::string &arg) |
Replace command line argument no. More... | |
int | find (const std::string &argName) const |
Find a command line argument 'argName' ("-display" etc.). More... | |
Utility class to access /proc/<pid>/cmdline to retrieve argc and argv.
Definition at line 37 of file YCommandLine.h.
YCommandLine::YCommandLine | ( | ) |
Constructor.
This will read /proc/<pid>/cmdline of this process.
Definition at line 48 of file YCommandLine.cc.
std::string YCommandLine::arg | ( | int | index | ) | const |
Return command line argument no.
'index' (from 0 on).
This might throw an YUIIndexOutOfRangeException.
Definition at line 109 of file YCommandLine.cc.
int YCommandLine::argc | ( | ) | const |
Return the number of arguments in the command line.
Remember that the command itself (the binary of the process) is included, so a value of 1 (not 0!) means "no additional arguments".
Definition at line 78 of file YCommandLine.cc.
char ** YCommandLine::argv | ( | ) | const |
Return the arguments in a C compatible fashion: An array of pointers to characters.
The data are copied with strdup(), so they are valid beyond the life time of this object (but OTOH should be released with free() at some point).
Definition at line 85 of file YCommandLine.cc.
int YCommandLine::find | ( | const std::string & | argName | ) | const |
Find a command line argument 'argName' ("-display" etc.).
Notice that leading minus signs must be specified in 'argName'. Since argv[0] is the program name, the search starts from argv[1].
Return the position of 'argName' (from 0 on) or -1 if not found.
Definition at line 136 of file YCommandLine.cc.
|
inline |
Return command line argument no.
'index' (from 0 on) as operator[]:
for ( int i=0; i < cmdLine.argc(); i++ ) cout << cmdLine[i] << std::endl;
This might throw an YUIIndexOutOfRangeException.
Definition at line 85 of file YCommandLine.h.
void YCommandLine::remove | ( | int | index | ) |
Remove command line argument no.
'index' (from 0 on).
This might throw an YUIIndexOutOfRangeException.
Definition at line 118 of file YCommandLine.cc.
void YCommandLine::replace | ( | int | index, |
const std::string & | arg | ||
) |
Replace command line argument no.
'index' (from 0 on) with 'arg'.
This might throw an YUIIndexOutOfRangeException.
Definition at line 127 of file YCommandLine.cc.