libyui
 
Loading...
Searching...
No Matches
YCommandLine Class Reference

#include <YCommandLine.h>

Public Member Functions

 YCommandLine ()
 
 ~YCommandLine ()
 
int argc () const
 
char ** argv () const
 
int size () const
 
std::string arg (int index) const
 
std::string operator[] (int index) const
 
void add (const std::string &arg)
 
void remove (int index)
 
void replace (int index, const std::string &arg)
 
int find (const std::string &argName) const
 

Detailed Description

Utility class to access /proc/<pid>/cmdline to retrieve argc and argv

Constructor & Destructor Documentation

◆ YCommandLine()

YCommandLine::YCommandLine ( )

Constructor. This will read /proc/<pid>/cmdline of this process.

◆ ~YCommandLine()

YCommandLine::~YCommandLine ( )

Destructor.

Member Function Documentation

◆ add()

void YCommandLine::add ( const std::string & arg)

Add a command line argument (at the end of the existing ones).

◆ arg()

string YCommandLine::arg ( int index) const

Return command line argument no. 'index' (from 0 on).

This might throw an YUIIndexOutOfRangeException.

◆ argc()

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".

◆ argv()

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).

◆ find()

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.

◆ operator[]()

std::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] << std::endl;

This might throw an YUIIndexOutOfRangeException.

◆ remove()

void YCommandLine::remove ( int index)

Remove command line argument no. 'index' (from 0 on).

This might throw an YUIIndexOutOfRangeException.

◆ replace()

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.

◆ size()

int YCommandLine::size ( ) const
inline

Alias for argc() for those who like a more C++ -like syntax.


The documentation for this class was generated from the following files: