libptpmgmt  1.3
libptpmgmt library that provides the functionality of linuxptp pmc
Classes | Public Types | Public Member Functions | List of all members
Options Class Reference

Hold and process options. More...

#include <opt.h>

Public Types

enum  loop_val { OPT_ERR , OPT_MSG , OPT_HELP , OPT_DONE }
 

Public Member Functions

 Options (bool useDef=true)
 
void useDefOption ()
 
bool insert (const Pmc_option &opt)
 
const char * get_help ()
 
const std::string & get_msg () const
 
const char * get_msg_c () const
 
loop_val parse_options (int argc, char *const argv[])
 
bool have (char opt) const
 
const std::string & val (char opt) const
 
const char * val_c (char opt) const
 
int val_i (char opt) const
 
char get_net_transport () const
 
bool have_more () const
 
int process_next () const
 

Detailed Description

Hold and process options.

Member Enumeration Documentation

◆ loop_val

parsing return code

Enumerator
OPT_ERR 

Parsing error

OPT_MSG 

Message from parsing

OPT_HELP 

Need to print help

OPT_DONE 

parsing success

Constructor & Destructor Documentation

◆ Options()

Options::Options ( bool  useDef = true)

constructor

Parameters
[in]useDefuse PMC default options

Member Function Documentation

◆ get_help()

const char* Options::get_help ( )

Get help message

Returns
help message

◆ get_msg()

const std::string& Options::get_msg ( ) const
inline

Get parse_options() message

Returns
message from last parse_options()

◆ get_msg_c()

const char* Options::get_msg_c ( ) const
inline

Get parse_options() message

Returns
message from last parse_options()

◆ get_net_transport()

char Options::get_net_transport ( ) const
inline

get Network Transport value

Returns
Network Transport
Note
return 0 if not select on command line

◆ have()

bool Options::have ( char  opt) const
inline

Is option on command line

Parameters
[in]optshort option character
Returns
true if option on command line

◆ have_more()

bool Options::have_more ( ) const
inline

Do we have more argumends on the command line, left unprocessed

Returns
true if we have more to process

◆ insert()

bool Options::insert ( const Pmc_option opt)

Insert option

Parameters
[in]optnew option parameters
Returns
true on adding the option
Note
should be called before calling parse_options()

◆ parse_options()

loop_val Options::parse_options ( int  argc,
char *const  argv[] 
)

Parse command line

Parameters
[in]argcnumber of arguments
[in]argvarray of command line arguments
Returns
Parse state
Note
Follow the command line. Argument 0 is the application name, as appear in the command line. This class do not store it.
regarding using scripts:
Python, Go and PHP uses full argument list. For Ruby, Perl and Tcl user need to add argument 0. Lua miss argument 0 completely, so user should add argument 0 manually!
To call from scripts:
Python obj.parse_options(sys.argv)
Go obj.Parse_options(os.Args) PHP $obj->parse_options($argv)
Ruby $obj.parse_options([$0] + ARGV)
Perl obj->parse_options([$0, @ARGV]);
Tcl obj parse_options [list {*}$argv0 {*}$::argv]
Lua table.insert(arg, 1, "myname"); obj:parse_options(arg)

◆ process_next()

int Options::process_next ( ) const
inline

First argumend on the command line, left unprocessed

Returns
index of argument

◆ useDefOption()

void Options::useDefOption ( )

Use PMC default options

◆ val()

const std::string& Options::val ( char  opt) const

get option value

Parameters
[in]optshort option character
Returns
option value
Note
relevant for option with argument

◆ val_c()

const char* Options::val_c ( char  opt) const
inline

get option value

Parameters
[in]optshort option character
Returns
option char pointer of value string (C style)
Note
relevant for option with argument

◆ val_i()

int Options::val_i ( char  opt) const
inline

get option integer value

Parameters
[in]optshort option character
Returns
option integer value
Note
relevant for option with argument of integer value

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