libyui  3.0.10
 All Classes Functions Variables Enumerations Friends
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

Definition at line 37 of file YCommandLine.h.

Constructor & Destructor Documentation

YCommandLine::YCommandLine ( )

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

Definition at line 48 of file YCommandLine.cc.

YCommandLine::~YCommandLine ( )

Destructor.

Definition at line 71 of file YCommandLine.cc.

Member Function Documentation

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

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

Definition at line 102 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.

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.

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.

int YCommandLine::size ( ) const
inline

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

Definition at line 68 of file YCommandLine.h.


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