libyui
|
#include <YCommandLine.h>
Public Member Functions | |
YCommandLine () | |
~YCommandLine () | |
int | argc () const |
char ** | argv () const |
int | size () const |
string | arg (int index) const |
string | operator[] (int index) const |
void | add (const string &arg) |
void | remove (int index) |
void | replace (int index, const string &arg) |
int | find (const string &argName) const |
Utility class to access /proc/<pid>/cmdline to retrieve argc and argv
YCommandLine::YCommandLine | ( | ) |
Constructor. This will read /proc/<pid>/cmdline of this process.
YCommandLine::~YCommandLine | ( | ) |
Destructor.
void YCommandLine::add | ( | const string & | arg | ) |
Add a command line argument (at the end of the existing ones).
string YCommandLine::arg | ( | int | index | ) | const |
Return command line argument no. 'index' (from 0 on).
This might throw an YUIIndexOutOfRangeException.
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".
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).
int YCommandLine::find | ( | const 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.
string YCommandLine::operator[] | ( | int | index | ) | const [inline] |
Return command line argument no. 'index' (from 0 on) as operator[]:
for ( int i=0; i < cmdLine.argc(); i++ ) cout << cmdLine[i] << endl;
This might throw an YUIIndexOutOfRangeException.
void YCommandLine::remove | ( | int | index | ) |
Remove command line argument no. 'index' (from 0 on).
This might throw an YUIIndexOutOfRangeException.
void YCommandLine::replace | ( | int | index, |
const string & | arg | ||
) |
Replace command line argument no. 'index' (from 0 on) with 'arg'.
This might throw an YUIIndexOutOfRangeException.
int YCommandLine::size | ( | ) | const [inline] |
Alias for argc() for those who like a more C++ -like syntax.